I am trying to transfer a dynamically sized byte array that can go from 0 to 762 bytes. The electric imp has a uart limit of 80 bytes. How can I accomplish this?
The FIFO is 80 bytes deep. As long as your code can read 682 bytes from the FIFO in the time it takes all 762 to arrive, you won’t overflow. For maximum speed, use the data-ready callback (the sixth parameter to uart.configure).
Will the data ready call back show up when the UART is full? I am also using the imp uart for many other functions do i need to reconfigure once i am done?
The callback is called when there are one or more bytes to be read - you should empty the buffer in the callback.
I empty the buffer every time i call the read function? I am also experiencing byte shifts within my transfers. Could this be due to a timing error?
Are there any effective baudrates btter than others, for example those that have 0.0% bit errors?
Byte shifts are usually due to FIFO overruns. If you aren’t using the data-ready callback, then it’s possible your code isn’t calling read() often enough. Note that using read() in an imp.wakeup(0.01) callback will overrun at baud rates above 80-bytes-in-0.01-seconds, which is only 80,000baud. At baud rates above that, such as 115,200, the only way to avoid overruns is the data-ready callback.
However my baudrate is currently 9600 bps. Is not using the callback still affecting me?
I am using imp.sleep in order to wait for system data to be available. I have different functions that require different forms of sending uart and receiving uart. Implementing each one with call backs would be the right way to do it?
To overrun and miss a character at 9600baud, the code would need to go for 1/16sec (0.083s) without checking the serial port. So yes, you’re better off implementing everything with callbacks (or, depending exactly how the code looks, with one callback that has some kind of “state” variable that tells it where to dispatch the data).
I am using blobs for the data since i am using an agent to push the data back to my android app. Is there a function to empty the receive buffer once I have collected my necessary data. i.e. i am sending from a microprocessor a buffered 60 bytes transfer of which i need only read the first 48. I send a command to the system and another parameter via uart, both byte, and then setup the callback function or setup the callback before hand? (Dont know if this helps, the imp is communicating with a 4dgl ulcd-32ptu, which at 9600 has an error percentage of 0.33% and uses a buffer for the data to be sent to the imp. at any moment i can hold the transfer until the imp is ready)
UARTs are generally fine with bitrates +/- 5%, as they resync every character.
If you’re using imp.sleep(), this blocks any callbacks (imp.wakeup or data ready) from running during the sleep period, so that would likely explain your missing data.
If you want to empty the RX buffer, just do:
while(hardware.uartX.read() != -1);
Thanks Hugo. Got it Working. Turns out the byte shifting was part of the IDE for the touchscreen since the programming environment uses the same COM port as the one used to communicate with the imp. So whenever programming the touchscreen you would have to keep in mind the use of the COM port. This however could be used as a tutorial for others who also wish for massive info transfers.