improve speed

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
User avatar
Roberthh
Posts: 1081
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: improve speed

Post by Roberthh » Mon Oct 08, 2018 6:27 pm

The discussion moves away form the initial topic, about how the total transfer rate can be improved. I do not understand that raw I2C communication speeds limits that, given that the actual data rate is 40 byte&/sec, and the raw I2C speed is 50kByte/sec. As said, in the main loop of the cited code there is a sleep_ms(7), which seems necessary and limits the achivable data rate to ~140 byte/sec, no matter how fast the communication to the device is. So optimization should start with the analysis, which part of the code take how much time. But even with a parallel out, I would not expect a better rate than 100 bytes/sec.

cyberlab
Posts: 31
Joined: Sat Apr 21, 2018 5:02 am

Re: improve speed

Post by cyberlab » Tue Oct 09, 2018 3:08 am

hello again to all, browsing the network I found this information, which confirms that with I2C works perfectly without any transfer error and because with SPI I could not make it work correctly:

Selecting Between I2C and SPI
Selecting between I2c and SPI, the two main serial communication protocols, requires a good understanding of the advantages and limitations of I2C, SPI, and your application. Each communication protocol will have distinct advantages which will tend to distinguish itself as it applies to your application. The key distinctions between I2C and SPI are:

I2C requires only two wires, while SPI requires three or four
SPI supports higher speed full-duplex communication while I2C is slower
I2C draws more power than SPI
I2C supports multiple devices on the same bus without additional select signal lines through in-communication device addressing while SPI requires additional signal lines to manage multiple devices on the same bus
I2C ensures that data sent is received by the slave device while SPI does not verify that data is received correctly
I2C can be locked up by one device that fails to release the communication bus
SPI cannot transmit off the PCB while I2C can, albeit at low data transmission speeds
I2C is cheaper to implement than the SPI communication protocol
SPI only supports one master device on the bus while I2C supports multiple master devices
I2C is less susceptible to noise than SPI
SPI can only travel short distances and rarely off of the PCB while I2C can transmit data over much greater distances, although at low data rates
The lack of a formal standard has resulted in several variations of the SPI protocol, variations which have been largely avoided with the I2C protocol

Roberthh, it would be great to send 100 bytes / sec.
if I change the pulse to 5ms, I can achieve 54 bytes per second.

User avatar
pythoncoder
Posts: 3060
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: improve speed

Post by pythoncoder » Tue Oct 09, 2018 5:03 am

My guess is that the delay comes from

Code: Select all

if D_set.value()== False: #Request data from machine.
Is it waiting on the machine? I can't see anything else in the code which would significantly reduce the speed below 140bytes/sec.

@cyberlab If you have access to a scope or a logic analyser you could check whether it is in fact waiting on the machine.

@Roberthh I take your point about overall performance - I hadn't studied the code closely enough. Clearly I2C performance is not the limiting factor. However transmission distance is an issue especially in an industrial environment.

@cyberlab What type and how long is the I2C cable?

Your comparison of I2C and SPI is accurate however both buses can be buffered as described by @emtree and myself to achieve reliable operation over longer transmission distances.
Peter Hinch

cyberlab
Posts: 31
Joined: Sat Apr 21, 2018 5:02 am

Re: improve speed

Post by cyberlab » Fri Oct 12, 2018 5:24 am

Hello everyone, thanks to your help following their advice and managed to send the machine 66 bytes / sec. Quite acceptable since a design is sent in a couple of minutes, thanks again.

Post Reply