AnsweredAssumed Answered

STM32F302 CAN works only in LoopBack mode

Question asked by Franck80 on May 29, 2017
Latest reply on May 30, 2017 by Imen D

Hello,

I am developing an application using a CAN bus and 2 different MCU: STM32F407 and STM32F302.

The code for the STM32F407 works fine. I can see data on the bus using an oscillo.

However, the STM32F302 does not ack the message and does not transmit either.

The STM32F302 works in loop back mode, but in normal mode, I cannot get it to send data on the Tx line. the tx line is always high and the Tx Mailbox just stays full.

I suppose the problem is in the GPIO initialization, but cannot find the problem

Any help is welcome.

void CAN_Config()
{
CAN_InitTypeDef CAN_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;

/* Enable CAN clock */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE);

/* Enable GPIO clock */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
/* Connect CAN pins to AF */
GPIO_PinAFConfig(GPIOA, GPIO_PinSource11, GPIO_AF_9);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource12, GPIO_AF_9);
/* Configure CAN RX and TX pins */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_12;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOA, &GPIO_InitStructure);

/* CAN register init */
CAN_DeInit(CAN1);
CAN_StructInit(&CAN_InitStructure);
/* CAN cell init */
CAN_InitStructure.CAN_TTCM = DISABLE;
CAN_InitStructure.CAN_ABOM = DISABLE;
CAN_InitStructure.CAN_AWUM = DISABLE;
CAN_InitStructure.CAN_NART = DISABLE;
CAN_InitStructure.CAN_RFLM = ENABLE;
CAN_InitStructure.CAN_TXFP = DISABLE;
CAN_InitStructure.CAN_Mode = CAN_Mode_Normal;
CAN_InitStructure.CAN_SJW = CAN_SJW_1tq;
/* CAN Baudrate = 500kbps (CAN clocked at 36 MHz) */
CAN_InitStructure.CAN_BS1 = CAN_BS1_5tq;
CAN_InitStructure.CAN_BS2 = CAN_BS2_6tq;
CAN_InitStructure.CAN_Prescaler = 6;
CAN_Init(CAN1, &CAN_InitStructure);

/* CAN filter init */
SetCANFilters(CAN_NodeID);
}

Outcomes