Question
STM32L4 - CAN HAL driver transmit error
Posted on September 06, 2017 at 10:39
Hello,
I am using STM32L476G evaluation board, I have generated CAN HAL driver using default parameters which is available in Cube MX. using this when i try to transmit a message i am getting transmit error(TERR0 = 1). Please refer the code below.
Can some one tell me why I am getting this error.
static void MX_CAN1_Init(void)
{hcan1.Instance = CAN1;
hcan1.Init.Prescaler = 16; hcan1.Init.Mode = CAN_MODE_NORMAL; hcan1.Init.SJW = 0; hcan1.Init.BS1 = 0; hcan1.Init.BS2 = 0; 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) { _Error_Handler(__FILE__, __LINE__); }}
int main(void)
{HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_CAN1_Init(); hcan1.pTxMsg->Data[0] = 0x11; hcan1.pTxMsg->Data[1] = 0x12; hcan1.pTxMsg->Data[2] = 0x13; hcan1.pTxMsg->Data[3] = 0x14; hcan1.pTxMsg->Data[4] = 0x15; hcan1.pTxMsg->Data[5] = 0x16; hcan1.pTxMsg->Data[6] = 0x17; hcan1.pTxMsg->Data[7] = 0x18; hcan1.pTxMsg->DLC = 8; hcan1.pTxMsg->StdId = 0x71F; hcan1.pTxMsg->ExtId = 0; hcan1.pTxMsg->IDE = CAN_ID_STD; hcan1.pTxMsg->RTR = CAN_RTR_DATA; HAL_CAN_Transmit(&hcan1, 50);}
Thanks
Anand
