|
查询方式正常工作,可以正常接收发送。
void CAN_setup (uint32_t ctrl,uint32_t baudrate) {
LPC_CAN_TypeDef *pCAN = (ctrl == 1) ? LPC_CAN1 : LPC_CAN2;
if (ctrl == 1) {
LPC_SC->PCONP |= (1 << 13); /* Enable power to CAN1 block */
LPC_PINCON->PINSEL0 |= (1 << 0); /* Pin P0.0 used as RD1 (CAN1) */
LPC_PINCON->PINSEL0 |= (1 << 2); /* Pin P0.1 used as TD1 (CAN1) */
NVIC_EnableIRQ(CAN_IRQn); /* Enable CAN interrupt */
} else {
LPC_SC->PCONP |= (1 << 14); /* Enable power to CAN2 block */
LPC_PINCON->PINSEL4 |= (1 << 14); /* Pin P2.7 used as RD2 (CAN2) */
LPC_PINCON->PINSEL4 |= (1 << 16); /* Pin P2.8 used as TD2 (CAN2) */
NVIC_EnableIRQ(CAN_IRQn); /* Enable CAN interrupt */
}
LPC_CANAF->AFMR = 2; /* By default filter is not used */
pCAN->MOD = 1; /* Enter reset mode */
pCAN->IER = 0; /* Disable all interrupts */
pCAN->GSR = 0; /* Clear status register */
CAN_cfgBaudrate(ctrl, getBaudrate(baudrate)*1000); /* Set bit timing */
pCAN->IER = 0x0000;
// CAN_waitReady(1);
}
uint32_t test[5];
if(LPC_CAN1->GSR & 1)
{
CAN_rdMsg(1,test);
test[2]+=1;
while ( !(LPC_CAN1->GSR & (1 << 3)) );
CAN_wrMsg(1,test);
}
中断方式
初始化时 pCAN->IER = 0x0003; 允许发送和接收中断后,第一次进入中断就错误了,只能接收一次,循环中的led就不闪烁了。
void CAN_IRQHandler (void)
{
volatile uint32_t icr;
/* check CAN controller 1 */
icr = LPC_CAN1->ICR; // clear interrupts
if (icr & (1 << 0)) { // CAN Controller #1 meassage is received
CAN_rdMsg(1,test);//此函数会释放接收缓存的。
test[2]+=1;
while ( !(LPC_CAN1->GSR & (1 << 3)) );
CAN_wrMsg(1,test);
}
if (icr & (1 << 1)) { /* CAN Controller #1 meassage is transmitted */
}
}
不知道如何调试了,各位看看有什么好的解决思路?
|
阿莫论坛20周年了!感谢大家的支持与爱护!!
一只鸟敢站在脆弱的枝条上歇脚,它依仗的不是枝条不会断,而是自己有翅膀,会飞。
|