Skip to main content
Visitor II
September 13, 2025
Solved

Simple Classic CAN + FreeRTOS Demo simulating OBD and a vehicle

  • September 13, 2025
  • 3 replies
  • 1114 views

Building upon my previous post, "Bidirectional Serial Communication with ST-Link using FreeRTOS on NUCLEO Boards," this code demonstrates a Simulator component and an Application component operating on two separate NUCLEO-C092RC boards. Please note that this project is intended for educational use and is not designed as robust production code; some errors or omissions may remain that users will need to address. This initial demonstration should function as described when configured according to the provided instructions, and it may serve as a foundational template for future development and enhancements.

Val Gretchev

    This topic has been closed for replies.
    Best answer by mƎALLEm

    Hello @Gretchev and thank you for your contribution.

    I tested the two projects and they work well.
    If I summurize: the first CAN node, the "simulator" (as a car simulator), is diagnosed by the second CAN node, the "application" (simulating the OBD) which simulates the On-Board Diagnostics, diagnosing the car. NUCLEO-C092RC boards were used: one used to simulate a vehicle and the second one to simulate the OBD.

    This is the log obtained when sending different commends from the PC to the "application" over USART2 to request data from the vehicle (the simulator) over CAN.

    Welcome to STlink PC-to-MCU command interpreter
    Starting default task
    Starting UART command task
    Starting CAN receive task
    Starting CAN transmit task
    A: toggle green LED
    B: toggle blue LED
    C: How now brown cow?
    D: Same way black bull
    R: Retrieve RPM
    RX: 11b 0x7E8 41 0C RPM: 1500
    S: Retrieve vehicle speed
    RX: 11b 0x7E8 41 0D Speed: 60 km/h
    T: Retrieve coolant temperature
    RX: 11b 0x7E8 41 05 Coolant: 85B0 C

    r: to request the current engine RPM
    s: to request the current vehicle speed
    t: to request the current coolant temperature value

    Other commands, like a, b, c, d are miscs and used to toggle leds etc ..

    I will mark this comment as solution to give it more visibility for other users to help them to find efficiently this solution.

     

    3 replies

    Technical Moderator
    September 15, 2025

    Hello @Gretchev 

    Thank you for sharing your project, "Bidirectional Serial Communication with ST-Link using FreeRTOS on NUCLEO Boards," on the ST Community. Your willingness to openly share your work and insights is truly appreciated.

    Thank you again for your contribution your efforts are making a positive impact and helping others learn and grow!

    THX

    Ghofrane

    mƎALLEmAnswer
    Technical Moderator
    September 17, 2025

    Hello @Gretchev and thank you for your contribution.

    I tested the two projects and they work well.
    If I summurize: the first CAN node, the "simulator" (as a car simulator), is diagnosed by the second CAN node, the "application" (simulating the OBD) which simulates the On-Board Diagnostics, diagnosing the car. NUCLEO-C092RC boards were used: one used to simulate a vehicle and the second one to simulate the OBD.

    This is the log obtained when sending different commends from the PC to the "application" over USART2 to request data from the vehicle (the simulator) over CAN.

    Welcome to STlink PC-to-MCU command interpreter
    Starting default task
    Starting UART command task
    Starting CAN receive task
    Starting CAN transmit task
    A: toggle green LED
    B: toggle blue LED
    C: How now brown cow?
    D: Same way black bull
    R: Retrieve RPM
    RX: 11b 0x7E8 41 0C RPM: 1500
    S: Retrieve vehicle speed
    RX: 11b 0x7E8 41 0D Speed: 60 km/h
    T: Retrieve coolant temperature
    RX: 11b 0x7E8 41 05 Coolant: 85B0 C

    r: to request the current engine RPM
    s: to request the current vehicle speed
    t: to request the current coolant temperature value

    Other commands, like a, b, c, d are miscs and used to toggle leds etc ..

    I will mark this comment as solution to give it more visibility for other users to help them to find efficiently this solution.

     

    GretchevAuthor
    Visitor II
    September 17, 2025

    For the coolant temperature, I get:

    t
    T: Retrieve coolant temperature
    RX: 11b 0x7E8 41 05 Coolant: 85° C

    I guess not all PCs handle special characters the same way.

    Val

    GretchevAuthor
    Visitor II
    September 17, 2025

    Although I haven’t tested this code in a vehicle, it should be able to retrieve those parameters from the car's OBD connector under the dash. All you need is an OBD cable. Dozens are available at Amazon.com. You only connect CAN High, CAN Low, and signal ground. Because the parameters retrieved from the OBD connector are dynamic, such as vehicle speed, the car must be in motion to obtain readings other than zero. For safety reasons, ensure a passenger is responsible for monitoring the laptop output at all times while the driver focuses on operating the vehicle.

    Val