I can’t start the CAN module on STM32F103C8 in normal mode
- July 7, 2020
- 4 replies
- 3022 views
when I run the CAN module in loopback mode - packets
transferred to the bus - everything is OK
when I run the CAN module in silent mode I will receive packets - everything is OK
but when I start the CAN module in normal mode - 15 pulses go out on the TX pin and everything stops ... packets are not transmitted ...
what am I doing wrong???
I generated the start configuration using:
STM32CubeMX 5.6.1
Firmwere STM32Cube FW_F1 V1.8.0
Atollic TrueSTUDIO Version: 9.3.0 Build id: 20190212-0734
I've been in conjunction with both ISO1050 and MCP2551 ...
I looked at the bus using a Chinese logic analyzer ....
connected to the parallel of RX and TX pins
Code:
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
#define TxBroadcastVoltagIdentifier 0x5FF400C
#define TxDeviceRegistrationFeedbeckIdentifier 0x5004804
#define TxSetDefaultVoltageIdentifier 0x5FF400C
/* USER CODE END PD */
/* Private variables ---------------------------------------------------------*/
CAN_HandleTypeDef hcan;
/* USER CODE BEGIN PV */
CAN_FilterTypeDef FlatPackRXFilter;
CAN_RxHeaderTypeDef RxHeader;
uint8_t RxData[16];
uint32_t RxFifo;
CAN_TxHeaderTypeDef TxHeader;
uint8_t TxData[16];
uint32_t TxFifo;
uint8_t test;
/* USER CODE END PV */
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
// hcan.Instance->BTR &= ~CAN_MCR_SLEEP;
// hcan.Instance->MSR = CAN_MSR_SLAK;
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_CAN_Init();
/* USER CODE BEGIN 2 */
FlatPackRXFilter.FilterBank = 0;
FlatPackRXFilter.FilterActivation = CAN_FILTER_ENABLE ;
FlatPackRXFilter.FilterFIFOAssignment = CAN_FILTER_FIFO0;
FlatPackRXFilter.FilterIdHigh = 0;
FlatPackRXFilter.FilterIdLow = 0;
FlatPackRXFilter.FilterMaskIdHigh = 0;
FlatPackRXFilter.FilterMaskIdLow = 0;
FlatPackRXFilter.FilterMode = CAN_FILTERMODE_IDMASK;
FlatPackRXFilter.FilterScale = CAN_FILTERSCALE_32BIT;
if (HAL_CAN_ConfigFilter(&hcan, &FlatPackRXFilter) != HAL_OK)
{
Error_Handler();
}
if (HAL_CAN_Start(&hcan) != HAL_OK)
{
Error_Handler();
}
if (HAL_CAN_ActivateNotification(&hcan, CAN_IT_RX_FIFO0_MSG_PENDING) != HAL_OK)
{
Error_Handler();
}
if (HAL_CAN_ActivateNotification(&hcan, CAN_IT_RX_FIFO0_OVERRUN) != HAL_OK)
{
Error_Handler();
}
TxHeader.ExtId = TxBroadcastVoltagIdentifier;
TxHeader.DLC = 8;
TxHeader.IDE = CAN_ID_EXT;
TxHeader.RTR = CAN_RTR_DATA;
TxHeader.TransmitGlobalTime = DISABLE;
HAL_Delay(100);
TxData[0]=0x32;
TxData[0]=0xF0;
if (HAL_CAN_AddTxMessage(&hcan, &TxHeader, TxData, &TxFifo) != HAL_OK)
{
Error_Handler();
}
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
test = HAL_CAN_AddTxMessage(&hcan, &TxHeader, TxData, &TxFifo);
if (test != HAL_OK)
{
Error_Handler();
}
HAL_Delay(100);
}
/* USER CODE END 3 */
}
/* USER CODE BEGIN 4 */
void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan)
{
if (HAL_CAN_GetRxMessage(hcan, RxFifo, &RxHeader, RxData) != HAL_OK)
{
Error_Handler();
}
}
/* USER CODE END 4 */
