本程序基于LM3S5K31
#include "config.h"#include "can_deal.h"#include "serial_com.h"/**/tCANMsgObject g_MsgObjectRx; // CAN接收报文对象设置tCANMsgObject g_MsgObjectTx; // CAN发送报文对象设置tCANBitClkParms CANBitClkSettings[] ={ {9,6,4,4}, // CANBAUD_125K {5,2,2,4}, // CANBAUD_250K {5,2,2,2}, // CANBAUD_500K {5,2,2,1} // CANBAUD_1M};
uint8 can_sendbuf[8] = {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07}; void CANSendInit() // transmit{ g_MsgObjectTx.ulFlags = MSG_OBJ_EXTENDED_ID; /* 扩展帧*/ g_MsgObjectTx.ulMsgID = 0x123; /* 取得报文标识符*/ g_MsgObjectTx.ulMsgLen = 8; /* 标记数据域长度 */ g_MsgObjectTx.pucMsgData = can_sendbuf; /* 传递数据存放指针 */ g_MsgObjectTx.ulFlags |= MSG_OBJ_TX_INT_ENABLE; /* 标记发送中断使能*/ CANRetrySet(CAN0_BASE, 31); /* 启动发送失败重发 */ CANMessageSet(CAN0_BASE, 31, &g_MsgObjectTx, MSG_OBJ_TYPE_TX); /* 配置31号报文对象为发送对象 */ // com_flag = 0;}void InitConsole(void) //需要注意 ARM_RXD0 ARM_TXD0{ SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); GPIOPinConfigure(GPIO_PA0_U0RX); GPIOPinConfigure(GPIO_PA1_U0TX); GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); UARTConfigSet(UART0_BASE,9600,UART_CONFIG_WLEN_8|UART_CONFIG_PAR_NONE|UART_CONFIG_STOP_ONE); UARTEnable(UART0_BASE);}void CANConfigure(){ InitConsole(); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); // 使能GPIOD系统外设 SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); SysCtlPeripheralEnable(SYSCTL_PERIPH_CAN0); // 使能CAN控制器系统外设 GPIOPinConfigure(GPIO_PA6_CAN0RX); GPIOPinConfigure(GPIO_PB5_CAN0TX); GPIOPinTypeCAN(GPIO_PORTA_BASE, GPIO_PIN_6 ); GPIOPinTypeCAN(GPIO_PORTB_BASE, GPIO_PIN_5 ); CANInit(CAN0_BASE); // 初始化CAN节点 CANBitTimingSet(CAN0_BASE, (tCANBitClkParms *)&CANBitClkSettings[CANBAUD_250K]); // 对 CAN控制器位时序进行配置 CANEnable(CAN0_BASE); // 使能CAN控制器 CANIntEnable(CAN0_BASE, CAN_INT_MASTER | CAN_INT_STATUS | CAN_INT_ERROR ); // 使能CAN控制器中断源 IntEnable(INT_CAN0); // 使能CAN控制器中断(to CPU) IntMasterEnable(); // 使能中断总开关} void CANIntHandler(void){ unsigned long ulStatus,UlStatus; unsigned long ulMsgObjID; unsigned long ulNewData; ulStatus = CANIntStatus(CAN0_BASE, CAN_INT_STS_CAUSE); ulMsgObjID = CANIntStatus(CAN0_BASE,CAN_INT_STS_OBJECT); ulNewData = CANStatusGet(CAN0_BASE ,CAN_STS_NEWDAT); if(ulStatus == CAN_INT_INTID_NONE) // No interrupt pending 无挂起中断 { CANRetrySet(CAN0_BASE, true); } else if(ulStatus == CAN_INT_INTID_STATUS) // Status Interrupt 状态中断 { UlStatus = CANStatusGet(CAN0_BASE, CAN_STS_CONTROL); CANMessageGet(CAN0_BASE, MSGOBJ_NUM_DATA_RX, &g_MsgObjectRx, true); CANIntClear(CAN0_BASE, ulStatus); }// 中断状态分析 if(UlStatus == CAN_STATUS_TXOK) //成功发送一帧报文 { CANIntClear(CAN0_BASE, UlStatus); } else if(UlStatus == CAN_STATUS_RXOK) { CANIntClear(CAN0_BASE, UlStatus); } else { CANIntClear(CAN0_BASE, UlStatus); }}
UlStatus的值为0x000000E2, 求解,是不是发送数据配置有问题?希望有个调试完整的例程参考,谢谢。
此帖出自
小平头技术问答
一周热门 更多>