cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 Blue Pill CAN Issues

RetroBuzz
Associate II

The board has passed a authentication test so I currently believe it is a me issue. 

I have been trying to get a CAN bus going using the STM32 Blue Pill board with a TJA1050 CAN Transceiver, but for some reason even with basically copy pasted example code I don't even get activity on the lines. The transceiver modules I am using has the CAN bus terminating resistors built in resulting in a 60ohm resistance between the H and L lines. I've ended up putting together a basic test Tx and Rx bread board in hopes of figuring out whats going on with no clues. The Tx loop eventually goes dead for some reason which makes me think the HAL_addTx started locking up. Linked is a github repository with both projects. Also a video of the boards. 

18 REPLIES 18
kumaichi
Senior

Looks like the baud rate is different for each board.  Both boards have to be using the same baud rate.  When I tried working with CAN, I followed the ControllersTech videos he did regarding CAN.


STM32 CAN Communication Explained | Send & Receive Data Between Two Microcontrollers 

Kindest regards

Thanks for the response. The baud rate was a missed clock config setting. Unfortunately there was no change and still no activity even in the canRx and canTx lines. I used their web tutorial when making this but tomorrow after work I will go through that video and what I have and see if I can figure it out.

@RetroBuzz 

I tried your CAN Tx Test and it seems to be working fine:

kumaichi_0-1760408050424.png

I don't think I made any changes, but I attached the project to this message.  Note that I don't have anything connected to the STM32F103C8T6 except for the TJA1050.  I don't even have a 120 Ohm resistor.  I just have the output of the TJA1050 connected directly to the logic analyzer.  I would start there, remove everything and make sure the logic analyzer is showing the data being sent, at least then you know the data is being put out on the wire.

Best of luck!

Kindest regards

Using your zip with the same setup you mentioned, just the blue pill and tja1050 module. I even removed the onboard 120ohm for a test. I still get no activity on the can bus, however I do get this on the can tx line consistently. I am sure my logic analyzer works as I used it on the i2c of the oled display. Now I am worried my boards are not genuine but still passed the blue pill diagnostic thing. I have tested this on 2 different boards the second I have not run the test on. Where did you purchase yours? I am using PA12(Tx) PA11(Rx) 5v and ground.

RetroBuzz_1-1760414353162.png

 

 

@RetroBuzz 

That's very strange, I have the same pin configuration as you.  I ordered my boards from Amazon, they have the real STM32F103C8T6 chip on it.  Here's the link for the ones I purchased:
HiLetgo 2pcs STM32F103C8T6 

I don't know how much it matters but are your wires twisted together for the CAN wires?  I have very loosely twisted wires from the TJA1050 to the logic analyzer, maybe it shows up in the photo.

Doesn't make sense why it works for me with the exact same setup.  Have you stepped into the code to see where it might be failing?

Kindest regards

kumaichi_0-1760449548907.png

 

 

Thanks for all the information. I ordered the HiLetGo boards just in case. Mine are Amazon too but the vendors are sketchier. Since we have some stm blue pills at work I will likely test the project on one here during my lunch(1pm EDT). I don’t think the twist matters since I’m not even getting any data to the transceiver yet. 

Can you walk me through your setup and flashing per chance? During the testing on yet another board at lunch which was purchased by my workplace, I got the same results as at home. I am hoping the HiLetGo boards work but at the same time, I hope its something else and all these chips aren’t counterfeit. 

@RetroBuzz 

Sure, I'm using STM32CubeIDE v1.19.0 and one of those cheap ST-Link devices I got off Amazon, I have the genuine ST-Link but used the Amazon one for testing your project.  I'm using the Blue Pill listed above at the Amazon link.  I also purchased the TJA1050 from Amazon (Comimark TJA1050).  I used all of your settings and connected the +5V and GND to the TJA1050.  I connected PA11 -> TJA1050 (RX) and PA12 -> TJA1050 (TX).  I then connected the TJA1050 CanH and CanL to the logic analyzer.  That was all I did.

Maybe the TX and RX are connected backwards like for UART?  I didn't try that, I have RX->RX and TX->TX.

Let me know if I missed any details you might need.

Kindest regards.

Karl Yamashita
Principal

First, check if loop back mode works so you know the CAN peripheral is working.

Then run in debug mode on the Transmitting node. Check the CAN_ESR register. More than like the TEC counter is increasing probably due to something not connected correctly.  

If a reply has proven helpful, click on Accept as Solution so that it'll show at top of the post.
CAN Jammer an open source CAN bus hacking tool
CANableV3 Open Source