CH32V203 CAN在发送数据时接收脚也检测到相同波形,跟其它模块通信又没问题,正常吗?
这是初始化
void CAN_Mode_Init( u8 tsjw, u8 tbs2, u8 tbs1, u16 brp, u8 mode )
{
GPIO_InitTypeDef GPIO_InitSturcture={0};
CAN_InitTypeDef CAN_InitSturcture={0};
CAN_FilterInitTypeDef CAN_FilterInitSturcture={0};
NVIC_InitTypeDef NVIC_InitStructure={0};
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO | RCC_APB2Periph_GPIOB, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE);
GPIO_PinRemapConfig(GPIO_Remap1_CAN1, ENABLE);
GPIO_InitSturcture.GPIO_Pin = GPIO_Pin_9;
GPIO_InitSturcture.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitSturcture.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitSturcture);
GPIO_InitSturcture.GPIO_Pin = GPIO_Pin_8;
GPIO_InitSturcture.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOB, &GPIO_InitSturcture);
//CAN单元配置
CAN_InitSturcture.CAN_TTCM = DISABLE;
CAN_InitSturcture.CAN_ABOM = DISABLE;
CAN_InitSturcture.CAN_AWUM = DISABLE;
CAN_InitSturcture.CAN_NART = ENABLE;
CAN_InitSturcture.CAN_RFLM = DISABLE;
CAN_InitSturcture.CAN_TXFP = DISABLE;
CAN_InitSturcture.CAN_Mode = mode;
CAN_InitSturcture.CAN_SJW = tsjw;
CAN_InitSturcture.CAN_BS1 = tbs1;
CAN_InitSturcture.CAN_BS2 = tbs2;
CAN_InitSturcture.CAN_Prescaler = brp;
CAN_Init( CAN1, &CAN_InitSturcture );
CAN_FilterInitSturcture.CAN_FilterNumber = 0;
if(SetExtendedFrame == Standard_Frame)
{
/* identifier/mask mode, One 32-bit filter, StdId: All*/
CAN_FilterInitSturcture.CAN_FilterMode = CAN_FilterMode_IdMask;
CAN_FilterInitSturcture.CAN_FilterScale = CAN_FilterScale_32bit;
CAN_FilterInitSturcture.CAN_FilterIdHigh = 0xFFFF;
CAN_FilterInitSturcture.CAN_FilterIdLow = 0xFFFF;
CAN_FilterInitSturcture.CAN_FilterMaskIdHigh = 0;
CAN_FilterInitSturcture.CAN_FilterMaskIdLow = 0;
}
else if(SetExtendedFrame == Extended_Frame)
{
/* identifier/mask mode, One 32-bit filter, ExtId: 0x12124567 */
CAN_FilterInitSturcture.CAN_FilterMode = CAN_FilterMode_IdMask;
CAN_FilterInitSturcture.CAN_FilterScale = CAN_FilterScale_32bit;
CAN_FilterInitSturcture.CAN_FilterIdHigh = 0x9092;
CAN_FilterInitSturcture.CAN_FilterIdLow = 0x2B3C;
CAN_FilterInitSturcture.CAN_FilterMaskIdHigh = 0xFFFF;
CAN_FilterInitSturcture.CAN_FilterMaskIdLow = 0xFFFE;
}
CAN_FilterInitSturcture.CAN_FilterFIFOAssignment = CAN_Filter_FIFO0;
CAN_FilterInitSturcture.CAN_FilterActivation = ENABLE;
CAN_FilterInit( &CAN_FilterInitSturcture );
CAN_ITConfig(CAN1,CAN_IT_FMP0,ENABLE); //FIFO0消息挂号中断允许.
NVIC_InitStructure.NVIC_IRQChannel = USB_LP_CAN1_RX0_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
你好,CAN在通信时是TX/RX接到一起的,因为CAN在发送时要根据接收来判断发送的是否正确,是正常的
这是正常的CAN总线竞争逻辑,所有的CAN都是这样的。CAN节点发送ID的时候要同时判断接收到的ID是否相同,如果不同,说明其它节点发送的显性电平覆盖了自己发送的隐性电平,有其它节点发送优先级更高的帧,当前节点退出总线竞争。