Author Topic: CAN controller SJA1000  (Read 1407 times)

0 Members and 1 Guest are viewing this topic.

Offline lorenrusTopic starter

  • Regular Contributor
  • *
  • Posts: 64
  • Country: it
CAN controller SJA1000
« on: May 28, 2021, 10:22:59 am »
hi

can you help me to understand how can i calculate the AMR and ACR values for my case.

my ID are 0x301, 0x309, 0x308.

0x301 --> 001100000001

0x308 --> 001100001000

0x309 --> 001100001001

The 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 --> 1100000001

0x308 --> 1100001000

0x309 --> 1100001001

So now if i have to consider only 8 MSB, i have:

                |--MSB--|
0x301 --> 11000000  01

0x308 --> 11000010  00

0x309 --> 11000010  01

Now 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 --> 110000X0 

0x308 --> 110000X0

0x309 --> 110000X0

For 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 bit



NOTE:
                               bit 7 | bit 6 | bit 5 | bit 4 | bit 3 | bit 2 | bit 1 | bit 0
Ordination of bits -->   1   |   1    |   0    |   0    |   0   |   0   |   X    |   0


For my case:

0x301 --> 110000X0 

0x308 --> 110000X0

0x309 --> 110000X0

AMR ----> 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 if
            it 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, instead
         the 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 --> 0x61000000

AMR --> 0x01FFFFFF

Can you help me ?
 

Offline Nominal Animal

  • Super Contributor
  • ***
  • Posts: 6239
  • Country: fi
    • My home page and email address
Re: CAN controller SJA1000
« Reply #1 on: May 28, 2021, 01:34:49 pm »
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 be
   ACR = 0x60 or 0x61 (both work equally well)
   AMR = 0x01

In binary,
   ACR = 0b0110000x (where x indicates the bit value does not matter)
   AMR = 0b00000001

This 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.g NXP 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=0x1F
ACR2=0x61, ACR3=0x00, AMR2=0x00, AMR3=0x1F
Essentially, 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 the numerous edits.  I'm not familiar with this device, took me a bit to get it right.)
« Last Edit: May 28, 2021, 02:19:53 pm by Nominal Animal »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf