CAN接口,双机通信C8T6芯片

2019-10-15 05:16发布

本帖最后由 翼间 于 2016-3-14 13:42 编辑

初始化问题居多,回环模式可以说明CAN设置部分无错,应该是管脚复用和时钟部分出错。关键部分代码没贴出来无法判断。
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
9条回答
翼间
2019-10-15 10:34
static void CAN_Mode_Config(void)
{
        CAN_InitTypeDef        CAN_InitStructure;

        CAN_DeInit(CAN1);
        CAN_StructInit(&CAN_InitStructure);

        CAN_InitStructure.CAN_TTCM=DISABLE;
        CAN_InitStructure.CAN_ABOM=ENABLE;
        CAN_InitStructure.CAN_AWUM=DISABLE;
        CAN_InitStructure.CAN_NART=DISABLE;
        CAN_InitStructure.CAN_RFLM=DISABLE;
        CAN_InitStructure.CAN_TXFP=DISABLE;
        CAN_InitStructure.CAN_Mode = CAN_Mode_Normal;       
        CAN_InitStructure.CAN_SJW=CAN_SJW_2tq;
        CAN_InitStructure.CAN_BS1=CAN_BS1_13tq;
        CAN_InitStructure.CAN_BS2=CAN_BS2_4tq;
        CAN_InitStructure.CAN_Prescaler = 20;       
        CAN_Init(CAN1, &CAN_InitStructure);
}

static void CAN_Filter_Config(void)
{
        CAN_FilterInitTypeDef  CAN_FilterInitStructure;

        CAN_FilterInitStructure.CAN_FilterNumber=0;
        CAN_FilterInitStructure.CAN_FilterMode=CAN_FilterMode_IdMask;
        CAN_FilterInitStructure.CAN_FilterScale=CAN_FilterScale_32bit;
       
        CAN_FilterInitStructure.CAN_FilterIdHigh= 0;
        CAN_FilterInitStructure.CAN_FilterIdLow= 0;
        CAN_FilterInitStructure.CAN_FilterMaskIdHigh= 0;
        CAN_FilterInitStructure.CAN_FilterMaskIdLow= 0;
        CAN_FilterInitStructure.CAN_FilterFIFOAssignment=CAN_Filter_FIFO0 ;
        CAN_FilterInitStructure.CAN_FilterActivation=ENABLE;
        CAN_FilterInit(&CAN_FilterInitStructure);

        CAN_ITConfig(CAN1, CAN_IT_FMP0, ENABLE);
}

拿去用吧,100K波特率

一周热门 更多>