在F407的库函数版本综合试验中CAN的怎么使用?

2019-07-21 02:54发布

库函数版本中的综合实验里的CAN文件夹里的can.c和can.h文件是寄存器版本的代码,然后我将库函数版本的can.c和can.h将其代替,将库函数的CAN通信实验的主程序代码移植在了综合实验电子书中即ebook.c的u8 ebook_play(void)函数中,可是触屏双击电子书图标后显示发送成功但是接受不成功然后另个板子也没有接受到,请问问题出在哪里?另一个板子用的是F103这两个板子的CAN例程的通信已经调通,F103中加载的还是给的CAN例程没有变。
u8 ebook_play(void)
{
u8 key;
u8 i=0,t=0;
u8 cnt=0;
u8 canbuf[8];
u8 res;
u8 mode=1;//CAN?¤×÷????;0,???¨????;1,?·??????
// NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//?è????????????????·?×é2
// delay_init(168);    //?????????±????
// uart_init(115200); //???????®???¨??????115200
// LED_Init(); //??????LED 
 // LCD_Init(); //LCD?????? 
// KEY_Init(); //°??ü??????  
 CAN1_Mode_Init(CAN_SJW_1tq,CAN_BS2_6tq,CAN_BS1_7tq,6,CAN_Mode_LoopBack);//CAN???????·??????,?¨????500Kbps    
// CAN1_Mode_Init(CAN_SJW_1tq,CAN_BS2_8tq,CAN_BS1_7tq,5,CAN_Mode_Normal);//CAN???????·??????,?¨????500Kbps   
BACK_COLOR=WHITE;
LCD_Clear(WHITE);//??????   
  POINT_COLOR=RED;//?è??×??????ì?? 
LCD_ShowString(30,50,200,16,16,"Explorer STM32F4");
LCD_ShowString(30,70,200,16,16,"CAN TEST");
LCD_ShowString(30,90,200,16,16,"ATOM@ALIENTEK");
LCD_ShowString(30,110,200,16,16,"2014/5/7");
LCD_ShowString(30,130,200,16,16,"LoopBack Mode");  
LCD_ShowString(30,150,200,16,16,"KEY0:Send WK_UP:Mode");//?????á??????
  POINT_COLOR=BLUE;//?è??×?????????   
LCD_ShowString(30,170,200,16,16,"Count:");   //?????±?°??????
LCD_ShowString(30,190,200,16,16,"Send Data:"); //?á??·?????????
LCD_ShowString(30,250,200,16,16,"Receive Data:"); //?á??????????????
   
while(1)
{
key=KEY_Scan(0);
if(key==KEY0_PRES)//KEY0°???,·???????????
{
for(i=0;i<8;i++)
{
canbuf=cnt+i;//????·?????????
if(i<4)LCD_ShowxNum(30+i*32,210,canbuf,3,16,0X80);  //????????
else LCD_ShowxNum(30+(i-4)*32,230,canbuf,3,16,0X80); //????????
  }
res=CAN1_Send_Msg(canbuf,8);//·???8??×??? 
if(res)LCD_ShowString(30+80,190,200,16,16,"Failed"); //?á??·????§°?
else LCD_ShowString(30+80,190,200,16,16,"OK    "); //?á??·???????   
}else if(key==WKUP_PRES)//WK_UP°???????±?CAN???¤×÷????
{   
mode=!mode;
CAN1_Mode_Init(CAN_SJW_1tq,CAN_BS2_6tq,CAN_BS1_7tq,6,mode); //CAN???¨??????????,???¨????,?¨????500Kbps
  POINT_COLOR=RED;//?è??×??????ì?? 
if(mode==0)//???¨???????è??2????·?°?
{
LCD_ShowString(30,130,200,16,16,"Nnormal Mode ");    
}else //???·????,??????·?°?????????????.
{
  LCD_ShowString(30,130,200,16,16,"LoopBack Mode");
}
  POINT_COLOR=BLUE;//?è??×????????? 
}  
key=CAN1_Receive_Msg(canbuf);
if(key)//????????????
{
LCD_Fill(30,270,160,310,WHITE);//?????®?°??????
  for(i=0;i<key;i++)
{    
if(i<4)LCD_ShowxNum(30+i*32,270,canbuf,3,16,0X80); //????????
else LCD_ShowxNum(30+(i-4)*32,290,canbuf,3,16,0X80); //????????
  }
}
t++; 
delay_ms(10);
if(t==20)
{
LED0=!LED0;//?á??????????????
t=0;
cnt++;
LCD_ShowxNum(30+48,170,cnt,3,16,0X80); //????????
}   


}

友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。