cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 CAN Communication isn't occuring

Racing_stm32
Associate

Setup- I am using Platform I/o to upload code to STM32 , Teensy. I am Sending Data from one STM to another STM via CAN and the message that I received on STM I am communicating it through UART to  Teensy to Serial print it. I couldn't Serial print using STM directly so I am using Teensy. 

Issue- My UART Communication works fine when I remove all the CAN statements from the code but when I write just can.begin(500000) then My Serial monitor prints just S when I said it to print 

"STM32 CAN Receiver Initialized" and when I add the entire CAN code then Nothing is visible on Serial monitor. I checked difference between CANH and CANL on Oscilloscope and I am always getting it to be 0. So CAN communication isn't happening. Is there any extra code that is required for enabling CAN communication ? The library that I am using is https://github.com/pazi88/STM32_CAN/blob/main/STM32_CAN.cpp   
3 REPLIES 3
Ozone
Lead II

> ... but when I write just can.begin(500000)  ...

Sounds like you talk about  Arduino here.

> ... so I am using Teensy. 

Nor did you mention the hardware you are using.

All this information would be crucial.

> My UART Communication works fine when I remove all the CAN statements from the code but when I write just can.begin(500000) then My Serial monitor prints just S when I said it to print 

"STM32 CAN Receiver Initialized" and when I add the entire CAN code then Nothing is visible on Serial monitor.
Review the schematics of your board.
Are one or more UART pins of the MCU shared with CAN ?
ST's Cortex M0 ... M7 MCUs have up to 7 alternate functions for each GPIO, which are mutually exclusive. Which means, you can use only one functionality at a time.
If you have a board (like your Teensy, or ST's eval or discovery boards), you need to check the circuitry attached to the respective GPIO pins before using it. As a side note, by "checking" I mean to crosscheck with the datasheet of the exact MCU variant.
A "good" example for limited-use boards are larger ST discovery boards with LCD or external memory mounted. Those interfaces bind up a large number of GPIOs which cannot be used for any other purpose.

I am using STM32F103C6T6 for this communication and Teensy 4.o. Sorry for writing it wrong , I actually meant can.setbaudrate(500000) and yes , I am using arduino Framework in Platform I/o. Hardware stuff - I am having two Transceivers SN65HVD230 and I checked the working of them by making a CAN communication between two teensy's using those transceivers. I am using Jumpers to make all the Connections which are - Teensy 0,1,G pins connected to receiving STM A9,A10,Ground respectively and A11 , A12 of receiving STM to CAN RX and TX of one transceiver. 3.3V to transceiver and 120 ohm resistance between CANH and CANL in split. CANH of both Transceivers are shorted respectively CANL's too. Transmitting STM pins A11 , A12 are also connected to Transceivers RX and TX respectively. This all I am doing on a Breadboard and the CAN transceivers are soldered on PCB. I even uploaded the codes that I have written , Could you please verify them?

> I am using Jumpers to make all the Connections which are - Teensy 0,1,G pins connected to receiving STM A9,A10,Ground respectively and A11 , A12 of receiving STM to CAN RX and TX of one transceiver.

Does that mean that PA9 + PA10 are the UART pins, and PA11 + PA12 the CAN pins ?
That would be ok.

> Could you please verify them?

I did have a look at it, but lacking the hardware, environment and experience with Arduino, I cannot confirm anything. Superficially it seems fine.

> I checked difference between CANH and CANL on Oscilloscope and I am always getting it to be 0. So CAN communication isn't happening.

The CAN bus is very different from UART, not sure if you are aware.
You need at least one other CAN node to get actual CAN transfers.
And you need at least a termination resistor (between CANH and CANL) to see something on the scope. Still, the CAN peripheral would go into "error passive" and bus-off mode eventually, when it doesn't get an acknowledge for transmission attempts.
You can check the CAN-TX pin of the STM32 with a scope, a signal should be visible there when the initiialisation was ok and you try to send.