CAN_FilterInitTypeDef CAN_FilterInitStructure;
CAN_FilterInitStructure.CAN_FilterNumber = 1; //CAN1?????0?13
CAN_FilterInitStructure.CAN_FilterMode = CAN_FilterMode_IdMask; //??????
CAN_FilterInitStructure.CAN_FilterScale = CAN_FilterScale_32bit;
CAN_FilterInitStructure.CAN_FilterIdHigh = 0x0000;
CAN_FilterInitStructure.CAN_FilterIdLow = 0x0000;
CAN_FilterInitStructure.CAN_FilterMaskIdHigh = 0x0000; //?????ID
CAN_FilterInitStructure.CAN_FilterMaskIdLow = 0x0000; //?????ID
CAN_FilterInitStructure.CAN_FilterFIFOAssignment = CAN_Filter_FIFO0; // /*!< Specifies the FIFO (0 or 1) which will be assigned to the filter.
//This parameter can be a value of @ref CAN_filter_FIFO */
CAN_FilterInitStructure.CAN_FilterActivation = ENABLE;
CAN_FilterInit(CAN2, &CAN_FilterInitStructure);
目前用CAN卡分析的就是2号节点不能与3/4/5同时工作。但是他可以和1号节点同时工作。
供电电源的功率是足够的,滤波器配置指的是哪里呢?
你这初始化配置的位时间参数为:
SJW=1tq
BS1=9qt
BS2=8qt
按这个参数算出来的采样点=(1+BS1)/(1+BS1+BS2)=(1+9)/(1+9+8)=55.56%,太低了(按CiA的建议,采样点尽量接近但不超过87.5%)
你试试这组参数:
SJW=1qt
BS1=14qt
BS2=3qt
多谢帮助,我试了一下,还是有问题。
1、2号单片机的型号是STM32F103CBT6;3,4,5单片机型号是STM32F413VGT6。刚才贴的初始化代码是1,2单片机的。3,4,5单片机的初始化代码如下:
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN2, ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//????
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource5, GPIO_AF_CAN2);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_CAN2);
CAN_DeInit(CAN2);
CAN_InitTypeDef CAN_InitStructure;
/* CAN cell init */
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;
CAN_InitStructure.CAN_TXFP = DISABLE;
CAN_InitStructure.CAN_Mode = CAN_Mode_Normal;
//500kbps
CAN_InitStructure.CAN_SJW = CAN_SJW_1tq;
CAN_InitStructure.CAN_BS1 = CAN_BS1_3tq;
CAN_InitStructure.CAN_BS2 = CAN_BS2_1tq;
CAN_InitStructure.CAN_Prescaler = 20;
CAN_Init(CAN2, &CAN_InitStructure);
CAN_FilterInitTypeDef CAN_FilterInitStructure;
CAN_FilterInitStructure.CAN_FilterNumber = 1; //CAN1?????0?13
CAN_FilterInitStructure.CAN_FilterMode = CAN_FilterMode_IdMask; //??????
CAN_FilterInitStructure.CAN_FilterScale = CAN_FilterScale_32bit;
CAN_FilterInitStructure.CAN_FilterIdHigh = 0x0000;
CAN_FilterInitStructure.CAN_FilterIdLow = 0x0000;
CAN_FilterInitStructure.CAN_FilterMaskIdHigh = 0x0000; //?????ID
CAN_FilterInitStructure.CAN_FilterMaskIdLow = 0x0000; //?????ID
CAN_FilterInitStructure.CAN_FilterFIFOAssignment = CAN_Filter_FIFO0; // /*!< Specifies the FIFO (0 or 1) which will be assigned to the filter.
//This parameter can be a value of @ref CAN_filter_FIFO */
CAN_FilterInitStructure.CAN_FilterActivation = ENABLE;
CAN_FilterInit(CAN2, &CAN_FilterInitStructure);
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel = CAN2_RX0_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
CAN_ITConfig(CAN2, CAN_IT_FMP0, ENABLE);
一周热门 更多>