Both CAN standard and extended ID in HCS12

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Both CAN standard and extended ID in HCS12

4,122 Views
andreacavazzoni
Contributor II

Hi,

in my project I need to manage CANBUS messaging (Tx and Rx) both with standard (11bit) and extended protocol (29bit). The microcontroller is unique (MC9S12G240) and the bus can be the same (CAN0).

The microcontroller datasheet writes that it can be done.
Are there any examples or application notes about it?

Thank you and best regards,

Andrea Cavazzoni

Tags (2)
0 Kudos
Reply
6 Replies

3,534 Views
lama
NXP TechSupport
NXP TechSupport

Hi,

I would like to add...

CAN Standard ID and CAN Extended ID for S12(X) and MagniV devices, memories refreshment 

... and small set of examples which can lead you in your design.

BTW, if you use filter you can decide which type of message and ID you filter. See excel. If you do not use HW  filter to filter messages you can check and decode all received frames following your requirements by SW.

Attached examples are for set of MCUs but the same approach and also the same code.

Best regards,

Ladislav

0 Kudos
Reply

3,534 Views
andreacavazzoni
Contributor II

Hi Ladislav,

thank you!

I will check in the attachments.

Best regards,

Andrea

0 Kudos
Reply

3,534 Views
kef2
Senior Contributor V

Hi,

what about reading datasheets? These two figures are your friends.

Figure 18-24. Receive/Transmit Message Buffer — Extended Identifier Mapping

Figure 18-25. Receive/Transmit Message Buffer — Standard Identifier Mapping

IDE bit =0 in both receive/transmit buffer means that ID is standard, IDE=1 means ID is extended.

Do you need acceptance filters? Well, their bit mapping is the same. Since you have a mix of messages with standard and extended ID's, you have to not ignore IDE bit, but set up particular filter to either accept only IDE=0 messages or accept only IDE=1 messages. And since IDE bit is not in the first message buffer location, but in the second, you can't use 8-bit acceptance filters, you need to use 16- or 32-bit acceptance filters.

Edward

0 Kudos
Reply

3,534 Views
andreacavazzoni
Contributor II

Hi Edward,

I mean chapter "18.4.3 Identifier Acceptance Filter", in particular figure 18-40 for receiving messages. I think that with 2 32bit masks (1 for standard protocol and the other for extended) the reception is possible.

I can receive both standard (e.g. 0x500, 0x518, 0x570, ...) and extended (e.g. 0x18DAC3F1).

I have to transmit both standard and extended. This is the point I need example to understand better.

Thank you

Andrea

0 Kudos
Reply

3,534 Views
kef2
Senior Contributor V

I mean chapter "18.4.3 Identifier Acceptance Filter", in particular figure 18-40 for receiving messages. I think that with 2 32bit masks (1 for standard protocol and the other for extended) the reception is possible.

I can receive both standard (e.g. 0x500, 0x518, 0x570, ...) and extended (e.g. 0x18DAC3F1).

Again, understanding of all of this is in these two pictures:canid1.png

canid2.png

The difference is IDE bit. Then, since Std and Ext ID bit mapping in buffer and acceptance filters is different, you need one filter(s) for standard message(s) and another one(s) for extended message(s). If you do it wrong (the same filter for both Std and Ext), you may falsely accept standard ID=1 (ID0 bit = 1) message in filter for extended ID=(1<<18) = 0x40000 (ID18 bit = 1). Do you see already that they are in the same locations? Message filters have the same mapping as ID bits in message tx/rx buffers.

Here’s what ID, RTR, IDE etc bits different filters apply to:

canid3.png

As you may see to make filter properly filtering correctly standard or extended messages from the mix of Std and Ext messages, filter has to include IDE bit location, that’s why 16 and 32 bit filters are good for your application and 8 bit filters are not good.

 

standard (e.g. 0x500, 0x518, 0x570, ...) to msg buffer

IDR0 = (unsigned int)id >> 3;

IDR1 = id << 5;

Back to id

Id = ((unsigned int) IDR1 >> 5) + ((unsigned int)IDR0 << 3);

 

extended (e.g. 0x18DAC3F1) to msg buffer

IDR3 = id << 1;

IDR2 = id >> 7;

IDR1 = ((id >> 15) & 7) | 0x18 | ((id >> (18-5)) & 0xE0);

IDR0 = id >> 21;

All these shifts are very slow and ineffective on S12(X). It would be better if you could use compile time constants for ID mappings or at least calculate them few times and reuse many times. But that’s up to you.

0 Kudos
Reply

3,534 Views
andreacavazzoni
Contributor II

Hi Edward,

thank you for your exlplanation. It's very clear to me.

I think I will try to use 2x 32bit filters with constants.

Thank you and best regards,

Andrea Cavazzoni

0 Kudos
Reply