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
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
Hi Ladislav,
thank you!
I will check in the attachments.
Best regards,
Andrea
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
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
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:
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:
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.
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