问题是,我的CAN软件,一开始总是通信存在发送计数器累加,后来改了 CAN_InitStructure.CAN_BS1=CAN_BS1_7tq; 原来是CAN_BS1_14tq CAN_InitStructure.CAN_BS2=CAN_BS2_8tq; 原来是CAN_BS1_2tq;
原来的配置总是发着发着,我就离线了,而且还存在多发好几条重发命令,实际总线已经有了;
后来,开启了CAN_InitStructure.CAN_ABOM=ENABLE;总线离线自动上线模式;
而且禁止使能重发CAN_InitStructure.CAN_NART=ENABLE;
现在和别人联调时,在总线开启时,我总是会发好几条命令出来;
请问这个是为什么呢?
我发送是在收到客户命令后,置标志为1,然后检查到标志为1时,回复命令;
如果它的上条命令发来,我没回出去,然后总线关断,在开启的瞬间,我会一直发出好几条当初没发出去的命令?
如下是CAN的配置看是否存在问题?
void CAN1_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
CAN_InitTypeDef CAN_InitStructure;
CAN_FilterInitTypeDef CAN_FilterInitStructure;
/* Enable the clock for the CAN GPIOs */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
/* Connect the involved CAN pins to AF */
GPIO_PinAFConfig(GPIOA, GPIO_PinSource11, GPIO_AF_4);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource12, GPIO_AF_4);
/* Configure these CAN pins in alternate function mode by calling */
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_12;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Enable the peripheral clock CAN */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN, ENABLE);
/* CAN cell init */
CAN_InitStructure.CAN_TTCM=DISABLE;
CAN_InitStructure.CAN_ABOM=ENABLE;
CAN_InitStructure.CAN_AWUM=DISABLE;
CAN_InitStructure.CAN_NART=ENABLE;
CAN_InitStructure.CAN_RFLM=DISABLE;
CAN_InitStructure.CAN_TXFP=DISABLE;
// CAN_InitStructure.CAN_Mode=CAN_Mode_LoopBack;
CAN_InitStructure.CAN_Mode=CAN_Mode_Normal;
CAN_InitStructure.CAN_SJW=CAN_SJW_1tq;
CAN_InitStructure.CAN_BS1=CAN_BS1_7tq;
CAN_InitStructure.CAN_BS2=CAN_BS2_8tq;
CAN_InitStructure.CAN_Prescaler = 4; //(pclk1/((1+14+1)*4)) = 125Kbits
CAN_Init(CAN, &CAN_InitStructure);
CAN_FilterInitStructure.CAN_FilterNumber=0;
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;
CAN_FilterInitStructure.CAN_FilterMaskIdLow=0x0000;
CAN_FilterInitStructure.CAN_FilterFIFOAssignment= CAN_FIFO0;
CAN_FilterInitStructure.CAN_FilterActivation=ENABLE;
CAN_FilterInit(&CAN_FilterInitStructure);
CAN_ITConfig(CAN, CAN_IT_FMP0, ENABLE);
/* Configure IT */
/* (14) Set priority for CAN_IRQn */
/* (15) Enable CAN_IRQn */
NVIC_SetPriority(CEC_CAN_IRQn, 1); /* (16) */
NVIC_EnableIRQ(CEC_CAN_IRQn); /* (17) */
}
|