AnsweredAssumed Answered

HAL_CAN_transmit_issue

Question asked by Markose Baby on Sep 8, 2017
Latest reply on Sep 12, 2017 by T J

Hi, I am using StM32f042f4 (20 pin) for my project. I am getting stuck in can transmit. Logic work fine with different m0 controller. How can i solve it ? How do i check the error? 

 

#include "main.h"
#include "stm32f0xx_hal.h"


CAN_HandleTypeDef hcan;

 

CanTxMsgTypeDef TxMsg;
CanRxMsgTypeDef RxMsg;

 

void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_CAN_Init(void);

 

 

int main(void)

HAL_Init();


SystemClock_Config();
MX_GPIO_Init();
MX_CAN_Init();

 

TxMsg.Data[0] = 0xc0;
TxMsg.Data[1] = 0xc1;
TxMsg.Data[2] = 0xc2;
TxMsg.Data[3] = 0xc3;
TxMsg.Data[4] = 0xc4;
TxMsg.Data[5] = 0xc5;

TxMsg.DLC = 6;
TxMsg.StdId = 0x204;
TxMsg.IDE = CAN_ID_STD;
TxMsg.RTR = CAN_RTR_DATA;
hcan.pTxMsg = &TxMsg;
hcan.pRxMsg = &RxMsg;


while (1)
{
HAL_CAN_Transmit(&hcan,10000);
HAL_Delay(1000);

}

}

 

static void MX_CAN_Init(void)
{

hcan.Instance = CAN;
hcan.Init.Prescaler = 16;
hcan.Init.Mode = CAN_MODE_NORMAL;
hcan.Init.SJW = CAN_SJW_1TQ;
hcan.Init.BS1 = CAN_BS1_3TQ;
hcan.Init.BS2 = CAN_BS2_5TQ;
hcan.Init.TTCM = DISABLE;
hcan.Init.ABOM = DISABLE;
hcan.Init.AWUM = DISABLE;
hcan.Init.NART = DISABLE;
hcan.Init.RFLM = DISABLE;
hcan.Init.TXFP = DISABLE;
if (HAL_CAN_Init(&hcan) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}

}

Outcomes