This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Common serial interface over UART and USB

Hi,

I am developing firmware for both nRF52832 and nRF52840 chips. For serial communication, I would like to have a common interface for both chips, which means sending binary data over UART (nRF52832) or over USB (nRF52840). The only solution that I found having the same interface is the command line interface (CLI) module. But unfortunately I did not find any way to send/receive raw data (in binary) with this module.

Could you please suggest me what would be the best way to implement that?

Thank you in advance,

Javier

Parents Reply Children
  • Hi Javier, I think the CLI example in SDK 15.3.0 can be a good starting point (link). The print function will for instance print out any arbitrary data you pass to it. You can find more documentation for the module itself here: https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v15.3.0/lib_cli.html?cp=5_1_3_10 

    Best regards,

    Vidar

  • Hi Vidar, yes, as I said at the beginning, I took your CLI module as reference, because it has a common interface to use both UART and USB.

    But maybe I did not express myself correctly. For the communication from the nRF52 to the host, I want to build a kind of serial protocol that works with UART and USB, and be able to send several types of binary packets. What I mean with binary packet is without formatting it by means of printf. I just want to send out arrays of bytes without having the overhead of formatting them as string, integer or whatever. But to do that, I did not find any function in the CLI module. Is it now more clear?

    Best regards,

    Javier

  • Sorry, your description was clear, but I realize now that CLI probably isn't the best choice for what you want to do. It should be up to your application to interpret the data passed as arguments to your custom command (doesn't have to be a string), but I forgot the fact that the module will still need to parse incoming data to detect newlines <\n or \r> (end of command), backspace <0x08> (new argument), and NULL termination in order for the interface to work. I guess it could have worked better if there were an option to use TLV encoded command arguments. 

    Maybe the CLI implementation can be more useful as a reference to implement your own abstraction layer. nrf_cli_cdc_acm.c and nrf_cli_uart.c how we've created the "serial port" API. 

    Best regards,

    Vidar

Related