void
CANIntHandler(void)
{
unsigned long ulStatus;
ulStatus = CANIntStatus(CAN0_BASE, CAN_INT_STS_CAUSE);
if(ulStatus == CAN_INT_INTID_STATUS)
{
ulStatus = CANStatusGet(CAN0_BASE, CAN_STS_CONTROL);
g_bErrFlag = 1;
}
else if(ulStatus == 1)
{
CANIntClear(CAN0_BASE, 1);
g_ulMsg1Count++;
g_bErrFlag = 0;
}
else
{
}
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
int
main(void)
{
tCANMsgObject sCANMessage;
unsigned char ucMsgData[4];
SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
SYSCTL_XTAL_16MHZ);
InitConsole();
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
GPIOPinConfigure(GPIO_PA6_CAN0RX);
GPIOPinConfigure(GPIO_PA7_CAN0TX);
GPIOPinTypeCAN(GPIO_PORTA_BASE, GPIO_PIN_6 | GPIO_PIN_7);
SysCtlPeripheralEnable(SYSCTL_PERIPH_CAN0);
CANInit(CAN0_BASE);
CANBitRateSet(CAN0_BASE, SysCtlClockGet(), 500000);
CANIntEnable(CAN0_BASE, CAN_INT_MASTER | CAN_INT_ERROR | CAN_INT_STATUS);
IntEnable(INT_CAN0);
CANEnable(CAN0_BASE);
*(unsigned long *)ucMsgData = 0;
sCANMessage.ulMsgID = 1; // CAN message ID - use 1
sCANMessage.ulMsgIDMask = 0; // no mask needed for TX
sCANMessage.ulFlags = MSG_OBJ_TX_INT_ENABLE; // enable interrupt on TX
sCANMessage.ulMsgLen = sizeof(ucMsgData); // size of message is 4
sCANMessage.pucMsgData = ucMsgData; // ptr to message content
for(;;)
{
UARTprintf("Sending msg: 0x%02X %02X %02X %02X",
ucMsgData[0], ucMsgData[1], ucMsgData[2], ucMsgData[3]);
CANMessageSet(CAN0_BASE, 1, &sCANMessage, MSG_OBJ_TYPE_TX);
SimpleDelay();
if(g_bErrFlag)
{
UARTprintf(" error - cable connected? ");
}
else
{
UARTprintf(" total count = %u ", g_ulMsgCount);
}
(*(unsigned long *)ucMsgData)++;
}
//
// Return no errors
//
return(0);
}
这个是主函数,只发,都是官方代码。
一周热门 更多>