MSCAN Init S12G96

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MSCAN Init S12G96

Jump to solution
1,082 Views
Michael71
Contributor II

Hi @ all,

 

We're facing a problem with the initialisation of MSCAN Module on Microcontroller S12G96:

 

We used following code to enable MSCAN and to change settings:

void CAN_SETTINGS(void)  {        CANCTL0  = 0x01;        //CANCTL0 = 0000 0001 CAN Control Register 0 (Manual S.224, 225, 267) Einschalten des Sleepmodes                                while ((CANCTL1 & 0x01) != 0x01)   //Warten, bis Init Acknowledge Bit gesetzt ist    {    }                                          CANBTR0 = 0x93;       //CANBTR0 = 1000 1001         MSCAN Bus timing Register 0 (Manual S. 227, 228) Einstellung des Baudratenprescaler (auf Wert 10 = 9+1) und der Synchronisation Jump width (auf Wert 3 = 2+1), +1 ist immer gesetzt!!                             CANBTR1 = 0x3A;       //CANBTR1 = 0011 1010         MSCAN Bus timing Register 1 (Manual S. 228) Einstellung der Samplingrate (auf Wert 1), Time Segment 2 (auf Wert 4 = 3+1) und Time Segment (auf Wert 11 = 10+1, inclusive Propagation Time Segment), +1 ist immer gesetzt!!                   CANCTL1 = 0x80;      //CANCTL1 = 1000 00xx          CAN Control Register 1 (Manual S. 226, 227) Einschalten des MSCAN-Moduls Control Registers                                  CANIDAC = 0x10;       //CANIDAC = 0001 0000 MSCAN Identifier Acceptance Register (Manual S. 236, 237) Einstellung auf 4 16-Bit Acceptance Filter                                  //Filter 1: Filtert einen Bereich von Identifieren 0x400 bis 0x430        CANIDMR0 = 0x07;      //CANIDMR0 = 0000 0000         MSCAN Identifier Mask Register 0 (Manual S. 240)                              CANIDMR1 = 0xFF;      //CANIDMR1 = 0000 0000         MSCAN Identifier Mask Register 1 (Manual S. 240)                                                        CANIDAR0 = 0x84;      //CANIDAR0 = 0000 0000         MSCAN Identifier Acceptance Register 0 (Manual S. 239)                              CANIDAR1 = 0x00;      //CANIDAR1 = 0000 0000         MSCAN Identifier Acceptance Register 1 (Manual S. 239)                                CANIDMR5 = 0x07;      //CANIDAR5 = 0000 0000         MSCAN Identifier Mask Register 5 (Manual S. 240)                                                        CANIDMR7 = 0x07;      //CANIDMR7 = 0000 0000         MSCAN Identifier Mask Register 7 (Manual S. 240)                              CANCTL0 = 0x00;         //CANCTL0 = 0000 0001 CAN Control Register 0 (Manual S.224, 225, 267) Einstellung des Initialisierungsmodes                                   while ((CANCTL1 & 0x01) == 0x01)   //Warten, bis Initial Mode Acknowledge Bit zurückgesetzt ist    {    }            CANRIER = 0x01;        while ((CANCTL0 & 0x10) != 0x10)   //Warten, bis CAN-Bus synchronisiert ist.     {    }  }

 

 

Our problem is, that the initailisation sequence is running until:

 

    while ((CANCTL1 & 0x01) == 0x01)   //Warten, bis Initial Mode Acknowledge Bit zurückgesetzt ist    {    }

The Ínitial mode acknowledge bis will not be set to 0x00 and the programm stays here and doesn't go on anymore.

We tried to set MSCAN to sleep mode also, but it doesn't make any difference.

 

Has anybody an idea what we made wrong?

 

 

Thank you for your kind support.

 

 

Best regards

Michael

Labels (1)
1 Solution
671 Views
StenS
Contributor III

This routine works for me (on 9S12XDT256):

void CAN_Init(void) {   CAN0CTL0 = 1;        /* Initialization Request! */   while (!CAN0CTL1_INITAK);  /* wait until the module is in Initialization Mode */   CAN0CTL1 = 0xC0;     /* Enable MSCAN module and select the Bus Clock */   CAN0BTR0 = CANBTR0_125;    /* set the SJW and PRB for 125 kbit/s */   CAN0BTR1 = CANBTR1_125;    /* set the TSEGs for 125 kbit/s */   CAN0IDAC = 0x20;     /* Eight 8-Bit Acceptance Filters */   CAN0IDMR0 = 0xff;    /* Set all mask registers to 'Don't Care' */   CAN0IDMR1 = 0xff;   CAN0IDMR2 = 0xff;   CAN0IDMR3 = 0xff;   CAN0IDMR4 = 0xff;   CAN0IDMR5 = 0xff;   CAN0IDMR6 = 0xff;   CAN0IDMR7 = 0xff;   CAN0CTL0 = 0;        /* Normal Operation! */   while (CAN0CTL1_INITAK);  /* wait until the module has left the Initialization Mode */   CAN0RIER = 3;        /* Receiver Full and Overrun Interrupt Enable */}

 /Sten

 

View solution in original post

2 Replies
672 Views
StenS
Contributor III

This routine works for me (on 9S12XDT256):

void CAN_Init(void) {   CAN0CTL0 = 1;        /* Initialization Request! */   while (!CAN0CTL1_INITAK);  /* wait until the module is in Initialization Mode */   CAN0CTL1 = 0xC0;     /* Enable MSCAN module and select the Bus Clock */   CAN0BTR0 = CANBTR0_125;    /* set the SJW and PRB for 125 kbit/s */   CAN0BTR1 = CANBTR1_125;    /* set the TSEGs for 125 kbit/s */   CAN0IDAC = 0x20;     /* Eight 8-Bit Acceptance Filters */   CAN0IDMR0 = 0xff;    /* Set all mask registers to 'Don't Care' */   CAN0IDMR1 = 0xff;   CAN0IDMR2 = 0xff;   CAN0IDMR3 = 0xff;   CAN0IDMR4 = 0xff;   CAN0IDMR5 = 0xff;   CAN0IDMR6 = 0xff;   CAN0IDMR7 = 0xff;   CAN0CTL0 = 0;        /* Normal Operation! */   while (CAN0CTL1_INITAK);  /* wait until the module has left the Initialization Mode */   CAN0RIER = 3;        /* Receiver Full and Overrun Interrupt Enable */}

 /Sten

 

671 Views
Michael71
Contributor II

Hello Stan,

 

thank you very much for your Code.

 

We tried this Code out and it works.

We found out that the problem is to enable the Oscillator clock as the clock source.

 

Thanks again,

Michael

0 Kudos
Reply