problem when i receive data on Uart rx when i read

Hello,

I have got a problem when i receive data on Uart rx when i read.

Here is my test code :

import pyb,time

red_led = pyb.LED(1)
red_led.off()

uart=pyb.UART(3,14400)
uart.init(14400, bits=8, parity=None, stop=1) #, timeout_char=20

while(True):
   time.sleep(500)
   if uart.any():
      uchar=uart.read(1)
      print('==> Info -------------')
      print(uchar)
      red_led.toggle()

I send “0x0F 0x00 0x0F 0x00 0x0F 0x00 0x0F 0x00” number with realterm software every half second (quick click) and the camera stops.
i dont have the same behavior if i send 50x this number at once because the uart buffer is limited.

It looks like the uart buffer index is lost when the reading is during the reception.

Do i do something wrong ?

I don’t quite understand what you care trying to do. How many characters are you sending between the 0.5s waits?

Well, i discovered the problem when i tried to send image over UART to a master which does something else, lose a part of the data and try to restart a new synchronization.

To reproduce the behavior, I send several datas by frame (like 0x0F 0x00 0x0F 0x00 0x0F 0x00 0x0F 0x00) every ~0.5s when the camera is reading the buffer slowly (one data every 0.5s).

This does not happen when i send at once a very big frame (like 50 times 0x0F 0x00 0x0F 0x00 0x0F 0x00 0x0F 0x00) because the uart buffer is a circular list i assume.

I hope it is clearer.

Ibrahim, can you help out?

Hi, no I don’t understand the problem either. Can you post steps + code to reproduce ?

Lol, ok i try again !

Here is a new test code with image snapshot :

import pyb,time, sensor

sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time = 2000)
clock = time.clock()

uart=pyb.UART(3,14400)
uart.init(14400, bits=8, parity=None, stop=1)

while(True):
   img = sensor.snapshot()
   time.sleep(500)
   if uart.any():
      uchar=uart.read(1)
      print(uchar)

I join a picture, where you can see Openmv IDE and Realterm software with the frame “0x00 0xFF 0x00 0xFF 0x00 0xFF 0x00 0xFF” and the “send Numbers” button.
After few quick clicks (10 times every half sec), the camera stops, disconnects and cant be reconnected (unplug and plug again the USB cable is necessary to reconnect the camera).

I hope it helps.

I think this is the same issue:

Please try the attached firmware and let me know if it works.
firmware.zip (899 KB)

Tx it works with my code test, do you github it ?
I could test this and jpg exception.

I was waiting for you to test it. I’ll commit it now.

Opposite to your firmware, the last git have the same previous behavior.

This was committed to our micropython fork. I think you need to do a git pull in src/micropython too

Do:

“git remote -v”

To see what repo you cloned off of. Then “git pull --rebase origin master” where origin should point to our github and master is the master branch.

I am lost in github but the modification works for UART !

Here are the results to get the last modifications :