Freescale MC9S12X: CAN initialization configuration

Publisher:legend9Latest update time:2021-07-14 Source: eefocusKeywords:Freescale Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1. MSCAN initialization process

Check whether it has entered the initialization state. If not, enter the initialization state.

The CANCTL0 register needs to be set here.

Set the CAN baud rate.

The CANBTR0 and CANBTR1 registers need to be set here.

Set the corresponding CAN port filter.

The CANIDMR register needs to be set here.

Enable the MSCAN module and set the MSCAN clock source.

The CANCTL1 register needs to be set here.

Leave the initialization state and return to normal operation mode.

The CANCTL0 register needs to be set here.

Set the receive interrupt enable.

The CANRIER register needs to be set here.


2. Introduction to MSCAN initialization registers

insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here

3. CAN initialization configuration specific program implementation

/****************************************************************/

/* Initialize CAN0 */

/****************************************************************/

void INIT_MSCAN0(void) 

{

  if(CAN0CTL0_INITRQ==0) // Check whether it has entered the initialization state   

    CAN0CTL0_INITRQ =1; // Enter the initialization state

    

  while (CAN0CTL1_INITAK==0); //Wait to enter the initialization state

 

  CAN0BTR0_SJW = 0; //Set synchronization

  CAN0BTR0_BRP = 7; //Set the baud rate, the pre-scaling factor is 8

  CAN0BTR1 = 0x49; //TSEG1 is 10 time quanta, TSEG2 is 5 time quanta,

  //MSCAN baud rate is 32MHz/8/(1+10+5)=250kHz

  // Turn off the filter                                  

  CAN0IDMR0 = 0xFF;

  CAN0IDMR1 = 0xFF;

  CAN0IDMR2 = 0xFF;

  CAN0IDMR3 = 0xFF;

  CAN0IDMR4 = 0xFF;

  CAN0IDMR5 = 0xFF;

  CAN0IDMR6 = 0xFF;

  CAN0IDMR7 = 0xFF; 

 

  CAN0CTL1 = 0xC0; // Enable the MSCAN module, the MSCAN clock source is the CAN bus clock

     //CAN bus clock frequency is 32MHz

  CAN0CTL0 = 0x00; //Return to normal operation mode

  while(CAN0CTL1_INITAK); //Wait to return to normal operation mode

  while(CAN0CTL0_SYNCH==0); //Wait for bus clock synchronization

  CAN4RFLG_RXF = 1; // Clear the message receiving buffer

  CAN0RIER_RXFIE = 1; //Enable receive interrupt

}

Keywords:Freescale Reference address:Freescale MC9S12X: CAN initialization configuration

Previous article:Freescale MC9S12X: CAN Receive Configuration
Next article:Freescale MC9S12X Time Output Comparison

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号