使用CH32F20这款MCU的CAN通信,例子代码看不懂,有无大侠解释一下:
代码如下:
1)函数的各参数是什么含义?除了Bps =Fpclk1/((tpb1+1+tbs2+1+1)*brp)含义以外,各参数设置注意哪些事项。
2)函数内的各个设置都有哪些注意事项
void CAN_Test_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};
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_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;
CAN_FilterInitSturcture.CAN_FilterMode = CAN_FilterMode_IdMask;
CAN_FilterInitSturcture.CAN_FilterScale = CAN_FilterScale_32bit;
CAN_FilterInitSturcture.CAN_FilterIdHigh = 0;
CAN_FilterInitSturcture.CAN_FilterIdLow = 0;
CAN_FilterInitSturcture.CAN_FilterMaskIdHigh = 0;
CAN_FilterInitSturcture.CAN_FilterMaskIdLow = 0x0006;
CAN_FilterInitSturcture.CAN_FilterFIFOAssignment = CAN_Filter_FIFO1;
CAN_FilterInitSturcture.CAN_FilterActivation = ENABLE;
CAN_FilterInit( &CAN_FilterInitSturcture );
}