请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
器件型号:TMS320F280049 Thread 中讨论的其他器件:LAUNCHXL-F280049C
工具与软件:
这是我的代码、当我发送 CAN 消息时、我无法从 pcanview 看到该消息。 PCanview 给我一个错误 BUSHEAVY。
如果我在示波器中分析 TX 引脚、我将得到0x1556AAAB...
当我从 pCAN 向 MCU 发送消息时、程序没有 RX 中断。 如果我分析 Rx 引脚、我会得到正确的消息、但 MCU 未获得该消息。
CCS 12.7.1、sysconf 1.20、 empty_driverlib_project、F28004x_64PM
我查看了 DCAN 模块的文档编程示例和调试策略。
代码在评估板 launchxl-f280049c 上正确运行。 我所做的唯一区别是更改引脚配置。
#include "driverlib.h" #include "device.h" #include "board.h" #include "c2000ware_libraries.h" #define KL_CAN_TX_OBJ_ID 1 #define KL_CAN_RX_OBJ_ID 2 #define KL_CAN_TX_MSG_ID 0x15555556 #define KL_CAN_RX_MSG_ID 0x15555555 uint16_t txMsgData[8] = {0x12, 0x34, 0x56, 0x78, 0x22, 0x74, 0x56, 0x98}; uint16_t rxMsgData[8]; __interrupt void canaISR(void); void kl_CANInit(void); void main(void) { Device_init(); Device_initGPIO(); Interrupt_initModule(); Interrupt_initVectorTable(); Board_init(); C2000Ware_libraries_init(); EALLOW; kl_CANInit(); CAN_disableRetry(CANA_BASE); EDIS; EINT; ERTM; while(1) { DEVICE_DELAY_US(1000000); CAN_sendMessage(CANA_BASE, KL_CAN_TX_OBJ_ID, 8, txMsgData); } } __interrupt void canaISR(void) { uint32_t status; status = CAN_getInterruptCause(CANA_BASE); if(status == CAN_INT_INT0ID_STATUS) { status = CAN_getStatus(CANA_BASE); } else if(status == KL_CAN_TX_OBJ_ID) { CAN_clearInterruptStatus(CANA_BASE, KL_CAN_TX_OBJ_ID); } else if(status == KL_CAN_RX_OBJ_ID) { CAN_readMessage(CANA_BASE, KL_CAN_RX_OBJ_ID, rxMsgData); CAN_clearInterruptStatus(CANA_BASE, KL_CAN_RX_OBJ_ID); } else { } CAN_clearGlobalInterruptStatus(CANA_BASE, CAN_GLOBAL_INT_CANINT0); Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP9); } void kl_CANInit(void) { GPIO_setPinConfig(GPIO_5_CANA_RX); GPIO_setPinConfig(GPIO_4_CANA_TX); CAN_initModule(CANA_BASE); // 100MHz Clock, Can Speed 250Kb/s, T1:10, T2:5, SJW:3 CAN_setBitTiming(CANA_BASE, 24, 0, 9, 4, 3); CAN_enableInterrupt(CANA_BASE, CAN_INT_IE0 | CAN_INT_ERROR | CAN_INT_STATUS); Interrupt_register(INT_CANA0, &canaISR); Interrupt_enable(INT_CANA0); CAN_enableGlobalInterrupt(CANA_BASE, CAN_GLOBAL_INT_CANINT0); CAN_setupMessageObject(CANA_BASE, KL_CAN_TX_OBJ_ID, KL_CAN_TX_MSG_ID, CAN_MSG_FRAME_EXT, CAN_MSG_OBJ_TYPE_TX, 0, CAN_MSG_OBJ_TX_INT_ENABLE, 8); CAN_setupMessageObject(CANA_BASE, KL_CAN_RX_OBJ_ID, KL_CAN_RX_MSG_ID, CAN_MSG_FRAME_EXT, CAN_MSG_OBJ_TYPE_RX, 0, CAN_MSG_OBJ_RX_INT_ENABLE, 8); CAN_startModule(CANA_BASE); }