2019-02-14 03:47 AM
Dear ST sirs:
We are using STM32F072C8, and we now have problem on its CAN bus. Like the below thread issue in the forum. However we did not see any reply on it.
This is 1st time we use CAN bus so maybe our question could be stupid.
We connect 2 of our devices to the bus, and CAN pins are PB8 and PB9
When we set the loopback mode, the TX/RX has no problem on the test problem.
But when we set to normal mode, the TX will have error on it and receives nothing.
When using the STM32CubeMX, I see a setting CAN Master mode which needs to use PA11 and PA12. Should we change to CAN Master pins in our devices?
Regards,
/ckhsu
2019-02-14 04:43 AM
Do you redirected CAN module pins to PB8 and PB9 ? Also should be connected pullup 4.7K-10K resistor to VCC.
/* Peripheral clock enable */
__HAL_RCC_CAN1_CLK_ENABLE();
/**CAN GPIO Configuration
PB8 ------> CAN_RX
PB9 ------> CAN_TX
*/
GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF4_CAN;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
Gediminas
2019-02-14 11:50 PM
Hi Gediminas:
We did that, and we also have the initialization process as you wrote above. That part is auto generated by the CubeMX. However, the TX will always return with the Timeout.
void HAL_CAN_MspInit(CAN_HandleTypeDef* hcan)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
if(hcan->Instance==CAN)
{
/* USER CODE BEGIN CAN_MspInit 0 */
/* USER CODE END CAN_MspInit 0 */
/* Peripheral clock enable */
__HAL_RCC_CAN1_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
/**CAN GPIO Configuration
PB8 ------> CAN_RX
PB9 ------> CAN_TX
*/
GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF4_CAN;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
/* USER CODE BEGIN CAN_MspInit 1 */
/* USER CODE END CAN_MspInit 1 */
}
}
Regards,
/ckhsu
2019-02-15 12:08 AM
Hi:
We also connect our board to a IXXAT USB-to-CAN compact to make sure the problem is not cause by no other nodes or no ack on the bus, but the situation is still the same.
If you have any other ideas, please let me know.
The attach is our code, even if the RX is marked, the TX is still Timeout.