Forum: Mikrocontroller und Digitale Elektronik CAN: Denkfehler?


von Joachim .. (joachim_01)


Lesenswert?

Ich mach hier grad Versuche (AT91SAM3X8E) um Busnachrichten (Standard 
Message-ID, 11Bit) zu filtern. Die Nachrichten werden von CAN-Modul 0 zu 
Modul 1 geschickt.

Folgende IDs sollen gefiltert werden:
000100 0 11 00  ID0 = 0x08C
000100 0 11 01  ID1 = 0x08D
000100 0 11 10  ID2 = 0x08E
000100 0 11 11  ID3 = 0x08F
000100 1 11 00  ID4 = 0x09C
000100 1 11 01  ID5 = 0x09D
000100 1 11 10  ID6 = 0x09E
000100 1 11 11  ID7 = 0x09F


Das Kochrezept dazu:

The CAN_MIDx (Message ID Nr.x) and CAN_MAMx (message acceptance mask 
Nr.x) of Mailbox x must be initialized to the corresponding values:
CAN_MIDx = 000 100 x 11 xx = 0x08C
CAN_MAMx = 111 111 0 11 00 = 0x7EC
Ok, hab ich verstanden.

Dann:
If Mailbox x receives a message with ID6, then CAN_MIDx and CAN_MFIDx 
are set:
CAN_MIDx  = 000 100 1 11 10 = 0x09E  //ID6
CAN_MFIDx = 000 000 0 01 10 = 0x006  //Filter ID (Atmel benutzt das Wort 
Family ID, ist aber mMn das gleiche wie Filter ID)
Ok.
1
/**
2
 *  \brief Test ID mask and Family ID (Filter) from CAN0 Mailbox 0 to CAN1 Mailbox 0.
3
     Use rotary encoder for different message ID 
4
 */
5
void test_7(uint16_t MIDToSend)
6
{  uint16_t dataToSend;
7
  static uint8_t uc_suppress = 0;
8
  if (!uc_suppress) {
9
    puts("\n\rTest Message Acceptance Mask + FID, SID selected with rotary encoder, CAN0 Mailbox 0 -> CAN1 Mailbox 0"  STRING_EOL);
10
  uc_suppress = 1;
11
  }
12
  can_reset_all_mailbox(CAN0);
13
  can_reset_all_mailbox(CAN1);
14
  
15
    /* Init CAN1 Mailbox 0 to Reception Mailbox. */    
16
    //  CAN_MIDx  = 000100 x 11 xx = 0x08C
17
    //  CAN_MAMx  = 111111 0 11 00 = 0x7EC
18
    //  CAN_MFIDx = 000000 0 01 10 = 0x006
19
    reset_mailbox_conf(&can1_mailbox);
20
    can1_mailbox.ul_mb_idx = TEST7_CAN_COMM_MB_IDX; //Mailbox 0...7
21
    can1_mailbox.uc_obj_type = CAN_MB_RX_MODE;
22
    can1_mailbox.ul_id_msk =  0x7EC; //CAN_MAM_MIDvA_Msk | CAN_MAM_MIDvB_Msk;
23
    can1_mailbox.ul_id = CAN_MID_MIDvA(0x08C);// CAN_MID_MIDvA(TEST7_CAN_TRANSFER_ID);
24
    can1_mailbox.ul_fid = 0x006;      //Filter ID
25
    can_mailbox_init(CAN1, &can1_mailbox);
26
  
27
  
28
  
29
  /* Init CAN0 Mailbox 0 to Transmit Mailbox. */
30
  reset_mailbox_conf(&can0_mailbox);
31
  can0_mailbox.ul_mb_idx = TEST6_CAN_COMM_MB_IDX;
32
  can0_mailbox.uc_obj_type = CAN_MB_TX_MODE;
33
  can0_mailbox.uc_tx_prio = TEST6_CAN0_TX_PRIO;
34
  can0_mailbox.uc_id_ver = 0;
35
  can0_mailbox.ul_id_msk = 0;
36
  can_mailbox_init(CAN0, &can0_mailbox);
37
38
  /* Write transmit information into mailbox. */
39
  can0_mailbox.ul_id = CAN_MID_MIDvA(MIDToSend); // TEST6_CAN_TRANSFER_ID);
40
  can0_mailbox.ul_datal = (MIDToSend + 0x0100);  //Nachricht...
41
  can0_mailbox.ul_datah = CAN_MSG_DUMMY_DATA;
42
  can0_mailbox.uc_length = MAX_CAN_FRAME_DATA_LEN;
43
  can_mailbox_write(CAN0, &can0_mailbox);
44
45
  /* Enable CAN1 mailbox 0 interrupt. */
46
  can_enable_interrupt(CAN1, CAN_IER_MB0);
47
48
  /* Send out the information in the mailbox. */
49
  can_global_send_transfer_cmd(CAN0, CAN_TCR_MB0);
50
51
    while (!g_ul_recv_status); //kommt von CAN-ISR
52
    // Ab hier nur noch Anzeige
53
    uint32_t ul_val, ul_val2 = 0;
54
55
    puts("Test7 passed" STRING_EOL);
56
    printf("CAN1 RX Mailbox 0:\r");
57
  
58
    ul_val = (uint32_t *)(CAN1->CAN_MB[0].CAN_MDH);
59
    ul_val2 = (uint32_t *)(CAN1->CAN_MB[0].CAN_MDL);
60
    printf("Dat Hi:  MDH\t%08X\t\t\tDat Lo:  MDL\t%08X\r", ul_val, ul_val2);
61
    
62
    ul_val = (uint32_t *)(CAN1->CAN_MB[0].CAN_MFID);
63
    ul_val2 = (uint32_t *)(CAN1->CAN_MB[0].CAN_MID);
64
    printf("FAM ID:  MFID\t%08X\t\t\tID:      MID\t%08X\r\r", ul_val, ul_val2);
65
}

Bei mir passiert jetzt was ganz seltsames: Bei jeder Aussendung einer 
neuen Standard ID verändert sich die Filter-ID ebenfalls (Ist das der 
Fehler?). Dadurch wird jede Nachricht upgedatet - eine Filterung findet 
nicht statt.

Hab ich was verwexelt? Gehört das so? Fehlt etwas?

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.