Sample code for CAN driver of MC9S12G128

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

Sample code for CAN driver of MC9S12G128

583 Views
Raaaj
Contributor I

Hi,

Please provide the sample code for CAN driver of MC9S12G128.

I am facing problem while initiating CAN driver.

By reset its entering into Initialization mode. I am initialising all the registers and setting Ctrl register bit to enter in normal mode. But its not coming out of initialisation mode.

Please refer the following code for reference.

  CAN_Module_Ptr -> TppCAN_Register.uc_Ctl0 = 0xFE;

  while (INITAK_BIT == (CAN_Module_Ptr -> TppCAN_Register.uc_Ctl1 \
                        & INITAK_BIT) )
  {
    /* wait for init mode to be released */
  }

Please provide the solution as soon as possible.

 

Regards,

Rajan

Labels (1)
0 Kudos
1 Reply

222 Views
Lundin
Senior Contributor IV

- Most (all?) register accesses in MSCAN requires the CAN module to be enabled. Do do this, set bit CANE in CANCTL1, before doing anything else. Note that this bit is "write-once", meaning that if you somehow manage to write a zero to it, the MSCAN module will be disabled.

 

- Are you actually trying to write value 0xFE to CANCTL0? If so, are you sure this makes any sense at all for your particular application? Some of those bits are read-only flags.

 

- Your code might rely correct on implicit integer promotion of INITAK_BIT, which is likely a bit field, to something that makes sense. Do you know how bit fields are promoted for your particular compiler? There are no guarantees from the C standard.

 

- Your while loop runs while a flag is high, instead of waiting for a flag to get high. It would make more sense to write something like while ((CAN_Module_Ptr -> TppCAN_Register.uc_Ctl1& INITAK_BIT)==0) { /* wait */}.

0 Kudos