📄 data_receive.c
字号:
/*""FILE COMMENT""***************************************************** * M32R C Programming Rev. 1.00 * < Sample Program for CAN data_receive > * * Copyright (c) 2003 Renesas Technology Corporation * And Renesas Solutions Corporation * All Rights Reserved *********************************************************************//************************************************************************//* Include file *//************************************************************************/#include "..\inc\sfr32170_pragma.h"/************************************************************************//* Function prototype declaration *//************************************************************************/ void main(void); void data_receive(void); void read_data(void);extern void can_init(void);/************************************************************************//* Externally referenced variable *//************************************************************************/ char CAN_DATA[8];/*""FUNC COMMENT""******************************************************* * Function name: void main(void) *----------------------------------------------------------------------- * Description : Data frame transmission sample program *----------------------------------------------------------------------- * Argument : - *----------------------------------------------------------------------- * Returns : - *----------------------------------------------------------------------- * Notes : - *""FUNC COMMENT END""***************************************************/void main(void){ /* Initializing CAN module */ can_init(); /* CAN module operation */ data_receive(); /* Wait until data is received in slot 0 */ while( ( CAN0SLIST & SSB0) == 0x0000 ) ; /* Read out received data */ read_data(); /* End of program */ while( 1 ) ;}/*""FUNC COMMENT""******************************************************* * Function name: void data_receive(void) *----------------------------------------------------------------------- * Description : Receives data frame in slot 0 *----------------------------------------------------------------------- * Argument : - *----------------------------------------------------------------------- * Returns : - *----------------------------------------------------------------------- * Notes : - *""FUNC COMMENT END""***************************************************/void data_receive(void){ C0MSL0CNT = 0x00; /* Initialize CAN message slot control register */ while ( ( C0MSL0CNT & TRSTAT) != 0) /* Verify that transmit operation is idle */ ; /* Set ID in message slot 0 */ C0MSL0SID0 = 0x00; /* ID : 0 */ C0MSL0SID1 = 0x00; /* Set extended ID register */ CAN0EXTID = 0x0000; /* Select standard format */ /* Set CAN message slot control register */ C0MSL0CNT = 0x40; /* Request reception of data frame */ /* * Because ID mask register is set within can_init() for "all bits to be checked," * slot 0 receives only data frames in standard format with ID:0. */}/*""FUNC COMMENT""******************************************************* * Function name: void data_send(void) *----------------------------------------------------------------------- * Description : Transmits data frame from slot 0 *----------------------------------------------------------------------- * Argument : - *----------------------------------------------------------------------- * Returns : - *----------------------------------------------------------------------- * Notes : - *""FUNC COMMENT END""***************************************************/void read_data(void){ do { C0MSL0CNT = 0x4E; /* Clear TRFIN bit */ /* Read out message slot 0 */ CAN_DATA[0] = C0MSL0DT0; CAN_DATA[1] = C0MSL0DT1; CAN_DATA[2] = C0MSL0DT2; CAN_DATA[3] = C0MSL0DT3; CAN_DATA[4] = C0MSL0DT4; CAN_DATA[5] = C0MSL0DT5; CAN_DATA[6] = C0MSL0DT6; CAN_DATA[7] = C0MSL0DT7; } while( ( C0MSL0CNT & TRFIN) != 0 ); /* Redo if TRFIN bit is set */ /* If necessary, check ML bit to see if message is lost * * if( (*C0MSL0CNT & ML) != 0) * (Processing for messages lost); */}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -