cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F302 CAN works only in LoopBack mode

franck23
Senior
Posted on May 29, 2017 at 16:41

Hello,

I am developing an application using a CAN bus and 2 differentMCU: STM32F407 and STM32F

The code for the STM32F407 works fine. Icanseedata 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);
}�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

1 ACCEPTED SOLUTION

Accepted Solutions
Posted on May 29, 2017 at 19:15

Reflect on the connectivity of the transceiver and bus. ie If not the code, then it's the hardware.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

View solution in original post

3 REPLIES 3
Posted on May 29, 2017 at 19:15

Reflect on the connectivity of the transceiver and bus. ie If not the code, then it's the hardware.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
franck23
Senior
Posted on May 30, 2017 at 06:33

Hi Clive,

Yes, that was the hardware!

It is what happens when you buy cheap pre-crimped wire for testing. One of the wires had rusty iron instead of copper...

The code on the first post works fine.

I have attached a close look of the wire below...

BTW, I couldn't find how to properly insert code on the forum. The [CODE] [/CODE] doesn't work?

Thanks,

Franck.

0690X00000602SkQAI.bmp
Posted on May 30, 2017 at 11:57

Hi

Guillon.Franck

,

To format source code, click on 'More >> Syntax Highlighter'

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen