基于STM32F107VC的CAN多帧中断发送函数,已通过调试
单片机源程序如下:
- /******************************************************************
- *STM32F107主控
- *ST3.5库函数
- *CAN1的多帧发送函数
- *CAN1的中断接收后、开发送中断将数据发送出去,验证成功
- ******************************************************************/
- #include "my.h"
- #include "led.h"
- #include "systick.h"
- #include "delay.h"
- #include "Can1.h"
- #include
- u8 RBuf[256];
- u16 tmplen=0;
- u8 hostid=0;
- extern u8 FLAG_Start;
- u8 canbuf1[8]={0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01};
- int main(void)
- {
- u8 t=0;
- u8 ii;
- SysTick_Init();
- LED_GPIO_Init();
- CAN_Config_Init();//500Kbit的波特率
- for(;;)
- {
- LED1=!LED1;
- LED2=!LED2;
- LED3=!LED3;
- LED4=!LED4;
- delay_ms(200);
- t++;
- if(t>=10)
- {t=0;
- LED1=1;
- LED2=1;
- LED3=1;
- LED4=1;
- break;
- }
- }
- for(ii=0;ii<64;ii++)RBuf[ii]=ii;
- while (1)
- {
- // tmplen=CAN1_Read(&hostid,RBuf);
- //
- // hostid = tmplen = 0;
- // memset(RBuf,0,sizeof(RBuf));//复位缓存
- // CAN1_Send_Multi_Messages(ID1,RBuf,64);
- if(FLAG_Start==0xBB)
- {
- FLAG_Start=0;
- CAN_ITConfig(CAN1, CAN_IT_FMP0, DISABLE); //关闭接受中断
- // CAN_ITConfig(CAN1, CAN_IT_TME, ENABLE);
- CAN1_Send_Multi_Messages(ID1,RBuf,64);
- // CAN_ITConfig(CAN1, CAN_IT_TME, DISABLE);//关闭发送邮箱空中断
- CAN_ITConfig(CAN1, CAN_IT_FMP0, ENABLE); //开始接受中断
- //CAN_Send_Msg(ID1,CAN_ID_EXT,CAN_RTR_DATA,8,canbuf1);
- }
- if(FLAG_Start==0xaa)
- {
- FLAG_Start=0;
- CAN_ITConfig(CAN1, CAN_IT_FMP0, DISABLE); //关闭接受中断
- CAN_Send_Msg(ID1,CAN_ID_EXT,CAN_RTR_DATA,8,canbuf1);
- CAN_ITConfig(CAN1, CAN_IT_FMP0, ENABLE); //开始接受中断
- }
- /************************System Operation **********************************/
- t++;
- ……………………
- …………限于本文篇幅 余下代码请从电子发烧友下载附件…………
所有资料51hei提供下载:
STM32F107的CAN接收发送中断函数.rar
|