cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F446RE CAN 1Mbps

hjparkg71
Associate
Posted on August 25, 2016 at 06:53

Hi Guys,

I tested CAN1(GPIOA_11 and 12) on Nucleo-F446RE with std lib 1.7 and successfully run Tx/Rx on 500Kbps and 250kbps. but, it is strange that 1Mbps is not working.

Please review my setting below and let me know if there is something wrong.

 

 if(bRate == CAN_1Mbps) //not working

  {

  CAN_InitStructure.CAN_SJW = CAN_SJW_1tq;

  CAN_InitStructure.CAN_BS1 = CAN_BS1_1tq;

  CAN_InitStructure.CAN_BS2 = CAN_BS2_3tq;

  CAN_InitStructure.CAN_Prescaler = 9;

  }else if(bRate == CAN_500Kbps ){ //working

  CAN_InitStructure.CAN_SJW = CAN_SJW_1tq;

  CAN_InitStructure.CAN_BS1 = CAN_BS1_2tq;

  CAN_InitStructure.CAN_BS2 = CAN_BS2_3tq;

  CAN_InitStructure.CAN_Prescaler = 15;

  }else if(bRate == CAN_250Kbps ) { //working

   CAN_InitStructure.CAN_SJW = CAN_SJW_1tq;

   CAN_InitStructure.CAN_BS1 = CAN_BS1_2tq;

   CAN_InitStructure.CAN_BS2 = CAN_BS2_3tq;

   CAN_InitStructure.CAN_Prescaler = 30;

  }

here is my clock configuration..

*=============================================================================

  *                         Supported STM32F446xx devices

  *-----------------------------------------------------------------------------

  *        System Clock source                    | PLL (HSE)

  *-----------------------------------------------------------------------------

  *        SYSCLK(Hz)                             | 180000000

  *-----------------------------------------------------------------------------

  *        HCLK(Hz)                               | 180000000

  *-----------------------------------------------------------------------------

  *        AHB Prescaler                          | 1

  *-----------------------------------------------------------------------------

  *        APB1 Prescaler                         | 4

  *-----------------------------------------------------------------------------

  *        APB2 Prescaler                         | 2

  *-----------------------------------------------------------------------------

  *        HSE Frequency(Hz)                      | 8000000

  *-----------------------------------------------------------------------------

  *        PLL_M                                  | 8

  *-----------------------------------------------------------------------------

  *        PLL_N                                  | 360

  *-----------------------------------------------------------------------------

  *        PLL_P                                  | 2

  *-----------------------------------------------------------------------------

  *        PLL_Q                                  | 7

  *-----------------------------------------------------------------------------

thanks..

#f446 #can
2 REPLIES 2
Posted on August 25, 2016 at 18:46

Define the test conditions/criterion for ''not working''

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
hjparkg71
Associate
Posted on August 29, 2016 at 09:38

Hi,

I'm using ''Microchip CAN bus analyzer'' connecting to CANH,L of TJA1050 connecting to CAN1_RX/TX of F446RE.

this is my full code for CAN1 config..

void CAN_Config(CAN_BAUDRATE bRate, uint32_t TxId, uint32_t RxId)

{

  GPIO_InitTypeDef  GPIO_InitStructure;

  TxStdId = TxId;

  RxStdId = RxId;

#ifdef RX_TEST

  /* NVIC configuration */

  NVIC_Config();

#endif

  /* CAN GPIOs configuration **************************************************/

  /* Enable GPIO clock */

  RCC_AHB1PeriphClockCmd(CAN_GPIO_CLK, 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);

  /* 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 Baudrate = 1 MBps (CAN clocked at 30 MHz) */

  if(bRate == CAN_1Mbps) //not working

  {

  CAN_InitStructure.CAN_SJW = CAN_SJW_1tq;

  CAN_InitStructure.CAN_BS1 = CAN_BS1_1tq;

  CAN_InitStructure.CAN_BS2 = CAN_BS2_3tq;

  CAN_InitStructure.CAN_Prescaler = 9;

  }else if(bRate == CAN_500Kbps ){ //working

  CAN_InitStructure.CAN_SJW = CAN_SJW_1tq;

  CAN_InitStructure.CAN_BS1 = CAN_BS1_2tq;

  CAN_InitStructure.CAN_BS2 = CAN_BS2_3tq;

  CAN_InitStructure.CAN_Prescaler = 15;

  }else if(bRate == CAN_250Kbps ) { //working

   CAN_InitStructure.CAN_SJW = CAN_SJW_1tq;

   CAN_InitStructure.CAN_BS1 = CAN_BS1_2tq;

   CAN_InitStructure.CAN_BS2 = CAN_BS2_3tq;

   CAN_InitStructure.CAN_Prescaler = 30;

  }

   CAN_Init(CANx, &CAN_InitStructure);

}