本帖最后由 小老千 于 2017-3-20 19:16 编辑
我CANH, CANL出来接的是USB-CAN的模块
void CAN_Interrupt_Config(void)
{
CAN_InitTypeDef CAN_InitStructure;// CAN ÅäÖýṹÌå
CAN_DeInit(CAN1);//½«ÍâÉèCANµÄÈ«²¿¼Ä´æÆ÷ÖØÉèΪȱʡֵ
CAN_StructInit(&CAN_InitStructure);//ÿ¸ö²ÎÊý°´È±Ê¡ÖµÐ´Èë
CAN_InitStructure.CAN_TTCM=DISABLE;// ʱ¼ä´¥·¢Í¨Ñ¶Ê§ÄÜ
CAN_InitStructure.CAN_ABOM=DISABLE;// ×Ô¶¯ÀëÏß¹ÜÀíʧÄÜ
CAN_InitStructure.CAN_AWUM=DISABLE;// ×Ô¶¯»½ÐÑģʽʧÄÜ
CAN_InitStructure.CAN_NART=DISABLE;// ·Ç×Ô¶¯ÖØ´«Ä£Ê½Ê§ÄÜ
CAN_InitStructure.CAN_RFLM=DISABLE;// ½ÓÊÕFIFOËø¶¨Ê§ÄÜ
CAN_InitStructure.CAN_TXFP=DISABLE;// ·¢ËÍFIFOÓÅÏȼ¶Ê§ÄÜ
CAN_InitStructure.CAN_Mode=CAN_Mode_Normal; //Õý³£´«Êäģʽ
CAN_InitStructure.CAN_SJW=CAN_SJW_2tq; //ÖØÐÂͬ²½ÌøÔ¾¿í¶È2¸öʱ¼äµ¥Î»£¨1-4£©
CAN_InitStructure.CAN_BS1=CAN_BS1_4tq; //ʱ¼ä¶Î1Ϊ4¸öʱ¼äµ¥Î»£¨1-16£©
CAN_InitStructure.CAN_BS2=CAN_BS2_6tq; //ʱ¼ä¶Î2Ϊ6¸öʱ¼äµ¥Î»£¨1-8£©
CAN_InitStructure.CAN_Prescaler=6; //·ÖƵϵÊýΪ5£¨1-1024£©
CAN_Init(CAN1,&CAN_InitStructure); //³õʼ»¯CAN1£¬²¨ÌØÂÊΪ 36/(6*(2+4+6))=500k
u8 can_tx(u16 Data1)
{
u16 i;
CanTxMsg TxMessage;
TxMessage.StdId=0x11;
TxMessage.ExtId=0x0000;
TxMessage.IDE=CAN_ID_STD;
TxMessage.RTR=CAN_RTR_DATA;
TxMessage.DLC=8;
TxMessage.Data[0]=Data1/256 ;
TxMessage.Data[1]=Data1%256 ;
for(i=2;i<=TxMessage.DLC;i++)
TxMessage.Data=0;
|