Hi Pete,
I am working on a new board with a LPC1517. I found this thread and your post where you say the project is attached but I don't see the file. Maybe because this was moved. Would it be possible to get your sample project.
Thanks,
Gary
.... void CAN_IRQHandler(void) .... |
//transmit message #1 [color=#f00] while(LPC_CAN->TXREQ1 & (1<<0)){}//read pending transmission request of object 0[/color] msg_obj.msgobj = 0; msg_obj.mode_id = 0x700+ NODE_ID; msg_obj.mask = 0x0; msg_obj.dlc = 0x4; msg_obj.data[0] = 0x11; msg_obj.data[1] = 0x11; msg_obj.data[2] = 0x11; msg_obj.data[3] = 0x11; LPC_CAND_API->hwCAN_MsgTransmit(pCanHandle, &msg_obj); //transmit message #2 [color=#f00] while(LPC_CAN->TXREQ1 & (1<<0)){}//read pending transmission request of object 0[/color] msg_obj.msgobj = 0; msg_obj.mode_id = 0x700 + NODE_ID+1; msg_obj.mask = 0x0; msg_obj.dlc = 3; msg_obj.data[0] = 0x22; msg_obj.data[1] = 0x22; msg_obj.data[2] = 0x22; LPC_CAND_API->hwCAN_MsgTransmit(pCanHandle, &msg_obj); |
#define NODE_ID 0x20//own node id //message #1 msg_obj.msgobj = 0; [color=#f00]msg_obj.mode_id = 0x700+ NODE_ID[/color]; msg_obj.mask = 0x0; [color=#f00]msg_obj.dlc = 0x4;[/color] msg_obj.data[0] = 0x11; msg_obj.data[1] = 0x11; msg_obj.data[2] = 0x11; [color=#f00]msg_obj.data[3] = 0x11;[/color] LPC_CAND_API->hwCAN_MsgTransmit(pCanHandle, &msg_obj); //message #2 msg_obj.msgobj = 0; msg_obj.mode_id = 0x700 + NODE_ID+1; msg_obj.mask = 0x0; msg_obj.dlc = 3; [color=#30f]msg_obj.data[0] = 0x22; msg_obj.data[1] = 0x22; msg_obj.data[2] = 0x22;[/color] LPC_CAND_API->hwCAN_MsgTransmit(pCanHandle, &msg_obj); |
//wait 5ms before CAN_Fail #define CAN_TX_TIME 5 //CAN State enum CAN_STATE { CAN_Success, CAN_TX, CAN_Fail }; //CAN typedef struct _CAN_STATE { volatile uint16_t timeout; //tx timeout volatile uint8_t state;//CAN state }CAN_STATE_t; CAN_STATE_t can_state; ... static void CAN_tx(uint8_t msg_obj) { Board_LED_Toggle(1);//show TX can_state.state = CAN_Success;//success, ready to transmit next message } ... //CAN timer, call every ms in SysTick... __attribute__((always_inline)) __INLINE void CAN_1ms_timer(void) { //timer to control tx if(can_state.state == CAN_TX) { //timeout to fail if(can_state.timeout) { can_state.timeout--; if(can_state.timeout==0) can_state.state = CAN_Fail; } } } //transmit message #1 while(!((can_state.state == CAN_Success) || (can_state.state == CAN_Fail))){}; //wait can_state.timeout = CAN_TX_TIME;//can timeout can_state.state = CAN_TX; //set tx busy flag msg_obj.msgobj = 0; msg_obj.mode_id = 0x700+ NODE_ID; msg_obj.mask = 0x0; msg_obj.dlc = 0x4; msg_obj.data[0] = 0x11; msg_obj.data[1] = 0x11; msg_obj.data[2] = 0x11; msg_obj.data[3] = 0x11; LPC_CAND_API->hwCAN_MsgTransmit(pCanHandle, &msg_obj); //transmit message #2 while(!((can_state.state == CAN_Success) || (can_state.state == CAN_Fail))){}; //wait can_state.timeout = CAN_TX_TIME; //can timeout can_state.state = CAN_TX; //set tx busy flag msg_obj.msgobj = 0; msg_obj.mode_id = 0x700 + NODE_ID+1; msg_obj.mask = 0x0; msg_obj.dlc = 3; msg_obj.data[0] = 0x22; msg_obj.data[1] = 0x22; msg_obj.data[2] = 0x22; LPC_CAND_API->hwCAN_MsgTransmit(pCanHandle, &msg_obj); |