Freescale MC9S12X: CAN Receive Configuration

Publisher:qq8174350Latest 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 receiving process

Detect receive flag: The CANRFLG register is used here.

Detect frame mode (standard frame/extended frame): The CANIDR register is used here.

Read identifier: The CANIDR register is used here.

Determine the frame format (remote frame/data frame): The CANIDR register is used here.

Read data length: The CANDLR register is used here.

Read data: The CANDSR register is used here.

Clear the receive flag: The CANTFLG register is used here.


2. Introduction to MSCAN Receive Register

There are two types of CANIDR registers: standard frame type and extended frame type.

Standard frame type:

insert image description here

Extended frame type:

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

3. CAN receiving configuration specific program implementation

1. Standard frame program

The specific code is as follows:


struct can_msg //Message structure

{

    unsigned int id; //帧ID

    unsigned char RTR; // RTR: 1 for remote frame, 0 for data frame

    unsigned char data[8]; //frame data

    unsigned char len; //data length

    unsigned char prty; //priority

};

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

/* CAN0 receiving */

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

int MSCAN0_Receive(struct can_msg *msg)

{

  unsigned char sp2;


  // Check the reception flag

  if(!(CAN0RFLG_RXF))

    return(FALSE);

  

  // Detect CAN protocol message mode (general/extended) identifier

  if(CAN0RXIDR1_IDE) //0 is standard format, 1 is extended format

    // IDE = Recessive (Extended Mode)

    return(FALSE);


  // Read the identifier

  msg.id = (unsigned int)(CAN0RXIDR0<<3) | 

            (unsigned char)(CAN0RXIDR1>>5);

  

  if(CAN0RXIDR1&0x10)

    msg.RTR = TRUE;

  else

    msg.RTR = FALSE;

  

  // Read data length 

  msg.len = CAN0RXDLR;

  

  // Read data

  for(sp2 = 0; sp2 < msg.len; sp2++)

    msg.data[sp2] = *((&CAN0RXDSR0)+sp2);


  // Clear RXF flag (buffer is ready to receive)

  CAN0RFLG = 0x01;


  return(TRUE);

}


2. Extended frame program

The specific code is as follows:


struct can_msg //Message structure

{

    unsigned long ID; //帧ID

    unsigned char RTR; // RTR: 1 for remote frame, 0 for data frame

    unsigned char data[8]; //frame data

    unsigned char len; //data length

    unsigned char prty; //priority

};

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

/* CAN0 receiving */

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

int MSCAN0_Receive(struct can_msg *msg)

{

  unsigned char sp2;


  // Check the reception flag

  if(!(CAN0RFLG_RXF))

    return(FALSE);

  

  // Detect CAN protocol message mode (general/extended) identifier

  if(!CAN0RXIDR1_IDE) //0 is standard format, 1 is extended format

    // IDE = Recessive (Extended Mode)

    return(FALSE);


  // Read the identifier

  msg.ID = ((unsigned long)(CAN1RXIDR0&0xff))<<21;

  msg.ID = can1_msg_get.ID & ((unsigned long)0xff<<21);

  msg.ID = can1_msg_get.ID | (((unsigned long)(CAN1RXIDR1&0xe0))<<13);

  msg.ID = can1_msg_get.ID | (((unsigned long)(CAN1RXIDR1&0x07))<<15);

  msg.ID = can1_msg_get.ID | (((unsigned long)(CAN1RXIDR2&0xff))<<7);  

  msg.ID = can1_msg_get.ID | (((unsigned long)(CAN1RXIDR3&0xfe))>>1); 

  

  if(CAN0RXIDR3&0x01)

    msg.RTR = TRUE;

  else

    msg.RTR = FALSE;

  

  // Read data length 

  msg.len = CAN0RXDLR;

  

  // Read data

  for(sp2 = 0; sp2 < msg.len; sp2++)

    msg.data[sp2] = *((&CAN0RXDSR0)+sp2);


  // Clear RXF flag (buffer is ready to receive)

  CAN0RFLG = 0x01;


  return(TRUE);

}

Keywords:Freescale Reference address:Freescale MC9S12X: CAN Receive Configuration

Previous article:Freescale MC9S12X SCI driver
Next article:Freescale MC9S12X: CAN initialization configuration

Recommended ReadingLatest update time:2024-11-15 07:28

Decoding of protocols such as CAN, UART, IIC, USB, etc. that are familiar to analysis engineers
With the continuous update of hardware architecture, oscilloscopes are no longer just instruments for "oscilloscopes". Protocol decoding is a typical example! IIC, SPI, UART, CAN, LIN... We have equipped the ZDS series oscilloscopes with up to 37 protocol decoding and analysis plug-ins for free. Where are these many p
[Automotive Electronics]
Decoding of protocols such as CAN, UART, IIC, USB, etc. that are familiar to analysis engineers
Airbag solution based on Freescale MCU
Description of the program: The control unit is the core component of the airbag system and consists of a 16- or 32-bit MCU and a set of local acceleration sensors. Satellite sensors can be added according to the complexity of the system to provide auxiliary collision information through standard sensor buses s
[Embedded]
Airbag solution based on Freescale MCU
Learning experience of STM32 CAN filter
About STM32 CAN filter     The CAN of the STM32 ordinary chip has 14 filter groups (the interconnected type has 28 filter groups) to filter the received frames. Each filter group includes 2 configurable 32-bit registers: CAN_FxR0 and CAN_FxR1. For the filter group, it can be configured as a mask bit mode, so that the
[Microcontroller]
Freescale MCU KEA128 ADC Learning
The operation mode of this ADC module is actually quite simple. The first thing is configuration. Let’s list what to configure. ADICLK ADC module input clock selection. Bus clock, bus clock divided by 2 or external After ADIV divides the above clock again, it can be used by the ADC core module. MODE Select 8/1
[Microcontroller]
Silit releases CAN transceiver with ringing suppression function - SIT1463Q
CAN SIC technology adds specific functional modules to the CAN transceiver. When a transition from dominant level to recessive level occurs on the CAN bus, the CAN transceiver with SIC function activates the ringing suppression circuit, strongly drives the bus to the recessive level, and maintains a low output
[Embedded]
Silit releases CAN transceiver with ringing suppression function - SIT1463Q
Design of CAN bus interface circuit for automobile auxiliary system
  Overall design   The CAN bus interface circuit mainly includes: single chip microcomputer, controller interface, bus transceiver and watchdog circuit, etc. The SJA1000 controller produced by Philips and the matching 82C250CAN transceiver are used. According to the CAN bus physical layer protocol, the bus medium is
[Microcontroller]
Design of CAN bus interface circuit for automobile auxiliary system
Exclusive interview with Bosch chief technical expert Mutt Arthur: CAN XL will have great potential to help future automotive networks
"In the future, the two dominant forces in vehicle communication networks will be CAN and Ethernet ." Mutt Arthur, a senior expert on integrated circuits and IP at Bosch Semiconductor , said in an exclusive interview with Gasgoo. Indeed, in the debate over automotive network standards over the past few decades, th
[Automotive Electronics]
Exclusive interview with Bosch chief technical expert Mutt Arthur: CAN XL will have great potential to help future automotive networks
A brief discussion on SOA simulation test using CANoe
Preface This time we are going to talk about how to implement SOA related functions through the CANoe tool we are familiar with. What is SOA SOA stands for Service Oriented Architecture, which can distribute, combine and use loosely coupled coarse-grained application components through the
[Embedded]
A brief discussion on SOA simulation test using CANoe
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号