Skip to main content
Senior
July 5, 2024
Solved

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

  • July 5, 2024
  • 6 replies
  • 1857 views

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 :)

 

This topic has been closed for replies.
Best answer by Dor_RH

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

6 replies

ST Employee
July 5, 2024

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

 

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Dor_RH
RickoAuthor
Senior
July 7, 2024

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 :)

Dor_RHBest answer
ST Employee
July 8, 2024

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

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Dor_RH