初始化函数:
void can1_init(void)
{
PCONP |= ((uint32)0x01 << 13); // enable CAN controller 1
PINSEL1 &= ~((uint32)0x03 << 18);
PINSEL1 |= ((uint32)0x01 << 18); // set P0.25 to be RD1
CAN1MOD = (uint32)0x01; // into reset mode;
CAN1MOD &= ~((uint32)0x01<<1); // LOM = 0
CAN1MOD &= ~((uint32)0x01<<2); // STM = 0
CAN1MOD &= ~((uint32)0x01<<3); // TPM = 0
CAN1BTR = BPS_20K; // 设置波特率为20K
CANAFMR = (uint32)0x02; // config AF
CANSFF_sa = (uint32)0x00;
CANSFF_GRP_sa = (uint32)0x04;
CANEFF_sa = (uint32)0x04;
CANEFF_GRP_sa = (uint32)0x04;
CANENDofTable = (uint32)0x04;
CANAFRAM = (0x01<<29)|(probe_num<<16)|(0x01<<13)|(255); // 只接收ID为probe_num(一个固定的unsigned char型值)
和255的CAN报文
CANAFMR = (uint32)0x00; // Acceptance filter operates
CAN1MOD &= ~(uint32)0x01; // into operate mode
/* 初始化中断 */
VICIntSelect = 0x00000000;
VICVectAddr2 = (uint32)can1_isr;
VICVectCntl2 = 0x3A;
//VICVectAddr3 = (uint32)can1_error_isr;
//VICVectCntl3 = 0x51;
CAN1IER = (uint32)0x01; // enable receiver interrupt
//CAN1IER |= ((uint32)0x01<<7); // enable bus error interrupt
}
-------------
总中断开启,timer可以正常进中断,工控机能收到LPC2119的can发送来的数据,但是LPC2119的can不能收到工控机发送的任
何帧ID的数据,(工控机的CAN收发都正常),是不是 CANAFRAM = (0x01<<29)|(probe_num<<16)|(0x01<<13)|(255); // 只
接收ID为probe_num(一个固定的unsigned char型值)和255的CAN报文
,寄存器赋值不对,请问要怎么初始化才能收到制定帧ID的报文?谢谢
------解决方案--------------------
友情帮顶下;
楼主自己去NXP官网下载KEIL C的代码吧。
------解决方案--------------------
你接收是扫描还中断,
你接收的通道是命令还是数据的
------解决方案--------------------
(unsiged long)(0x01 < <29)|(probe_num < <16)|(0x01 < <13)|(255);