2017-05-29 07:41 AM
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);
}�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?
Solved! Go to Solution.
2017-05-29 10:15 AM
Reflect on the connectivity of the transceiver and bus. ie If not the code, then it's the hardware.
2017-05-29 10:15 AM
Reflect on the connectivity of the transceiver and bus. ie If not the code, then it's the hardware.
2017-05-29 09:33 PM
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.
2017-05-30 04:57 AM
Hi
Guillon.Franck
,To format source code, click on 'More >> Syntax Highlighter'