2012-07-13 06:57 AM
Hi all,
I am trying to get the CAN interface working on the STM32F4DISCOVERY board.After calling the configuration functions from the peripheral library, when I tried to transmit message with just a oscilloscope connected to the TX and RX pins it does not work. I tried usng CAN_TransmitStatus() to see the status of the mailbox and it returned ''pending''. Then I tracked down the register in the CAN controller, the error flag is up and further more it says ''BIT DOMINANT error''... I don't know if I need to connect to a transceiver first and hook this board onto a CAN bus before I test it out? Or is it just something wrong with the configuration.Here is the code I had for the configuration part:---(I just used GPIOE pin0 to see if the program is running, nothing else) /* Enable GPIO clock */ RCC_AHB1PeriphClockCmd(CAN_GPIO_CLK|RCC_AHB1Periph_GPIOE, ENABLE); /* Connect CAN pins to AF9 */ 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); //RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE, ENABLE); //configure a pin for debug GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_Init(GPIOE, &GPIO_InitStructure); /* CAN configuration ********************************************************/ /* Enable CAN clock */ RCC_APB1PeriphClockCmd(CAN_CLK, ENABLE); /* CAN register init */ CAN_DeInit(CANx); /* 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 = 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); /* CAN filter init */#ifdef USE_CAN1 CAN_FilterInitStructure.CAN_FilterNumber = 0;#else /* USE_CAN2 */ CAN_FilterInitStructure.CAN_FilterNumber = 14;#endif /* USE_CAN1 */ CAN_FilterInitStructure.CAN_FilterMode = CAN_FilterMode_IdMask; CAN_FilterInitStructure.CAN_FilterScale = CAN_FilterScale_32bit; CAN_FilterInitStructure.CAN_FilterIdHigh = 0x0000; CAN_FilterInitStructure.CAN_FilterIdLow = 0x0000; CAN_FilterInitStructure.CAN_FilterMaskIdHigh = 0x0000; CAN_FilterInitStructure.CAN_FilterMaskIdLow = 0x0000; CAN_FilterInitStructure.CAN_FilterFIFOAssignment = 0; CAN_FilterInitStructure.CAN_FilterActivation = ENABLE; CAN_FilterInit(&CAN_FilterInitStructure); /* Transmit Structure preparation */ TxMessage.StdId = 0x321; TxMessage.ExtId = 0x01; TxMessage.RTR = CAN_RTR_DATA; TxMessage.IDE = CAN_ID_STD; TxMessage.DLC = 1; /* Enable FIFO 0 message pending Interrupt */ CAN_ITConfig(CANx, CAN_IT_FMP0, ENABLE);Any help is very appreciated. Thanks!Keybo2012-07-30 02:52 AM
I have just tested Silent_Loopback mode with TX/RX disconnected ... not working, CAN does not get initialized. Maybe transceiver is a must.
2012-07-30 08:19 AM
Has anyone yet successfully received CAN message with any mode, including Silent_Loopback? If yes, how did you set up filters and how did you actually receive the message?
2012-08-12 11:29 PM
Hi, i have successfully implemented both CAN1 and CAN2 on one of my custom boards using the STM32F407IGT6 device. Maybe i can assist one of you guys if you can explain your problem again?
2014-05-29 04:51 AM
Has anyone yet successfully implement CAN protocol with STM32F407?
If yes, how did you configure filters and clock and how did you actually send a message? I'm very confused!!!! I used Keil sample (for stm32f103), but I couldn't implement it for STM32f407!!!!2014-05-29 09:08 AM
Has anyone yet successfully implement CAN protocol with STM32F407?
Yes, receive and transmit, on both F2 and F4 boards.If yes, how did you configure filters and clock and how did you actually send a message? For transmit you have to have transceivers enabled, and you need some place to receive and acknowledge reception.[DEAD LINK /public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Can-Bus%20Error&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B¤tviews=122]https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=%2Fpublic%2FSTe2ecommunities%2Fmcu%2FLists%2Fcortex_mx_stm32%2FCan-Bus%20Error&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B¤tviews=122 The filters, as I recall, require the matching ID in the upper bits. I believe I have other code demonstrating this.I'm very confused!!!! Yes, this seems to be a very common ailment.2014-06-11 01:59 AM
Dear sir,
Thanks for your help. I want to connect two STM32F407 discovery board CAN pins together. So, I have to enable the transmitter and receiver pins on them. Could I connect CAN pins of theseboards
together directly?2014-06-11 03:54 AM
Could I connect CAN pins of these
boards
together directly? No, I'm pretty sure you're going to need a transceiver at both ends, and create the bus properly.2014-06-11 04:39 AM
How can I do this?
2014-06-11 06:30 AM
How can I do this?
Have you studied this at all? You'd want to wire it up in the same way pretty every other CAN bus is wired up.http://www.interfacebus.com/CAN-Bus-Description-Vendors-Canbus-Protocol.html
Then take a look at other ST EVAL boards, review how they did it, look at the schematics and review code examples in the firmware libraries, and on the forum.2014-06-11 04:24 PM
This works for testing purposes.It's from the keil example code, that I found a lot easier to get working and understand. (use 1N4148 diodes)