STM32 CAN配置
下面是1MHz的配置参数
void MX_CAN1_Init(void)
{
/*隐性电平为0,每条电压为2.5V,显性电平压差为2.5V,High为3V5,low为1.5V*/
/*
为了实现can同步,CAN通讯包含SS段:同步段(1)
PTS段:传播时间段(1~8)
PBS1段:相位缓冲段(1~8)
PB2段:相位缓冲段2(2~8)
SJW(再同步补偿段)(1~4)
*/
/*
波特率计算:
1.时钟频率:CAN的时钟频率是pclk1 :可以读取相关的时钟频率;
2.波特率计算 168/4 /3 /(1+6+7)
*/
hcan1.Instance = CAN1;
hcan1.Init.Prescaler = 3;/*预分频,即位时序提到的APB1 peripheral clocks继续分一次频*/
hcan1.Init.Mode = CAN_MODE_NORMAL;
hcan1.Init.SyncJumpWidth = CAN_SJW_1TQ;/*重同步跳跃宽度,即位时序提到的SJW*/
hcan1.Init.TimeSeg1 = CAN_BS1_6TQ;/*PBS1段长度*/
hcan1.Init.TimeSeg2 = CAN_BS2_7TQ;/*PBS2段长度*/
hcan1.Init.TimeTriggeredMode = DISABLE;/*是否使能时间触发*/
hcan1.Init.AutoBusOff = ENABLE;/*是否使能自动离线管理*/
hcan1.Init.AutoWakeUp = DISABLE; /*是否使能自动唤醒*/
hcan1.Init.AutoRetransmission = ENABLE;/*是否使能自动重传*/
hcan1.Init.ReceiveFifoLocked = DISABLE; /*是否使能锁定FIFO*/
hcan1.Init.TransmitFifoPriority = ENABLE; /*配置报文优先级的判断方法*/
if (HAL_CAN_Init(&hcan1) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN CAN1_Init 2 */
//CAN_FilterTypeDef
/* USER CODE END CAN1_Init 2 */
}
posted on 2022-04-15 11:13 songwei2030 阅读(1030) 评论(0) 编辑 收藏 举报