cancel
Showing results for 
Search instead for 
Did you mean: 

Blue Pill: Sending Data from python's Serial library over UART (DMA) to CAN Bus

tantheman
Associate II

 

STM32F103C8T6 CAN Not Responding — UART to CAN Test

I’m testing a very simple setup with two STM32F103C8T6 (Bluepill) boards.
The goal is just to send data from my PC to one STM32 through UART, and then transmit it over CAN to another STM32 board.


Setup

Data flow:

 

 
PC (PySerial) → UART → STM32 (Transmitter) → CAN Bus → STM32 (Receiver) → UART → PC
 

Hardware used:

  • Two STM32F103C8T6 boards

  • MCP2551 CAN transceivers

  • 120 Ω termination resistors at both ends

  • Common ground between boards

  • UART baud: 115200

  • CAN bit rate: 1 Mbps (Prescaler = 2, BS1 = 15, BS2 = 2)


What’s Working

  • The PC is successfully sending UART data using Python (PySerial).

  • The STM32 transmitter receives the data correctly — UART works fine.

  • The DMA callbacks trigger as expected, showing that data reception over UART is confirmed.


What’s Not Working

  • The CAN bus is not showing any transmission or response.

  • The transmitter’s CAN doesn’t seem to send anything, even though initialization completes without errors.

  • The receiver board also does not detect or print anything over UART.

  • No CAN interrupts are triggered on either board.


Summary

UART communication from PC to STM32 is verified and working.
However, the CAN side shows no activity — no transmission, no reception, and no response from either STM32 board.
I just need help understanding why the CAN is completely silent even though everything initializes correctly in CubeIDE..... All codes are below


:white_heavy_check_mark:In short:
PC → UART → STM32 works fine,
but STM32 → CAN → STM32 shows no response at all.

1 ACCEPTED SOLUTION

Accepted Solutions
tantheman
Associate II

Yes, so the setup is working now ... turns out it was problem with my hardware..... my usb cable extender was old and gave a lot of error..... after shifting to a usb hub i got proper responsive echo ......no problem with the bluepills 

 

View solution in original post

9 REPLIES 9
Techn
Senior III

You can create a  software loopback of CAN and see if the data is received back. Same data can be repeated..

If you feel a post has answered your question, please click "Accept as Solution".
Ozone
Principal II

> However, the CAN side shows no activity — no transmission, no reception, and no response from either STM32 board.
> I just need help understanding why the CAN is completely silent even though everything initializes correctly in CubeIDE..... All codes are below

I recommend to check out other threads related to CAN here.
Not sure if you understand that, but a CAN node cannot work on a bus alone.

Check the Txe and Txe counters in the CAN peripheral when you try to send.

tantheman
Associate II

So you mean to say that CAN loopback wont work...

"Check the Txe and Txe counters in the CAN peripheral when you try to send."....Im fairly new to C programming and stm32 .....Can you please elaborate on how I can debug the bluepill

I tried to do that but whenever I went to debug and see SFR for CAN registers .... then ran the code it didnt work ....Ig it switches between the debug mode and running mode ..... I have an stlinkv2 ....please help as well....Is there anything else you found 

24.5.2 Loop back mode
The bxCAN can be set in Loop Back Mode by setting the LBKM bit in the CAN_BTR
register. In Loop Back Mode, the bxCAN treats its own transmitted messages as received
messages and stores them (if they pass acceptance filtering) in a Receive mailbox.
Figure 226. bxCAN in loop back mode
This mode is provided for self-test functions. To be independent of external events, the CAN
Core ignores acknowledge errors (no dominant bit sampled in the acknowledge slot of a
data / remote frame) in Loop Back Mode. In this mode, the bxCAN performs an internal
feedback from its Tx output to its Rx input. The actual value of the CANRX input pin is
disregarded by the bxCAN. The transmitted messages can be monitored on the  CANTX pin

If you feel a post has answered your question, please click "Accept as Solution".
Techn
Senior III

Another suggestion is to pump data to a known CAN bus such as Arduino using mcp2515 which is sure to work in all modes. There you can test the RX data and TX data easily. or use any CAN Analyzer.

If you feel a post has answered your question, please click "Accept as Solution".
Techn
Senior III

https://controllerstech.com/can-protocol-in-stm32/

If you feel a post has answered your question, please click "Accept as Solution".
mƎALLEm
ST Employee

Hello,

Unfortunately, you are using STM32F103C8T6 (Bluepill) which I almost sure it contains a counterfeit STM32 product.

It was discussed many times here in this community.

I suggest to use boards from ST, Ex:  NUCLEO-F103RB instead.

+

You can refer to these articles:

Using CAN (bxCAN) in Normal mode with STM32 microcontrollers (Part 1)

Using CAN (bxCAN) in Normal mode with STM32 microcontrollers (Part 2)

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
tantheman
Associate II

Yes, so the setup is working now ... turns out it was problem with my hardware..... my usb cable extender was old and gave a lot of error..... after shifting to a usb hub i got proper responsive echo ......no problem with the bluepills