problem when i receive data on Uart rx when i read

Discussion related to "under the hood" OpenMV topics.
User avatar
chrisPyres66
Posts: 74
Joined: Mon Jul 16, 2018 9:22 am
Location: France

problem when i receive data on Uart rx when i read

Postby chrisPyres66 » Wed Dec 12, 2018 6:50 am

Hello,

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

Here is my test code :

Code: Select all

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 ?
User avatar
kwagyeman
Posts: 2797
Joined: Sun May 24, 2015 2:10 pm

Re: problem when i receive data on Uart rx when i read

Postby kwagyeman » Wed Dec 12, 2018 12:42 pm

I don't quite understand what you care trying to do. How many characters are you sending between the 0.5s waits?
Nyamekye,
User avatar
chrisPyres66
Posts: 74
Joined: Mon Jul 16, 2018 9:22 am
Location: France

Re: problem when i receive data on Uart rx when i read

Postby chrisPyres66 » Thu Dec 13, 2018 2:55 am

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.
User avatar
kwagyeman
Posts: 2797
Joined: Sun May 24, 2015 2:10 pm

Re: problem when i receive data on Uart rx when i read

Postby kwagyeman » Thu Dec 13, 2018 12:28 pm

Ibrahim, can you help out?
Nyamekye,
User avatar
iabdalkader
Posts: 690
Joined: Sun May 24, 2015 3:53 pm

Re: problem when i receive data on Uart rx when i read

Postby iabdalkader » Thu Dec 13, 2018 4:31 pm

Hi, no I don't understand the problem either. Can you post steps + code to reproduce ?
User avatar
chrisPyres66
Posts: 74
Joined: Mon Jul 16, 2018 9:22 am
Location: France

Re: problem when i receive data on Uart rx when i read

Postby chrisPyres66 » Fri Dec 14, 2018 3:08 am

Lol, ok i try again !

Here is a new test code with image snapshot :

Code: Select all

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.
Attachments
uart.JPG
User avatar
iabdalkader
Posts: 690
Joined: Sun May 24, 2015 3:53 pm

Re: problem when i receive data on Uart rx when i read

Postby iabdalkader » Sun Dec 16, 2018 11:53 am

I think this is the same issue:

https://github.com/micropython/micropython/issues/3375


Please try the attached firmware and let me know if it works.
Attachments
firmware.zip
(898.52 KiB) Downloaded 31 times
User avatar
chrisPyres66
Posts: 74
Joined: Mon Jul 16, 2018 9:22 am
Location: France

Re: problem when i receive data on Uart rx when i read

Postby chrisPyres66 » Mon Dec 17, 2018 5:14 am

Tx it works with my code test, do you github it ?
I could test this and jpg exception.
User avatar
iabdalkader
Posts: 690
Joined: Sun May 24, 2015 3:53 pm

Re: problem when i receive data on Uart rx when i read

Postby iabdalkader » Mon Dec 17, 2018 7:31 am

chrisPyres66 wrote:
Mon Dec 17, 2018 5:14 am
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.
User avatar
chrisPyres66
Posts: 74
Joined: Mon Jul 16, 2018 9:22 am
Location: France

Re: problem when i receive data on Uart rx when i read

Postby chrisPyres66 » Tue Dec 18, 2018 4:29 am

Opposite to your firmware, the last git have the same previous behavior.
User avatar
iabdalkader
Posts: 690
Joined: Sun May 24, 2015 3:53 pm

Re: problem when i receive data on Uart rx when i read

Postby iabdalkader » Tue Dec 18, 2018 8:15 am

chrisPyres66 wrote:
Tue Dec 18, 2018 4:29 am
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
User avatar
kwagyeman
Posts: 2797
Joined: Sun May 24, 2015 2:10 pm

Re: problem when i receive data on Uart rx when i read

Postby kwagyeman » Tue Dec 18, 2018 10:50 am

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.
Nyamekye,
User avatar
chrisPyres66
Posts: 74
Joined: Mon Jul 16, 2018 9:22 am
Location: France

Re: problem when i receive data on Uart rx when i read

Postby chrisPyres66 » Wed Dec 19, 2018 3:47 am

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

Here are the results to get the last modifications :

- git pull
in in src/micropython gives
Your are not in a branch...

- git remote -v
in openmv/ gives :
origin https://github.cm/openmv/openmv.git (fetch)
origin https://github.cm/openmv/openmv.git (push)

- git pull --rebase https://github.com/openmv/src/micropython.git master
in opemnv/ replaced all the openmv directory by micropython directory : OOups !
in openmv/src/python would have been better

- git clone --recursive https://github.com/openmv/openmv.git
gave the last modification

Return to “Technical Discussion”

Who is online

Users browsing this forum: No registered users and 7 guests