cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F0 CAN self-reception?

esimon
Associate II
Posted on July 10, 2015 at 23:59

I'm using an STM32F0 for a CAN application. I noticed, though, that the MCU doesn't receive the messages that it sends out on the bus. It would be preferable for me to be able to see all of the data on the bus, though, so is there a way to do this besides saving the data after it's been transmitted? Obviously, LoopBack mode prevents me from seeing other bus traffic so just using that won't work.

6 REPLIES 6
Posted on July 11, 2015 at 01:49

Well isn't the hardware confirming/retrying when it sends the data? I think you want to see your own data you need to manage that in your stack,

All the data? Including broken/colliding/corrupted packets?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
carl2399
Associate II
Posted on July 12, 2015 at 01:25

CAN doesn't work like that, you don't get to see your own messages, however it is important to realise that the CAN bus does

not

do sequential messaging. If there is a conflict on the CAN bus as mutliple devices start to send a message at the same time, then 1 of the messages (and only 1)

will

get through. The message that get's through is the first one that has a dominant bit being transmitted when the other messages are transmitting a recessive bit (causing them to stop transmitting). The result of this is that the priority of a message is determined by its CAN bus address (lower addresses have higher priority). At an extreme, higher addressed messages can get frozen out on a very busy CAN bus.

If you really want to see your own messages, then use a device with a second CAN port in ''listen only'' mode.

esimon
Associate II
Posted on July 14, 2015 at 18:36

I'll take that as validation on what I was planning on doing, which is saving packets that I put in a mailbox and retrieving them using the transmit completion interrupt.

Mark Edwards
Associate II
Posted on July 14, 2015 at 19:54

Assuming it’s similar to the F429, The transmit complete interrupt only indicates that transmission is complete, not that it’s a valid message on the CAN Bus.

To get around a similar problem I have 2 channels connected together and TX on one channel and check the data is RX’d on the other.

To see ALL the data on the Bus I have the CAN TX/RX lines connected to GPIO lines that are set as interrupt sources so that every signal transition is time stamped (from which I can work out how may bits between IRQ’s) and the actual CAN lines feeding into ADC channels, so that I can see the voltage levels (so I can profile devices using the differential amplitude and CAN_H/CAN_L voltage levels).

esimon
Associate II
Posted on July 14, 2015 at 20:18

Unfortunately, the F042 only has one CAN peripheral, so I can't do that external feedback. Right now, the ISR also checks the TXOKx bit for the appropriate mailbox. It looks like if automatic retransmission is enabled, it will only be set if it sent a ''valid message''. I'm fairly new to CAN, though, so is there actually a difference between a ''valid message'' and a ''successful transmission''?

Mark Edwards
Associate II
Posted on July 17, 2015 at 01:06

Ok, perhaps my terminology isn’t the greatest. The distinction I am trying to make is one that is accepted as a message and one that isn’t.

Automatic resend ensures that the message is sent, but like you I want to see all the data on the bus and was frustrated that there was no indication of when a collision occurred (and a resend was necessary). OK, it’s a limit of the protocol and we have to live with it or find another way to monitor the bus.

Only having one CAN port is going to be a problem for you. Perhaps duplicating the CAN RX line onto something that you can use as an interrupt source and then monitor the IRQ buffer (as I do).

Decoding the CAN packet from the IRQ data isn’t difficult so long as you remember the Golden Rule that after 5 bits at a state there MUST be a stuff bit (of the opposite state), which you ignore (except at the end of the message where stuff bits aren’t used) I will post my code for this if you’re interested.