// Initialize CAN port void CAN0_Open(void){uint32_t volatile delay; CAN0_Fifo_Init(16); OS_InitSemaphore(&CAN0ReceiveFree, 1); PacketLost = 0; MailFlag = false; SYSCTL_RCGCCAN_R |= 0x00000001; // CAN0 enable bit 0 SYSCTL_RCGCGPIO_R |= 0x00000010; // RCGC2 portE bit 4 for(delay=0; delay<10; delay++){}; GPIO_PORTE_AFSEL_R |= 0x30; //PORTE AFSEL bits 5,4 // PORTE PCTL 88 into fields for pins 5,4 GPIO_PORTE_PCTL_R = (GPIO_PORTE_PCTL_R&0xFF00FFFF)|0x00880000; GPIO_PORTE_DEN_R |= 0x30; GPIO_PORTE_DIR_R |= 0x20; CANInit(CAN0_BASE); CANBitRateSet(CAN0_BASE, 80000000, CAN_BITRATE); CANEnable(CAN0_BASE); // make sure to enable STATUS interrupts CANIntEnable(CAN0_BASE, CAN_INT_MASTER | CAN_INT_ERROR | CAN_INT_STATUS); // Set up filter to receive these IDs // in this case there is just one type, but you could accept multiple ID types CAN0_Setup_Message_Object(RCV_ID, MSG_OBJ_RX_INT_ENABLE, 8, NULL, RCV_ID, MSG_OBJ_TYPE_RX); NVIC_EN1_R = (1 << (INT_CAN0 - 48)); //IntEnable(INT_CAN0); return; }
// Initialize CAN port void CAN0_Open(void){ uint32_t volatile delay; int32_t sr; sr = StartCritical(); MailFlag = false; SYSCTL_RCGCCAN_R |= 0x00000001; // CAN0 enable bit 0 SYSCTL_RCGCGPIO_R |= 0x00000010; // RCGC2 portE bit 4 for(delay=0; delay<10; delay++){}; GPIO_PORTE_AFSEL_R |= 0x30; //PORTE AFSEL bits 5,4 // PORTE PCTL 88 into fields for pins 5,4 GPIO_PORTE_PCTL_R = (GPIO_PORTE_PCTL_R&0xFF00FFFF)|0x00880000; GPIO_PORTE_DEN_R |= 0x30; GPIO_PORTE_DIR_R |= 0x20; CANInit(CAN0_BASE); CANBitRateSet(CAN0_BASE, 80000000, CAN_BITRATE); CANEnable(CAN0_BASE); // make sure to enable STATUS interrupts CANIntEnable(CAN0_BASE, CAN_INT_MASTER | CAN_INT_ERROR | CAN_INT_STATUS); // Set up filter to receive these IDs // in this case there is just one type, but you could accept multiple ID types CAN0_Setup_Message_Object(Ping1_ID, MSG_OBJ_RX_INT_ENABLE, 4, NULL, Ping1_ID, MSG_OBJ_TYPE_RX); CAN0_Setup_Message_Object(Ping2_ID, MSG_OBJ_RX_INT_ENABLE, 4, NULL, Ping2_ID, MSG_OBJ_TYPE_RX); CAN0_Setup_Message_Object(Ping3_ID, MSG_OBJ_RX_INT_ENABLE, 4, NULL, Ping3_ID, MSG_OBJ_TYPE_RX); CAN0_Setup_Message_Object(Ping4_ID, MSG_OBJ_RX_INT_ENABLE, 4, NULL, Ping4_ID, MSG_OBJ_TYPE_RX); CAN0_Setup_Message_Object(Button1_ID, MSG_OBJ_RX_INT_ENABLE, 4, NULL, Button1_ID, MSG_OBJ_TYPE_RX); CAN0_Setup_Message_Object(Button2_ID, MSG_OBJ_RX_INT_ENABLE, 4, NULL, Button2_ID, MSG_OBJ_TYPE_RX); CAN0_Setup_Message_Object(IR_ID, MSG_OBJ_RX_INT_ENABLE, 4, NULL, IR_ID, MSG_OBJ_TYPE_RX); NVIC_EN1_R = (1 << (INT_CAN0 - 48)); //IntEnable(INT_CAN0); EndCritical(sr); return; }
// send 4 bytes of data to other microcontroller void CAN0_SendData(unsigned char data[4]){ // in this case there is just one type, but you could accept multiple ID types CAN0_Setup_Message_Object(XMT_ID, NULL, 4, data, XMT_ID, MSG_OBJ_TYPE_TX); }