我正在尝试使用从USB2CAN设备传输的SN65HVD233收发器在STM32F412G-DISCOVERY上接收CAN帧。两者都连接在长约15厘米的总线上,每端有两个120Ω电阻。我连接示波器,在收发器转换之前读取STM32板上的RX和TX引脚。当我以静音模式配置CAN控制器并使用以下命令从USB2CAN发送CAN帧时:$ cansend can0 '144#25'
我在RX引脚的示波器上看到整个帧(黄 {MOD}是电路板的RX,蓝 {MOD}是其TX):
注意:光标指示一位的时间间隔(2μs,比特率为500 kb / s)。(HAL_CAN_Receive呼叫仍然超时,但这是另一个问题。)但是当我将控制器置于正常模式时,这是我测量的:
这是代码:
- <font size="4">hcan1.pTxMsg = &g_out_msg;
- hcan1.pRxMsg = &g_in_msg;
- hcan1.Instance = CAN1;
- hcan1.Init.Prescaler = 12;
- hcan1.Init.Mode = CAN_MODE_NORMAL;
- hcan1.Init.SJW = CAN_SJW_1TQ;
- hcan1.Init.BS1 = CAN_BS1_1TQ;
- hcan1.Init.BS2 = CAN_BS2_1TQ;
- hcan1.Init.TTCM = DISABLE;
- hcan1.Init.ABOM = DISABLE;
- hcan1.Init.AWUM = DISABLE;
- hcan1.Init.NART = DISABLE;
- hcan1.Init.RFLM = DISABLE;
- hcan1.Init.TXFP = DISABLE;
- if (HAL_CAN_Init(&hcan1) != HAL_OK)
- fatal_error("failed to init HAL CAN.");
- CAN_FilterConfTypeDef sFilterConfig;
- sFilterConfig.FilterNumber = 0;
- sFilterConfig.FilterMode = CAN_FILTERMODE_IDMASK;
- sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;
- sFilterConfig.FilterIdHigh = 0x0000;
- sFilterConfig.FilterIdLow = 0x0000;
- sFilterConfig.FilterMaskIdHigh = 0x0000;
- sFilterConfig.FilterMaskIdLow = 0x0000;
- sFilterConfig.FilterFIFOAssignment = 0;
- sFilterConfig.FilterActivation = ENABLE;
- sFilterConfig.BankNumber = 14;
- if (HAL_CAN_ConfigFilter(&hcan1, &sFilterConfig) != HAL_OK)
- fatal_error("failed to setup CAN filter.");
- HAL_StatusTypeDef can_status;
- if ((can_status = HAL_CAN_Receive(&hcan1, CAN_FIFO0, 20000)) != HAL_OK)
- fatal_error("failed to receive frame: %d", can_status);</font>
复制代码看起来发射器(USB2CAN)尝试为ID的第2位写入隐性(1),而接收器(STM32)发送显性(0):发射器检测到碰撞并停止发射。为什么STM32 CAN控制器发送停止通信的显性位?
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>