AnsweredAssumed Answered

STM32F767NI CAN RECEIVER PROBLEM

Question asked by Suat Berkant Gulen on Oct 9, 2017
Latest reply on Oct 9, 2017 by Suat Berkant Gulen

I generate Can code from Cube MX. But i can't receive any data. i just want to receive data on CAN Receiver of STM32F767NI.

 

I try to communicate via PCAN View. When i send data from PCAN-View the program said "Bus-Off". And receive interrupt never triggered.

 

APB1 periph clocks : 54Mhz

 

My configurations is here:

 

# Main Function

int main(void)
{
   HAL_Init();


   SystemClock_Config();


   MX_GPIO_Init();
   MX_ADC2_Init();
   MX_ADC3_Init();
   MX_CAN1_Init();
   MX_CRC_Init();
   MX_I2C2_Init();
   MX_SDMMC1_SD_Init();
   MX_SPI1_Init();
   MX_TIM5_Init();
   MX_TIM12_Init();
   MX_UART4_Init();
   MX_USART1_UART_Init();
   MX_USART2_UART_Init();
   MX_USART3_UART_Init();
   MX_USART6_UART_Init();
   MX_FATFS_Init();
   MX_LWIP_Init();
   MX_USB_DEVICE_Init();


   if (HAL_CAN_Receive_IT(&hcan1, CAN_FIFO0) != HAL_OK)
   {
      /* Reception Error */
      Error_Handler();
   }

  while (1);

}

 

# CAN Init Function

static void MX_CAN1_Init(void)
{
   static CanTxMsgTypeDef TxMessage;
   static CanRxMsgTypeDef RxMessage;


   hcan1.Instance = CAN1;
   hcan1.pTxMsg = &TxMessage;
   hcan1.pRxMsg = &RxMessage;

   hcan1.Init.TTCM = DISABLE;
   hcan1.Init.ABOM = ENABLE;
   hcan1.Init.AWUM = DISABLE;
   hcan1.Init.NART = DISABLE;
   hcan1.Init.RFLM = DISABLE;
   hcan1.Init.TXFP = DISABLE;
   hcan1.Init.Mode = CAN_MODE_NORMAL;
   hcan1.Init.SJW = CAN_SJW_1TQ;
   hcan1.Init.BS1 = CAN_BS1_6TQ;
   hcan1.Init.BS2 = CAN_BS2_7TQ;
   hcan1.Init.Prescaler = 4;

   if (HAL_CAN_Init(&hcan1) != HAL_OK)
   {
      /* Initialization Error */
      Error_Handler();
   }

}

 

# MSP Init Functions

void HAL_CAN_MspInit(CAN_HandleTypeDef* hcan)
{

   GPIO_InitTypeDef GPIO_InitStruct;
   f(hcan->Instance==CAN1)
   {

      __HAL_RCC_CAN1_CLK_ENABLE();


   GPIO_InitStruct.Pin = GPIO_PIN_12|GPIO_PIN_11;
   GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
   GPIO_InitStruct.Pull = GPIO_NOPULL;
   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
   GPIO_InitStruct.Alternate = GPIO_AF9_CAN1;
   HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);


   HAL_NVIC_SetPriority(CAN1_RX0_IRQn, 0, 0);
   HAL_NVIC_EnableIRQ(CAN1_RX0_IRQn);
   HAL_NVIC_SetPriority(CAN1_RX1_IRQn, 0, 0);
   HAL_NVIC_EnableIRQ(CAN1_RX1_IRQn);
   }

}

 

void HAL_CAN_MspDeInit(CAN_HandleTypeDef* hcan)
{

if(hcan->Instance==CAN1)
{


   __HAL_RCC_CAN1_CLK_DISABLE();

 

   HAL_GPIO_DeInit(GPIOA, GPIO_PIN_12|GPIO_PIN_11);

   
   HAL_NVIC_DisableIRQ(CAN1_RX0_IRQn);
   HAL_NVIC_DisableIRQ(CAN1_RX1_IRQn);   

   }

}

Outcomes