我用的是LPC2131+SJA1000+TJA1050,ARM c语言与C语言有所不同,我本以为是寄存器设置的问题,所以只发了初始化,我发送接收数据用的查询. void init_can() { uint8 dat; IO0CLR = CS; // 0x40800000;INT|CS; write_can(0,0x01);//控制寄存器,进入复位模式,并且禁能所有中断源 write_can(31,0x48); //时钟分频器 write_can(4,0xaa); //验收代码ID 550 write_can(5,0x00); //验收屏蔽寄存器 write_can(6,0x01); //btr0 write_can(7,0x1c); //btr1 write_can(8,0xaa); //输出控制寄存器 delay(2); write_can(0,0x06); //退出复位模式,并且使能发送中断和接收中断 dat= read_can(0); while((dat&0x01)==1) //判断是否复位 { write_can(0,0x06); } } void Tx1(void) //发送子程序 { uint8 i; uint8 addr=10; uint8 snd1[10]={0xaa,0x28,0x19,0x83,0x02,0x12,0x44,0x53,0x48,0x12}; write_can(0,0x06); //使能发送中断和接收中断,控制寄存器 for(i=0;i<10;i++) { write_can(addr,snd1); addr++; delay(100); } write_can(1,0x05);// 启动发送,置位发送请求位 delay(100); }
uint8 receive() //接收数据,并发到串口上 { uint8 i; receive_data[0]=read_can(0x14); receive_data[1]=read_can(0x15); receive_data[2]=read_can(0x16);//data1 receive_data[3]=read_can(0x17);//data2 receive_data[4]=read_can(0x18);//data3 receive_data[5]=read_can(0x19);//data4 receive_data[6]=read_can(0x1a);//data5 receive_data[7]=read_can(0x1b);//data6 receive_data[8]=read_can(0x1c);//data7 receive_data[9]=read_can(0x1d);//data8 for(i=0;i<10;i++) { UART0_SendByte(receive_data); // 向串口发送字符串 delay(10); } write_can(1,0x04);//释放,接收缓冲器中载有信息内容被释放 return 1; }
int main (void) { init_can(); delay(10); while(1) { Tx1(); delay(1000000); receive(); } return 0; }
|