2017-09-08 05:05 AM
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__); }}
2017-09-09 06:16 PM
enable hcan.Init.ABOM = ENABLE
this will definately stop it working...
2017-09-11 12:53 AM
@
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 ?
2017-09-11 04:21 PM
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 ?
2017-09-11 11:07 PM
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
2017-09-12 04:57 AM
is CanRx pin on the processor high ? if not try a 10k pullup.
do you have an oscilloscope ?
can you check the TX baud rate you are expecting ?
2018-07-13 02:22 AM
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
;