cancel
Showing results for 
Search instead for 
Did you mean: 

Hi i am using stm32f746zg nucleo board and i want to establish communication between two CAN modules where CAN1 should transmit and CAN2 should receive the msg but its not happening dont know why ..can anyone help me with the code ..?

B Vinod
Associate II

here is my code

void can(void)

{

   CAN_TxHeaderTypeDef TxHeader;

   uint32_t TxMailbox;

   uint8_t usr_msg[10]={'h','e','l','l','o'};

      TxHeader.DLC=2;

      TxHeader.RTR= CAN_RTR_DATA ;

      TxHeader.IDE= CAN_ID_STD;

      TxHeader.StdId= 0x65;

   if(HAL_CAN_AddTxMessage(&hcan1,&TxHeader,usr_msg,&TxMailbox)!=HAL_OK)

   {

            Error_Handler();

   }

   while(HAL_CAN_IsTxMessagePending(&hcan1,TxMailbox));

   HAL_GPIO_WritePin(GPIOB, LD1_Pin, GPIO_PIN_SET);

}

void RX(void)

{

   CAN_RxHeaderTypeDef RxHeader;

   uint8_t rcv_msg[10];

   while(HAL_CAN_GetRxFifoFillLevel(&hcan2,CAN_RX_FIFO0));

   if(HAL_CAN_GetRxMessage(&hcan2,CAN_RX_FIFO0,&RxHeader,rcv_msg)!=HAL_OK)

   {

      Error_Handler();

   }

   HAL_GPIO_WritePin(GPIOB, LD2_Pin, GPIO_PIN_SET);

}

14 REPLIES 14

   if(HAL_CAN_GetRxMessage(&hcan2,CAN_RX_FIFO0,&RxHeader,rcv_msg)!=HAL_OK)

   {

      HAL_CAN_GetError(&hcan2);

   }

HAL_CAN_GetError returns an error code. Look it up in the stm32f4xx_hal.h source file and analyze yourself.

sir message not entering into CAN_RX_FIFO0

sir problem has not resolved till now .any help from you it could be very helpful....:)

No more ideas, sorry. Have you checked at the electrical level what's going on on the bus?