AnsweredAssumed Answered

STM32F407VG DISCOVERY BOARD micro controller CAN messages

Question asked by naeen reddy on Sep 26, 2017

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 STM32F103 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);

Outcomes