Skip to main content
Markose Baby
Associate
September 8, 2017
Question

HAL_CAN_transmit_issue

  • September 8, 2017
  • 3 replies
  • 1325 views
Posted on September 08, 2017 at 14:05

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__);

}

}

    This topic has been closed for replies.

    3 replies

    T J
    Senior III
    September 10, 2017
    Posted on September 10, 2017 at 03:16

    enable hcan.Init.ABOM = ENABLE

    this will definately stop it working...

    Markose Baby
    Associate
    September 11, 2017
    Posted on September 11, 2017 at 09:53

    @

    Marsh.Nick

    Thank you for your reply.

    But enabling that didn't solve my problem. Checked the Error status and I found it as LEC dominant Error.Can you help me with the reason for errorand how could I resolve it ?

    T J
    Senior III
    September 11, 2017
    Posted on September 11, 2017 at 23:21

    LEC ? I never see this error.

    are your wires swapped ?

    what CanBus Driver chip are you using ?

    do you have a CanBus Dongle like CanDo ?

    can you receive frames ?

    Did you use CubeMX to set your bit rate ?

    Do you have a n Oscilloscope ?

    Markose Baby
    Associate
    September 12, 2017
    Posted on September 12, 2017 at 06:07

    1) HAL_CAN_ERROR_BD LEC dominant  ( as per the hal documnet )

    2) MCP 2562.... CAN transceiver used. 

    3)I I didn't receive any frame.

    4)  All Set in Cube MX as below

    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;

    }

    5) I am using IXXAT can USB interface to connect PC and device.m 

    Rachel Duray
    Associate II
    July 13, 2018
    Posted on July 13, 2018 at 11:22

    Hello Markose,

    I think u missed the initialization of addresses of 

    TxMsg and RxMsg. Can you define in  

    MX_CAN_Init function as 

      hcan.pTxMsg = &

    TxMsg

    ;