cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F10X - CAN not working when using certain values within message

bernhard
Associate II
Posted on April 24, 2014 at 17:27

Dear everybody,

I found a strange behaviour, which I have no explanation for currently. This code doesn't work

NCAN_Outgoing.DLC = 8;
NCAN_Outgoing.ExtId = 0;
NCAN_Outgoing.IDE = CAN_ID_STD;
NCAN_Outgoing.RTR = CAN_RTR_DATA;
NCAN_Outgoing.StdId = 0x7DF;
NCAN_Outgoing.Data[0] = 0x02;
NCAN_Outgoing.Data[1] = 0x09;
NCAN_Outgoing.Data[2] = 0x02;
NCAN_Outgoing.Data[3] = 0x00;
NCAN_Outgoing.Data[4] = 0x00;
NCAN_Outgoing.Data[5] = 0x00;
NCAN_Outgoing.Data[6] = 0x00;
NCAN_Outgoing.Data[7] = 0x00;

whereas the exact same code with 0x5FF (and every lower value) doesnt work (meaning no transmission is detected by other devices in the CAN)

NCAN_Outgoing.DLC = 8;
NCAN_Outgoing.ExtId = 0;
NCAN_Outgoing.IDE = CAN_ID_STD;
NCAN_Outgoing.RTR = CAN_RTR_DATA;
NCAN_Outgoing.StdId = 0x5FF; 
//only differece
NCAN_Outgoing.Data[0] = 0x02;
NCAN_Outgoing.Data[1] = 0x09;
NCAN_Outgoing.Data[2] = 0x02;
NCAN_Outgoing.Data[3] = 0x00;
NCAN_Outgoing.Data[4] = 0x00;
NCAN_Outgoing.Data[5] = 0x00;
NCAN_Outgoing.Data[6] = 0x00;
NCAN_Outgoing.Data[7] = 0x00;

I appreciate any advice. Thank you all very much in advance! #can
6 REPLIES 6
glory_man
Associate II
Posted on April 25, 2014 at 09:23

As far as I understand

CAN-frames

with

ID=0x5FF

are recepted by other devices on CAN bus

, while

with

ID = 0x7DF

not.

What kind of

 

''other devices

in the

CAN''?

How are they

configured

?

bernhard
Associate II
Posted on April 25, 2014 at 10:10

thanks for the reply, glory.man - I appreciate it!

I used several devices, e.g. a ETAS CAN-Link II or a car (haha) with no filters active. Standard CAN Messages (''standard adressing'' using 11 Bits) should range from 0b00 0000 0000 (0x000) to 0b111 1111 1111 (0x7FF) so there sould be no problemo!

''

As far as I understand

 

CAN-frames

 

with

 

ID=0x5FF

 are recepted by other devices on CAN bus, while 

with

 

ID = 0x7DF

 

not.'' - exactly, or even a little bit more precise:

CAN-Frames with ID <= 0x5FF are recepted while IDs > 0x5FF are not.

bernhard
Associate II
Posted on April 25, 2014 at 11:24

Found another strange behaviour:

NCAN_Outgoing.DLC = 8;
NCAN_Outgoing.ExtId = 0;
NCAN_Outgoing.IDE = CAN_ID_STD;
NCAN_Outgoing.RTR = CAN_RTR_DATA;
NCAN_Outgoing.StdId = 0x7DF;
NCAN_Outgoing.Data[0] = 0x02;
NCAN_Outgoing.Data[1] = 0x10;
NCAN_Outgoing.Data[2] = 0x02;
NCAN_Outgoing.Data[3] = 0x00;
NCAN_Outgoing.Data[4] = 0x00;
NCAN_Outgoing.Data[5] = 0x00;
NCAN_Outgoing.Data[6] = 0x00;
NCAN_Outgoing.Data[7] = 0x00;

works, while everything lower in the second databate does not

NCAN_Outgoing.DLC = 8;
NCAN_Outgoing.ExtId = 0;
NCAN_Outgoing.IDE = CAN_ID_STD;
NCAN_Outgoing.RTR = CAN_RTR_DATA;
NCAN_Outgoing.StdId = 0x7DF;
NCAN_Outgoing.Data[0] = 0x02;
NCAN_Outgoing.Data[1] = 0x09;

// only difference

NCAN_Outgoing.Data[2] = 0x02;
NCAN_Outgoing.Data[3] = 0x00;
NCAN_Outgoing.Data[4] = 0x00;
NCAN_Outgoing.Data[5] = 0x00;
NCAN_Outgoing.Data[6] = 0x00;
NCAN_Outgoing.Data[7] = 0x00;

How is that possible?
glory_man
Associate II
Posted on April 25, 2014 at 15:02

It's really strange

-

usually

can-

controllers

uses ID filtering for

frames

,

not

the data filterring.

To transmit data you need to select one empty transmit mailbox - may be there is no empty MB.

Can you

add to

your

CAN_TX_IRQHandler

incremented counter

and

check

its value

(for  example you can transmitt its value via CAN with ''good'' ID )?

May be this is software trick of other CAN-devices - i.e. they are uses some data protocol to decode data.

It would be

nice to use some kind of CAN-logger (an

alyzer) to check CAN-bus state -

and make sure

that the data

with that ID

is not transmitted.

jpeacock2399
Associate II
Posted on April 25, 2014 at 15:48

This looks more like a problem with whatever CAN protocol your devices are using.  Yes, a message identifier can be anywhere in the 11 bit range, but that's no guarantee it won't be ignored by other devices on the bus.

For example, in CANopen protocol the 0x7df identifier is in the range used by the service that assigns node numbers dynamically, the equivalent of DHCP on a TCP/IP network.  Chances are the other devices do receive the message but are not processing it.  This assumes filtering doesn't block it, and if these are commercial devices you may have no way of knowing what message IDs the devices will ignore.

The other possibility is you are colliding with an identifier used by another device on the same bus.  Message identifiers are supposed to be unique to a node except in special cases where you know there won't be a collision.

Try sending the message between two STM32 nodes.  If it works you will know the problem is in someone else's box.

  Jack Peacock
Posted on April 25, 2014 at 16:02

This looks more like a problem with whatever CAN protocol your devices are using...Try sending the message between two STM32 nodes.  If it works you will know the problem is in someone else's box.

Totally this!

The measurements you make are only as good as the tools making the measurement.

Typically you'd want to find analysis equipment that's an order of magnitude better (functionality, bandwidth, cost, etc) than the signal/protocol you want to observe.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..