求各位指教,我快要崩溃了,简单的发送都没法实现。每次都进入状态中断
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/hw_can.h"
#include "inc/hw_ints.h"
#include "driverlib/can.h"
#include "driverlib/interrupt.h"
#include "driverlib/sysctl.h"
#include "driverlib/gpio.h"
#define GPIO_LED_SYSCTL_PERIPH SYSCTL_PERIPH_GPIOB
#define GPIO_LED_PORT_BASE GPIO_PORTB_BASE
#define GPIO_LED_PIN (GPIO_PIN_4)
#define CANBAUD_125K 0
#define CANBAUD_250K 1
#define CANBAUD_500K 2
#define CANBAUD_1M 3
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
};
tCANMsgObject g_sCANMsgObject;
unsigned char g_ucMsg[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
void CANIntHandler(void)
{
unsigned long ulStatus;
ulStatus = CANIntStatus(CAN0_BASE, CAN_INT_STS_CAUSE);
if(ulStatus == CAN_INT_INTID_STATUS) //0x00008000 就是这个破状态中断,每次循环发送都进入
{
ulStatus = CANStatusGet(CAN0_BASE, CAN_STS_CONTROL);
}
else if(ulStatus == 1)
{
CANIntClear(CAN0_BASE, 1);
}
else
{
}
}
//*****************************************************************************
//
// Configure the CAN and enter a loop to transmit periodic CAN messages.
//
//*****************************************************************************
int main(void)
{
SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |SYSCTL_XTAL_16MHZ);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
// 使能端口PB,然后配置PB.4为输出
SysCtlPeripheralEnable(GPIO_LED_SYSCTL_PERIPH);
GPIOPinTypeGPIOOutput(GPIO_LED_PORT_BASE, GPIO_LED_PIN);
GPIOPinConfigure(GPIO_PD0_CAN0RX);//设置引脚功能
GPIOPinConfigure(GPIO_PD1_CAN0TX);
GPIOPinTypeCAN(GPIO_PORTD_BASE, GPIO_PIN_0 | GPIO_PIN_1);
SysCtlPeripheralEnable(SYSCTL_PERIPH_CAN0);
CANInit(CAN0_BASE);
CANBitTimingSet(CAN0_BASE,(tCANBitClkParms *)&CANBitClkSettings[CANBAUD_500K]);
//CANBitRateSet(CAN0_BASE, SysCtlClockGet(), 500000);
//CANIntRegister(CAN0_BASE, CANIntHandler); // if using dynamic vectors
CANIntEnable(CAN0_BASE, CAN_INT_MASTER | CAN_INT_ERROR | CAN_INT_STATUS);
IntEnable(INT_CAN0);
CANEnable(CAN0_BASE);
g_sCANMsgObject.ulMsgID = 0x1001;
g_sCANMsgObject.ulMsgIDMask = 0;
g_sCANMsgObject.ulFlags = MSG_OBJ_TX_INT_ENABLE;
g_sCANMsgObject.ulMsgLen = sizeof(g_ucMsg);
g_sCANMsgObject.pucMsgData = g_ucMsg;
SysCtlPeripheralEnable(GPIO_LED_SYSCTL_PERIPH);
GPIOPinTypeGPIOOutput(GPIO_LED_PORT_BASE, GPIO_LED_PIN);
for(;;)
{
CANMessageSet(CAN0_BASE, 1, &g_sCANMsgObject, MSG_OBJ_TYPE_TX);
// 置PB.4为高电平
GPIOPinWrite(GPIO_LED_PORT_BASE, GPIO_LED_PIN, GPIO_LED_PIN);
// 延时500ms
SysCtlDelay(500 * SysCtlClockGet()/300);
// 置PB.4为低电平
GPIOPinWrite(GPIO_LED_PORT_BASE, GPIO_LED_PIN, 0);
// 延时500ms
SysCtlDelay(500 * SysCtlClockGet()/300);
}
return(0); //若删去它则程序不能正常运行
} |