Switching from USB to UART

hi

I created a project that uses Zephyr RTOS on a nRF52840 dk that is attached to a USB port on the computer, and on the computer side, there is Python code that sends configuration data over USB.
It reads config data over USB in hex format, so it is able to read all of the sent data in a single read with the usb_dc_ep_read() function.

It is implemented as follows: usb_dc_ep_read(ep,buff, 64,&read bytes) so that the configuration data length and content can be validated and applied.

After that, I needed to convert the USB to UART, so I used uart_fifo_read() as they did in the Zephyr sample echo_bot, but I had to make some changes because they use ASCII and in my case i sent binary (hex) data .

and I found these two issues:
1. The uart_fifo_read reads byte by byte, which does not work for me, so I cannot determine the length of the single message sent.
2. When sending data with zeros (for example, 0x1156000099), it deletes the zeros and returns 0x115699.

How can I solve these problems and make it work like the USB case without having to store data byte by byte and maybe use timers to handle the data?

thank you

Parents
  • Hello,

    I suspect that there is something in the way that you are trying to read the uart that strips away the '0's. 0 is a perfectly fine UART byte, and it shouldn't be cut out like this. 

    Using UART, you need to read out byte by byte, because there is no header or anything saying anything about the length of a message. It is being sent one byte at the time. You need to stitch the message back together in your application.

    I suggest you have a look at the NCS\nrf\samples\bluetooth\peripheral_uart, and look at how this example reads the UART, and checks for special characters to determine whether to handle the message now, or wait for the next byte.

    If that doesn't work out, is it possible for you to upload your project, so that I can replicate what you are seeing on a DK?

    Best regards,

    Edvin

Reply
  • Hello,

    I suspect that there is something in the way that you are trying to read the uart that strips away the '0's. 0 is a perfectly fine UART byte, and it shouldn't be cut out like this. 

    Using UART, you need to read out byte by byte, because there is no header or anything saying anything about the length of a message. It is being sent one byte at the time. You need to stitch the message back together in your application.

    I suggest you have a look at the NCS\nrf\samples\bluetooth\peripheral_uart, and look at how this example reads the UART, and checks for special characters to determine whether to handle the message now, or wait for the next byte.

    If that doesn't work out, is it possible for you to upload your project, so that I can replicate what you are seeing on a DK?

    Best regards,

    Edvin

Children
No Data
Related