cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F103RB CAN J1939 identifier

Nicolas Cmb
Associate III
Posted on June 19, 2017 at 13:45

Hi evryone, I'm using STM32f103rb card to communicate with another STM32f103rb thanks to STM32F103Rb CAN protocole, and I'm looking for using J1939.

I have parameter my identifier like that :

hcan.pTxMsg->StdId = 0x01;

hcan.pTxMsg->ExtId = 0x01DAD4DC1;

hcan.pTxMsg->RTR = CAN_RTR_DATA;

hcan.pTxMsg->IDE = CAN_ID_EXT;

hcan.pTxMsg->DLC = 8;

and I'm trying to configurate my filter, but I've no idea of what could be the following configurations :

sFilterConfig.FilterIdHigh 

sFilterConfig.FilterIdLow

sFilterConfig.FilterMaskIdHigh

sFilterConfig.FilterMaskIdLow

sFilterConfig.BankNumber 

Anyone can help me ?

Thanks for your attention,

Regards,

Nicolas.
7 REPLIES 7
Posted on June 19, 2017 at 14:44

https://community.st.com/0D50X00009XkYJGSA3

You have to construct the mask and id so the comparator in the peripheral can recognize the specific bit pattern

The mask is ANDed with the bit stream and the ID is then compared.

https://community.st.com/0D50X00009XkXx6SAF

The EXID complicates the construction of the bit patterns, but look at the diagram of what the chip is looking for.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on June 19, 2017 at 18:37

HCANFilter_Struct.FilterIdHigh = (EXTID >> 13) & 0xFFFF; // 29-bit EXTID

HCANFilter_Struct.FilterIdLow = ((EXTID << 3) & 0xFFF8) | 4;

HCANFilter_Struct.FilterMaskIdHigh = 0xFFFF; // MSB

HCANFilter_Struct.FilterMaskIdLow = 0xFFFC; //LSB
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on June 21, 2017 at 10:36

thank you so much, but I need to know how you have doing this

Posted on June 21, 2017 at 10:46

I read the others link you send and I'm trying to understand but I don't really know how you have doing this 

Posted on June 21, 2017 at 17:40

Don't over think the problem, silicon implementation tend to take the most simple and straight-forward design decisions.

The peripheral is processing a stream of bits, the filter is Masking the bits it wants to inspect with an AND, and then matching the bit pattern left with a comparator.

The manual describes the bit ordering of the data stream.

A critical skill to learn is to read the manual and understand the logic they describe. If it is too complex, go back to simpler concepts and understand binary representation, bits and logic operations (AND, OR, XOR, NAND, NOR, etc)

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on June 22, 2017 at 10:49

If I've understand,the filter bank scale configuration that we use is this one:

0690X00000607SaQAI.png

And you use :

''HCANFilter_Struct.FilterIdHigh = (EXTID >> 13) & 0xFFFF;'' for go to EXID [17:13] 

And ''

HCANFilter_Struct.FilterIdLow = ((EXTID << 3) & 0xFFF8) | 4;'' for go just after IDE

am I right?

Thanks for all your help

Posted on June 22, 2017 at 16:41

Yes, I'm manipulating the 29-bit ID into the pair of 16-bit registers, and also checking for the bit defining it as using the extended ID. Thus the patterns that match the comparison are posted to the FIFO, and the rest are ignored.

If you are looking to match a range of IDs then you'd adapt the mask to allow a bigger group of messages to be collected. If the bit positions don't fully accommodate this, then you can use multiple filters, or apply a fine grain filtering in software once you pull the message from the FIFO. The goal of the filters being to decimate the work load.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..