#include "LPC17xx.h¨ unsigned int rxBuffer[2]; void canTx(unsigned int id, unsigned int datalen, unsigned int a[]) { unsigned int len; while(!(LPC_CAN1->SR & 0b0100)); LPC_CAN1->TFI1= (datalen<<16); //to set the DLC LPC_CAN1->TID1= id; //to set the message id LPC_CAN1->TDA1 = a[0]; //data LPC_CAN1->TDB1 = a[1]; LPC_CAN1->CMR |= 0b1; } void CAN_IRQHandler(void) { unsigned int status; status=LPC_CAN1->ICR; switch(status) { case 1: rxBuffer[0]=LPC_CAN1->RDA; rxBuffer[1]=LPC_CAN1->RDB; LPC_CAN1->CMR |= (1<<2); break; case 0b10: break; } } int main(void) { unsigned int data[]={0xaa, 0xbb}, test; LPC_SC->PCONP |= (1<<13); LPC_PINCON->PINSEL0 |=(0b0101); LPC_CAN1->MOD=0b01; //to set in reset mode LPC_CAN1->MOD |= 0b000100; //to set the self test bit test = LPC_CAN1->MOD; LPC_CAN1->CMR=0b00110000; //stb1 selected and self reception enabled LPC_CAN1->IER = 0b001; //ri enabled LPC_CAN1->MOD &= ~(0b1); //setting the can in operating mode LPC_CANAF->AFMR = 0b10; //AF in bypass mode NVIC_EnableIRQ(CAN_IRQn); while ( !(LPC_CAN1->GSR & (1 << 3)) ); canTx(0x00, 8, data); while(1); } |
LPC_CAN1->CMR |= 0b1; |
LPC_CAN1->CMR = (1<<4); //send with self reception |
LPC_CAN1->CMR = (1<<4); //send with self reception |