cancel
Showing results for 
Search instead for 
Did you mean: 

Simple out-of-the-box I2C / RS232 software protocol

Ricko
Associate III

Hi,

I have a custom master PCB connected to a few slave custom PCBs via serial. In some systems they are connected via I2C and in other systems they are connected via RS232.

They all run STM32 micros.

I am looking for two out-of-the-box protocols with source code available, one for the I2C and one for the RS232. They need to be very simple because only very little and simple data is exchanged (enable motor, change state machine state, turn LED on/off, etc) and none of it is time critical either.

Which protocol would you suggest and where can I find the source code?

Is there any such or similar solution provided by ST?

Thank you 🙂

 

1 ACCEPTED SOLUTION

Accepted Solutions

Hello @Ricko 

Yes, you could try FreeRTOS that is a real-time operating system kernel for embedded devices that is popular for STM32. It provides task management, inter-task communication, and synchronization.

As examples, we have:

  • Semaphore Usage

This example shows how to use semaphores for task synchronization.

File_Path: https://github.com/STMicroelectronics/STM32CubeF4/tree/master/Projects/STM32F413ZH-Nucleo/Applications/FreeRTOS/FreeRTOS_Semaphore

  • Mutex Usage

This example shows how to use mutexes to manage resource access.

File_Path: https://github.com/STMicroelectronics/STM32CubeF4/tree/master/Projects/STM32F413ZH-Nucleo/Applications/FreeRTOS/FreeRTOS_Mutexes

  • Queue Management

This example demonstrates the use of queues for inter-task communication.

File_Path: https://github.com/STMicroelectronics/STM32CubeF4/tree/master/Projects/STM32F413ZH-Nucleo/Applications/FreeRTOS/FreeRTOS_Queues

You can also find many examples in other STM32Cubes such as: STM32CubeH7, STM32CubeF7, STM32CubeG4...

I hope my answer has helped you. When your question is answered, please select this topic as solution that answered you, it will help others find that answer faster.

Thanks for your contribution.

Dor_RH

View solution in original post

6 REPLIES 6
Dor_RH
ST Employee

Hello @Ricko ,

I2C: It is widely used and supported by many microcontrollers, including STM32. You could use STM32CubeMX and STM32Cube firmware packages.

RS232: you can use open-source libraries for RS232 communication and refer to STM32Cube firmware packages for UART examples.

Also, for very simple data exchanges, you can create custom protocols based on STM32 HAL libraries. This involves defining a set of commands and responses that both master and slave devices understand.

I hope my answer has helped you. When your question is answered, please select this topic as solution that answered you, it will help others find that answer faster.

Thanks for your contribution.

Dor_RH

 

Thank you @Dor_RH 

I am aware of the I2C drivers.

What I was wondering about was whether there are some ready-made libraries for some very simple protocol, not for the peripherals (i.e. not the drivers for the peripherals).

I mean libraries that have already the state machine, parser, and storing of the received data into a predefined data structure. For some very simple protocol ad described in the OP.

I mentioned the I2C and RS232 just to list the peripheral am using. But it obviously can be over any peripheral.

Thank you 🙂

Hello @Ricko 

Yes, you could try FreeRTOS that is a real-time operating system kernel for embedded devices that is popular for STM32. It provides task management, inter-task communication, and synchronization.

As examples, we have:

  • Semaphore Usage

This example shows how to use semaphores for task synchronization.

File_Path: https://github.com/STMicroelectronics/STM32CubeF4/tree/master/Projects/STM32F413ZH-Nucleo/Applications/FreeRTOS/FreeRTOS_Semaphore

  • Mutex Usage

This example shows how to use mutexes to manage resource access.

File_Path: https://github.com/STMicroelectronics/STM32CubeF4/tree/master/Projects/STM32F413ZH-Nucleo/Applications/FreeRTOS/FreeRTOS_Mutexes

  • Queue Management

This example demonstrates the use of queues for inter-task communication.

File_Path: https://github.com/STMicroelectronics/STM32CubeF4/tree/master/Projects/STM32F413ZH-Nucleo/Applications/FreeRTOS/FreeRTOS_Queues

You can also find many examples in other STM32Cubes such as: STM32CubeH7, STM32CubeF7, STM32CubeG4...

I hope my answer has helped you. When your question is answered, please select this topic as solution that answered you, it will help others find that answer faster.

Thanks for your contribution.

Dor_RH

Thank you @Dor_RH 

but that is not what I asked. 🙂  Not sure how FreeRTOS came into this discussion either... 🙂

 

I asked if there are "libraries that have already the state machine, parser, and do the storing of the received data into a predefined data structure." For some any simple software protocol (like SLIP or any other point to point one) and not a peripheral drivers.

 

A library that:

- on the sender side, when I want to send a packet I just call a function and pass the parameters with the payload I want to send (or a pointer to a data structure I want to send)

- on the receiver side, I just get a interrupt or a callback function that is called whenever a message has been received, CRC checked and the data has been put directly into a data structure and is now ready for me to use

- on both sides it handles all the timeout and error conditions

 

Thank you again for your help 🙂

Hello @Ricko ,

Unfortunately, the STM32Cube Firmware does not provide such kind of specific application libraries.

Thanks for your contribution.

Dor_RH

Thank you @Dor_RH