Skip to main content
franck23
Associate III
May 29, 2017
Solved

STM32F302 CAN works only in LoopBack mode

  • May 29, 2017
  • 2 replies
  • 1016 views
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);
}�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

    This topic has been closed for replies.
    Best answer by Tesla DeLorean
    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.

    2 replies

    Tesla DeLorean
    Tesla DeLoreanBest answer
    Guru
    May 29, 2017
    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 VenmoUp vote any posts that you find helpful, it shows what's working..
    franck23
    franck23Author
    Associate III
    May 30, 2017
    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
    Technical Moderator
    May 30, 2017
    Posted on May 30, 2017 at 11:57

    Hi

    Guillon.Franck

    ,

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

    In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Thanks