cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 CAN Normal Mode

akshayamk
Associate II
Posted on December 23, 2015 at 10:57

Hello!

I am working on STM32 board and I am able to make it work by hitting transmit and receive handlers on CAN loopback mode but not normal mode.

Are there any additional settings that have to be changed for CAN normal compared to loopback?

Thank you!

#stm
8 REPLIES 8
Posted on December 23, 2015 at 13:56

Are there any additional settings that have to be changed for CAN normal compared to loopback?

 

There has to be a receiving device on the bus to acknowledge the transmission.

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

Hello Clive,

I have already connected the board to a controller, which would be the receiving device of the transmitted message from the board.

Posted on December 24, 2015 at 06:31

Ok, there is very little detail here to work with.

You'll need to double check the bit rates are the same, and the transceivers and connectivity.

What STM32 is being used here?

Custom board? Describe/diagram the circuit.

What speeds / pins are you configuring? Show code

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

Hi Clive,

I am a custom made board using STM32F302 MCU and pinout.

I have configured the rx and tx pins as below:

  GPIO_InitStruct.Pin = GPIO_PIN_12;

  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

  GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;

  GPIO_InitStruct.Pull = GPIO_NOPULL;

  GPIO_InitStruct.Alternate =  GPIO_AF9_CAN;

 

  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

 

  /* CAN1 RX GPIO pin configuration */

  GPIO_InitStruct.Pin = GPIO_PIN_11;

  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

  GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;

  GPIO_InitStruct.Pull = GPIO_NOPULL;

  GPIO_InitStruct.Alternate =  GPIO_AF9_CAN;

 

  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

  /* System interrupt init*/

 HAL_NVIC_SetPriority(USB_HP_CAN_TX_IRQn, 0, 0);

    HAL_NVIC_EnableIRQ(USB_HP_CAN_TX_IRQn);

  //  HAL_NVIC_SetPriority(CAN_SCE_IRQn, 0, 0);

  HAL_NVIC_SetPriority(CAN_SCE_IRQn, 1, 0);

   

  HAL_NVIC_EnableIRQ(CAN_SCE_IRQn);

    HAL_NVIC_SetPriority(USB_LP_CAN_RX0_IRQn, 0, 0);

    HAL_NVIC_EnableIRQ(USB_LP_CAN_RX0_IRQn);

I tried changing NART to ENABLE under CAN settings and I am able to hit Transmit handler (USB_HP_CAN_TX) but I am getting ACK error under HAL_CAN_IRQHANDLER function.

Posted on December 28, 2015 at 15:19

Ok, so you'll probably want to focus on the connectivity and data rates. If you have two of your boards, try setting one up as a listener, and the other as a sender.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
akshayamk
Associate II
Posted on December 29, 2015 at 09:58

Hello Clive,

I tried to set up two boards such that one board transmits the message and the error receives the message. I downloaded the same firmware onto both boards.

However, I am still getting ACK error.

jpeacock
Associate III
Posted on December 29, 2015 at 10:26

Look at the ESR register, it will tell you the actual error.  Are you using twisted pair wiring, and do you have a 60 ohm termination resistor at each end?

akshayamk
Associate II
Posted on December 30, 2015 at 03:10

Hi peacock.jack.003,

Yes, there is a 120 ohm termination register used on both modules and they are connected using twisted pair wiring.

I have checked the ESR register and I am getting a LEC for acknowledgement error.