Microcontroller for microcontroller library (via UART / RS232)

I want to link two microcontrollers with a UART interface and look for a protocol to exchange data between them.

In practice, I want to periodically exchange data (like reading sensors) as well as event data (GPIO state). I have about 100-200 bytes to exchange every 100 milliseconds.

Does anyone know a protocol or library to achieve this task?

While I can see the protobuff and the nano-protobuff? Is there something else? It would be nice if I could add a software layer on top of the UART and use the "virtual data stream" as if it were a TCP / IP connection with N ports.

Any idea? Thanks to

+3


source to share


5 answers


How about this: eRPC https://community.nxp.com/docs/DOC-334083

eRPC (Embedded Remote Procedure Call) is a remote procedure call (RPC) system created by NXP. RPC is a mechanism used to call a program subroutine on a remote system using a simple function call to a local function. The remote system can be any processor connected by an arbitrary communication channel: a server over a network, another CPU core in a multi-core system, etc. For the client, this is like calling a function in a library built into the application. The only difference is any latency or unreliability introduced by the communication channel.



I am using it in a dual-processor embedded system - a cortext-A9 processor with a Context-M4 MCU that communicates with SPI / GPIO.

Erpc can work over UART, SPI, rpmsg, and network (tcp). even when using serial or SPI as the transport tunnel, it can make bi-directional calls and with minimal size.

+1


source


I think the most direct way is to quit your own.

You will find RS232 drivers in the manufacturers' chip support library.

RS232 is a stream oriented transport, which means you will need to encode your messages into some kind of structure when you send them and detect frame boundaries on the receiver side. A clever and easy-to-use mechanism for this is the "Consistent Byte Fill Overhead".

https://en.wikipedia.org/wiki/Consistent_Overhead_Byte_Stuffing

This simple algorithm turns the zeros in your messages into a different meaning, so a zero byte can be used to determine the start and end of a frame. If the byte gets corrupted along the way you can even synchronize with the stream and keep going.

Wikipedia code should be simple enough for even the smallest microprocessors.



Then you can define your message format. You can probably keep it very simple and send your data-structures directly as they are.

Suggestion for simple message format:

Byte-ID   Meaning
---------------------------------
0         Destination port number
1         message type (define your own)
2 to n    message data

      

If you want to send variable length messages, you can either send the length of the byte or infer the length from the output of the frame assembly with a constant overhead.

By the way, UART / RS232 is nice and easy to work with, but you can also take a look at SPI. The SPI interface is more suitable for exchanging data between two microcontrollers. It is usually faster than RS232 and more reliable as it has a dedicated clock line.

+5


source


Simple serial point-to-point communication protocol

http://www.zipplet.co.uk/index.php/content/openformats_mise

It depends on whether you want a master / slave implementation, noise protection, point-to-point or multipoint (and in this case collision detection), etc.

but as our colleague said, I would go with the simplest solution that fits this problem, following the KISS principle http://en.wikipedia.org/wiki/KISS_principle

Just add some header information like ID and length, check CRC if needed and be happy :)

+1


source


Once the first answer starts, the simplest result is folding your own. Define your title ("format" above) as needed, possibly including status information so that each processor knows the other is working correctly. I have had success with a protocol that includes

  • 2 byte ascii prefix and suffix such as "[" and "]" so that the protocol parser can display message boundaries.
  • The number of bytes.
  • Command ID (parsed to indicate which command handler to use.
  • Command arguments (I used 3 32-bit words).
  • CRC or checksum to check the integrity of the transmission.

The parser then recognizes the [* as the start of the message and sends the body to the command handler for the specific command identifier, with appropriate arguments, as long as the checksum matches.

0


source


Try Microcontroller Interconnect (MIN) 1.0 Network:

https://github.com/min-protocol/min

It has a framing using byte input to keep the receiver in sync, Fletcher's 16-bit checksum algorithm, an identifier for use by the application, and a variable payload of up to 15 bytes.

There's C code embedded there, as well as a Python implementation to make communication with PC easier.

0


source







All Articles