CAN controller SJA1000 - Page 1
Forum section: electronics / general

author: lorenrus
author_rank: Regular Contributor
timestamp: May 28, 2021, 10:22:59 am
content: hican you help me to understand how can i calculate the AMR and ACR values for my case.my ID are 0x301, 0x309, 0x308.0x301 --> 0011000000010x308 --> 0011000010000x309 --> 001100001001The datasheet say that i have to consider only the MSB of ID, so for my case:I think that i can remove the two zeros on the left side and the ID become:0x301 --> 11000000010x308 --> 11000010000x309 --> 1100001001So now if i have to consider only 8 MSB, i have:|--MSB--|0x301 --> 11000000 010x308 --> 11000010 000x309 --> 11000010 01Now i have to do some conderations, i have to analyze wich bits are common and which not.For the bit that are different i rplace them with "X".0x301 --> 110000X00x308 --> 110000X00x309 --> 110000X0For AMR:- 1: the value of the bit is indifferent it passes- 0: before to pass it has to match with the value of ACR in the same position of the bitNOTE:bit 7 | bit 6 | bit 5 | bit 4 | bit 3 | bit 2 | bit 1 | bit 0Ordination of bits --> 1 | 1 | 0 | 0 | 0 | 0 | X | 0For my case:0x301 --> 110000X00x308 --> 110000X00x309 --> 110000X0AMR ----> 00000010 -> Because i want that bits 7,6,5,4,3,2,0 are exactly exactly what I find in the IDs. And for bit 1 is indifferent ifit assumes 0 or 1.ACR ----> 110000-0 -> As a consequence, the group of bits 7,6,5,4,3,2,0 must be exactly the same as the one present in the ID, insteadthe bit 0 I understood that in this case it is indifferent whether it is 0 or 1, is it correct?This is my reasoning, now I give you the values ​​that I find written by another:ACR --> 0x61000000AMR --> 0x01FFFFFFCan you help me ?

author: Nominal Animal
author_rank: Super Contributor
timestamp: May 28, 2021, 01:34:49 pm
content: CAN message identifiers are 11-bit values. Your IDs are 0x301 = 0b01100000001, 0x308 = 0b01100001000, and 0x309 = 0b01100001001.The eight most significant bits are with respect to the 11-bit value; it does not depend on which is the highest bit in your ID.That is, the eight most significant bits of your IDs are 0x60 = 0b01100000, 0x61 = 0b01100001, and 0x61 = 0b01100001.AMR selects which bits of ACR are compared. A zero bit in AMR means the corresponding bit in ACR is used, a set bit that the ACR bit is irrelevant.Therefore, here the register values must beACR = 0x60 or 0x61(both work equally well)AMR = 0x01In binary,ACR = 0b0110000x(wherexindicates the bit value does not matter)AMR = 0b00000001This configuration matches all CAN IDs between 0x300 = 0b01100000000 through 0x30F = 0b01100001111.The above assumes you do use BasicCAN mode, and not the full SJA1000 ACR/AMR capabilities as described in e.gNXP SJA1000 datasheet (PDF). The NXP SJA1000 has four ACR and four AMR registers, 8 bits each, that can be used as either a single 32-bit acceptance filter, or as a dual 16-bit acceptance filter (see pages 26 and 44-45 of the datasheet).In your case, the alternative suggestion, using ACR0=0x60, ACR1=0x00, ACR2=0x00, ACR3=0x00, AMR0=0x01, AMR2=0xFF, AMR3=0xFF, implements the single-filter version of the BasicCAN filter above, but in SJA1000 "native" (PeliCAN?) mode.You could also use the dual filter mode (see page 46 of the datasheet), by setting the AFM bit to zero (acceptance filter mode, MOD.3).Essentially, the filter is split into two equal parts, and if either filter signals acceptance, the message is accepted.In your case, the first filter could match 0x301 and 0x309, and the second filter 0x308. That way only these three messages match, and none else.ACR0=0x60, ACR1=0x20, AMR0=0x01, AMR1=0x1FACR2=0x61, ACR3=0x00, AMR2=0x00, AMR3=0x1FEssentially, the first filter is 0b0110000x001zzzzz, and the second filter is 0b01100001000zzzzz, where x indicates either 0 or 1 is accepted, and z are set according to the datasheet on page 44.TL;DR:ACR=0x60 (or 0x61) and AMR=0x01 uses the BasicCAN mode to match message IDs 0x300 through 0x30F, inclusive.ACR=0x60000000 (or 0x61000000 or 0x61FFFFFF) and AMR=0x01FFFFFF uses the non-BasicCAN single filter mode (set MOD.3 bit!)to match message IDs 0x300 through 0x30F, inclusive.ACR=0x60206100 (or 0x61206100 or 0x612F610F) and AMR=0x011F001F uses the non-BasicCAN dual filter mode (clear MOD.3 bit!)to match message IDs 0x301, 0x308, and 0x309.(Apologies about thenumerousedits. I'm not familiar with this device, took me a bit to get it right.)