I use MC9S08DZ60 and I must make a CAN application, but I am not able to do the can filter.
I set the CANIDAC register fo two filter of 32 bit, the CANIDAR0/3 registers with my ID that I want to filter and the CANIDMR0/3 with the mask, how it is written on data sheets, but it does not function
I write the example that I am doing
CANIDAC=0x00 obviously written with its procedure
CANIDAR0=0x18
CANIDAR1=0xFF
CANIDAR2=0x00
CANIDAR3=0x00
CANIDMR0=0x00
CANIDMR0=0x00
CANIDMR0=0xff
CANIDMR3=0xff
With this mask I want to applicate the filter only at the four initial byte and the other are do not care.
Can someone help me? Does someone know what I make the mistake?
Thanks.
Bye
已解决! 转到解答。
francy wrote:CANIDAR0=0x18
CANIDAR1=0xFF
CANIDAR2=0x00
CANIDAR3=0x00
I do not understood:
"So IDs accepted are from (1<<25)|(1<<24)|(0x3F <<15) = 0x31F8000 to 0x31F807F, both RTR=1 and RTR=0"
Bit4 from CANIDAR0 is ID25 (bit25 of extended CAN identifier), that's 2^25 or 1<<25
Bit3 from CANIDAR0 is ID24, 1<<24
All CANIDAR1 bits are set, that's 6 conseutive bits from ID20 to ID15. Binary consisting of 6 ones equals 2^6 -1 = 0x3F. Least of these bits is bit15 of CAN identifier, so we need to shift 0x3F left by 15 bit positions, 0x3F << 15.
You want to accept 0x18FF0000 to 0x18FFFFFF. 0x18FF0000 identifier has ones from bit16(ID16) to bit28(ID28) (not as you said id20 to id13). Now look again at extended id mapping.
CANIDAR0 = 0xFF; // ID28..ID21 are set
CANIDAR1 = 0xE6 | 0x18; // ID20..ID16 are set, plus IDE and SRR are set
Since all other bits (and probably RTR, you didn't say) are don't care, you don't have to set up CANIDAR2 and CANIDAR3.
Now masks.
CANIDMR0 = 0; // received ID28..ID21 have to match what's specified in IDAR0
CANIDMR1 = 1; // received ID20..ID16 (but not ID15), IDE, SRR have to match what's specified in IDAR1
CANIDMR2 = 0xFF; // ID14..ID7 are don't care
CANIDMR3 = 0xFF; // ID6..ID0 and RTR are don't care
See attached pictures from datasheet. One picture shows Standard identifier (IDE=0) mapping (which ID bit in which Tx/Rx buffer register/register_bit). Another picture shows the same for Extended identifier (IDE=1, SRR=1).
Acceptance filters, both IDARx and IDMRx have exactly the same ID mappings.
IDMRx bit set to '1' makes corresponding IDRx bit don't care (bit is passed). IDMRx bit set to '0' makes filter passing only if corresponding IDRx bit matches corresponding IDARx bit.
If 8 bit mode, acceptance filters analyse only IDR0 register. In standard mode, thats ID bits ID10 to ID3. In extended - ID28 to ID21. All other ID bits are don't care.
In 16bit mode, IDR0 and IDR1 registers are analysed.
Is it now more clear?
Let's analyse what's your setup would accept. You didn't setup CANIDMR1 and CANIDMR2. As docs say, by default IDMRx are reset to 0. So CANIDMR0-CANIDMR2 = 0, CANIDMR=0xFF. IDR3 bits are don't care, IDR0-IDR2 bits have to match IDAR0-IDAR1 bits.
CANIDAR1 = 0xFF, so IDE=1 and SRR = 1, so only eExtended identifier messages are accepted.
CANIDAR0= 0x18, so ID25=1, ID24=1.
CANIDAR1=0xFF, so ID20..ID15=1
CANIDMR3 = 0xFF, so all combinations of ID6..ID0 are accepted.
So IDs accepted are from (1<<25)|(1<<24)|(0x3F <<15) = 0x31F8000 to 0x31F807F, both RTR=1 and RTR=0.
Try using search at bottom of this page. It should reveal some more answers.
Hi kef,
I have alredy seen that picture on datasheet and I am using the extend identifier.
In my example I made a mistake of writing; the correct configuration is
CANIDAR0=0x18
CANIDAR1=0xFF
CANIDAR2=0x00
CANIDAR3=0x00
CANIDMR0=0x00
CANIDMR1=0x00
CANIDMR2=0xff
CANIDMR3=0xff
I do not understood:
"So IDs accepted are from (1<<25)|(1<<24)|(0x3F <<15) = 0x31F8000 to 0x31F807F, both RTR=1 and RTR=0"
I want that IDs accepted are from 0x18ff0000 to 0x18ffffff. How can I do?
I also used another configuration
CANIDAR0=0x18
CANIDAR1=0xFF
CANIDAR2=0xC0
CANIDAR3=0x00
CANIDMR0=0x00
CANIDMR1=0x00
CANIDMR2=0x3f
CANIDMR3=0xff
so from id20 to id13 are 1 and srr and ide are also 1,but the result don not change.
I am not able that IDs accepted are from 0x18ff0000 to 0x18ffffff
Thanks
francy wrote:CANIDAR0=0x18
CANIDAR1=0xFF
CANIDAR2=0x00
CANIDAR3=0x00
I do not understood:
"So IDs accepted are from (1<<25)|(1<<24)|(0x3F <<15) = 0x31F8000 to 0x31F807F, both RTR=1 and RTR=0"
Bit4 from CANIDAR0 is ID25 (bit25 of extended CAN identifier), that's 2^25 or 1<<25
Bit3 from CANIDAR0 is ID24, 1<<24
All CANIDAR1 bits are set, that's 6 conseutive bits from ID20 to ID15. Binary consisting of 6 ones equals 2^6 -1 = 0x3F. Least of these bits is bit15 of CAN identifier, so we need to shift 0x3F left by 15 bit positions, 0x3F << 15.
You want to accept 0x18FF0000 to 0x18FFFFFF. 0x18FF0000 identifier has ones from bit16(ID16) to bit28(ID28) (not as you said id20 to id13). Now look again at extended id mapping.
CANIDAR0 = 0xFF; // ID28..ID21 are set
CANIDAR1 = 0xE6 | 0x18; // ID20..ID16 are set, plus IDE and SRR are set
Since all other bits (and probably RTR, you didn't say) are don't care, you don't have to set up CANIDAR2 and CANIDAR3.
Now masks.
CANIDMR0 = 0; // received ID28..ID21 have to match what's specified in IDAR0
CANIDMR1 = 1; // received ID20..ID16 (but not ID15), IDE, SRR have to match what's specified in IDAR1
CANIDMR2 = 0xFF; // ID14..ID7 are don't care
CANIDMR3 = 0xFF; // ID6..ID0 and RTR are don't care