1
\$\begingroup\$

I am wondering if anyone is familiar with any STM32f407VG micro-controllers?

If so, I am having some problems configuring a CAN driver.
I can run the demo code, which is set to a loop-back mode, but I cannot get normal mode to work.

I think message is not going out of the transmit mailbox. Status is going to pending all the time.

I read through all the data sheets, and everything is configured correctly except the INAK in the CAN_MSR register never resets to 0. I can provide more detail if needed, but first I need to know if there is someone who has worked with a STM32F4 microcontroller and CAN messages.

Here is my sample code:

RCC_APB1PeriphClockCmd(CAN_CLK, ENABLE); 
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);  
GPIO_PinAFConfig(CAN_GPIO_PORT, CAN_RX_SOURCE, CAN_AF_PORT);  
GPIO_PinAFConfig(CAN_GPIO_PORT, CAN_TX_SOURCE, CAN_AF_PORT); 
/* Configure CAN RX and TX pins */   
GPIO_InitStructure.GPIO_Pin = CAN_RX_PIN | CAN_TX_PIN;  
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(CAN_GPIO_PORT, &GPIO_InitStructure);   
CAN_DeInit(CANx);
CAN_StructInit(&CAN_InitStructure);   
CAN_InitStructure.CAN_TTCM = DISABLE;   
CAN_InitStructure.CAN_ABOM = DISABLE;   
CAN_InitStructure.CAN_AWUM = DISABLE;   
CAN_InitStructure.CAN_NART = DISABLE;   
CAN_InitStructure.CAN_RFLM = DISABLE;  
CAN_InitStructure.CAN_TXFP = DISABLE;   
CAN_InitStructure.CAN_Mode = CAN_Mode_Normal;   
CAN_InitStructure.CAN_SJW = CAN_SJW_1tq;
/* CAN Baudrate = 1 MBps (CAN clocked at 30 MHz) */   
CAN_InitStructure.CAN_BS1 = CAN_BS1_6tq;   
CAN_InitStructure.CAN_BS2 = CAN_BS2_8tq;   
CAN_InitStructure.CAN_Prescaler = 2;  
CAN_Init(CANx, &CAN_InitStructure);

/************transmit message config***********/

TxMessage.StdId = 0x11;   
TxMessage.RTR = CAN_RTR_DATA;  
TxMessage.IDE = CAN_ID_STD;   
TxMessage.DLC = 2;   
TxMessage.Data[0] = 0xCA;   
TxMessage.Data[1] = 0xFE;

CAN_Transmit(CANx, &TxMessage);
uwCounter = 0;   
while(( CAN_TransmitStatus(CANx, TransmitMailbox)  !=  CANTXOK) && (uwCounter  !=  0xFFFF))   
{
    uwCounter++;   
}  
uwCounter = 0;   
while((CAN_MessagePending(CANx, CAN_FIFO0) < 1) && (uwCounter  != 0xFFFF))   
{
    uwCounter++;   
} 
k = CAN_TransmitStatus(CANx, i);
\$\endgroup\$
9
  • \$\begingroup\$ You are mentioning two chips. Pick one. \$\endgroup\$
    – Jeroen3
    Commented Sep 25, 2017 at 20:20
  • 1
    \$\begingroup\$ Do you have a CAN interface chip that is connected to a CAN network? If so, please describe \$\endgroup\$
    – user28910
    Commented Sep 25, 2017 at 20:39
  • \$\begingroup\$ I am using two stm32f4-discovery board and mcp2551 transceiver that connects between two boards \$\endgroup\$ Commented Sep 26, 2017 at 6:09
  • 1
    \$\begingroup\$ You need 2 CAN controllers (microcontrollers), each with their own transceiver (for example mcp2551). And the bus needs two terminating resistors of 120 Ohm. Is this the case? Also note that the two boards will not start synchronously. The first node to start have to expect CAN errors until the point where another CAN controller is active on the bus. \$\endgroup\$
    – Lundin
    Commented Sep 26, 2017 at 11:50
  • \$\begingroup\$ i have two 120 ohm terminating resistors .both controllers are active on bus . problem is when i send message it is loading into can txmailbox and it not going out of mail box . i have cheak the status of mail box it is showing status as pending .if it is in loop mode it is working fine \$\endgroup\$ Commented Sep 26, 2017 at 12:11

0

Browse other questions tagged or ask your own question.