📄 remote_send.c
字号:
/*""FILE COMMENT""***************************************************** * M32R C Programming Rev. 1.00 * < Sample Program for CAN remote_send > * * 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 remote_send(void); void remote_send_read_data(void);extern void can_init(void);/************************************************************************//* Externally referenced variable *//************************************************************************/ char CAN_DATA[8]; /* Used to store received data *//*""FUNC COMMENT""******************************************************* * Function name: void main(void) *----------------------------------------------------------------------- * Description : Remote frame transmission sample program *----------------------------------------------------------------------- * Argument : - *----------------------------------------------------------------------- * Returns : - *----------------------------------------------------------------------- * Notes : *""FUNC COMMENT END""***************************************************/void main(void){ /* Initialize CAN module */ can_init(); /* CAN module operation */ remote_send(); /* Wait until remote frame is sent */ while( ( CAN0SLIST & SSB0) == 0) ; CAN0SLIST = 0x0000; /* Wait until data frame is received */ while( ( CAN0SLIST & SSB0) == 0) ; /* Read out received data frame */ remote_send_read_data(); while( 1 ) ;}/*""FUNC COMMENT""******************************************************* * Function name: void remote_send(void) *----------------------------------------------------------------------- * Description : Sends remote frame from slot 0 *----------------------------------------------------------------------- * Argument : - *----------------------------------------------------------------------- * Returns : - *----------------------------------------------------------------------- * Notes : *""FUNC COMMENT END""***************************************************/void remote_send(void){ C0MSL0CNT = 0x00; /* Initialize CAN message slot control register */ while ( ( C0MSL0CNT & TRSTAT) != 0) /* Verify that transmit operation is idle */ ; /* Set ID and DLC in message slot 0 */ C0MSL0SID0 = 0x00; /* ID : 0 */ C0MSL0SID1 = 0x00; C0MSL0DLC = 0x01; /* DLC : 1 */ /* Set extended ID register */ CAN0EXTID = 0x0000; /* Select standard format */ /* Set CAN message slot control register */ C0MSL0CNT = 0xA0; /* Request transmission of remote frame */}/*""FUNC COMMENT""******************************************************* * Function name: void remote_send_read_data(void) *----------------------------------------------------------------------- * Description : Reads out received data frame when CAN module has been set for remote frame transmission *----------------------------------------------------------------------- * Argument : - *----------------------------------------------------------------------- * Returns : - *----------------------------------------------------------------------- * Notes : *""FUNC COMMENT END""***************************************************/void remote_send_read_data(void){ do { C0MSL0CNT = 0xAE; /* 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 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 + -