cancel
Showing results for 
Search instead for 
Did you mean: 

STM3240G-EVAL / STM32F407 / CAN2 Issue

l239955
Associate II
Posted on February 26, 2015 at 17:09

Hello everybody,

I am working with a STM3240G-EVAL card (STM32F407) and I have CAN2 issue, especially the with the reception part. I need help.

I already tested the CAN1 channel and it worked really fine. Then I changed the definitions in order to use the CAN2 channel as followed:

&sharpdefine

CANx                            CAN2

//CAN1

//CAN1 Clock must absolutely be enabled to use CAN2 !!!

&sharpdefine

CANx_CLK_ENABLE()               __HAL_RCC_CAN1_CLK_ENABLE(); __HAL_RCC_CAN2_CLK_ENABLE()

&sharpdefine

CANx_GPIO_CLK_ENABLE()          __HAL_RCC_GPIOB_CLK_ENABLE()

//__HAL_RCC_GPIOD_CLK_ENABLE()

&sharpdefine

CANx_FORCE_RESET()              __HAL_RCC_CAN2_FORCE_RESET()

//__HAL_RCC_CAN1_FORCE_RESET()

&sharpdefine

CANx_RELEASE_RESET()            __HAL_RCC_CAN2_RELEASE_RESET()

//__HAL_RCC_CAN1_RELEASE_RESET()

/* Definition for USARTx Pins */

&sharpdefine

CANx_TX_PIN                    GPIO_PIN_13

//GPIO_PIN_1

&sharpdefine

CANx_TX_GPIO_PORT              GPIOB

//GPIOD

&sharpdefine

CANx_TX_AF                     GPIO_AF9_CAN2

//GPIO_AF9_CAN1

&sharpdefine

CANx_RX_PIN                    GPIO_PIN_5

//GPIO_PIN_0

&sharpdefine

CANx_RX_GPIO_PORT              GPIOB

//GPIOD

&sharpdefine

CANx_RX_AF                     GPIO_AF9_CAN2

//GPIO_AF9_CAN1

/* Definition for USARTx's NVIC */

&sharpdefine

CANx_RX_IRQn                   CAN2_RX0_IRQn

//CAN1_RX0_IRQn

&sharpdefine

CANx_RX_IRQHandler             CAN2_RX0_IRQHandler

//CAN1_RX0_IRQHandler

The emission from CAN2 works really fine, but the reception doesn�t. Whatever I send from the other side, the CAN2 Rx buffers stay empty and I don�t have any more ideas.

Does that case already happened with somebody else?

#stm3240-stm32f407-can2 #can2-configuration #can2-filter-configuration
5 REPLIES 5
Posted on February 26, 2015 at 17:57

Does that case already happened with somebody else?

Does sound awfully familiar, but I'm not touching HAL/Cube stuff.

Someone in one of the [DEAD LINK /public/STe2ecommunities/mcu/Lists/STM32Java/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/STM32Java/Bug%20in%20HAL_CAN_ConfigFilter%28%29%20in%20STM32Cube_FW_F4_V1.4.0&FolderCTID=0x01200200770978C69A1141439FE559EB459D758000F9A0E3A95BA69146A17C2E80209ADC21&TopicsView=https://my.st.com/public/STe2ecommunities/mcu/Lists/STM32Java/AllItems.aspx&currentviews=13]other threads indicated an explicit reference to CAN1, but I haven't dug into it enough to know if it's a real issue, or a Master/Slave relationship of CAN1 vs CAN2.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
jpeacock
Associate III
Posted on February 26, 2015 at 22:36

A couple of items:

First, the STM3240G only has one CAN transceiver, connected to CAN1.  CAN2 pins conflict with USB so make sure you are not using any USB HS functions and those pins are disconnected from the USB side and connected to the transceiver.

I used both CAN buses but I configure CAN2 as a loopback for some internal testing, no external pins.  It's handy for redundant bus software tests on CANopen.

Second, make sure you set the break for filter banks between CAN1 and CAN2 in the CAN memory.  And make sure you are setting the right filters.  I break at 14, 0-13 for CAN1, 14-27 for CAN2  (works very well for the CANopen stack filtering by group).  Assuming CAN2 goes to a transceiver and no USB interference you may not receive anything because of filtering.

  Jack Peacock
l239955
Associate II
Posted on February 27, 2015 at 10:23

Hello,

Thank you for your answers Jack Peacock and Clive.

Here is the filtering configuration part:

-------------------------------------------------------------------------------------------------------------------------

/*##-2- Configure the CAN Filter ###########################################*/

    sFilterConfig.

FilterNumber

= 14;

    sFilterConfig.

FilterMode

= CAN_FILTERMODE_IDMASK;

    sFilterConfig.

FilterScale

= CAN_FILTERSCALE_32BIT;

    sFilterConfig.

FilterIdHigh

= 0x0000;

    sFilterConfig.

FilterIdLow

= 0x0000;

    sFilterConfig.

FilterMaskIdHigh

= 0x0000;

    sFilterConfig.

FilterMaskIdLow

= 0x0000;

    sFilterConfig.

FilterFIFOAssignment

= 0;

    sFilterConfig.

FilterActivation

=

ENABLE

;

    sFilterConfig.

BankNumber

= 0;

   

if

(HAL_CAN_ConfigFilter(&CanHandle, &sFilterConfig) !=

HAL_OK

)

    {

        /* Filter configuration Error */

        Error_Handler();

    }

-------------------------------------------------------------------------------------------------------------------------

I can confirm that I don't use any USB function and that the JP31 jumper for USB HS is not fitted. Unfortunatly the result is still the same, namely the CAN2 doesn't read anything and the Rx buffer still stays empty.
Posted on February 27, 2015 at 14:56

Have you checked the wiring of the transceiver?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
l239955
Associate II
Posted on March 02, 2015 at 18:28

Yes, I have.

I now use alternative pins from CAN1 to get round my issue but I keep that question in my mind.

Thank you for your involvement.