cancel
Showing results for 
Search instead for 
Did you mean: 

Hello! I can not send 5 identifiers (IDs).Please tell me where the error is.

iboxe
Associate II

CAN_FilterTypeDef sFilterConfig;

CAN_TxHeaderTypeDef TxHeader;

CAN_RxHeaderTypeDef RxHeader;

uint8_t TxData[8];

uint8_t RxData[8];

uint32_t TxMailbox;

/* USER CODE END PV */

/* Private function prototypes ----------Ча�?тные функции прототипов-------------------------------------*/

void SystemClock_Config(void);

static void MX_GPIO_Init(void);

static void MX_CAN_Init(void);

static void MX_WWDG_Init(void);

/* USER CODE BEGIN PFP */

/* USER CODE END PFP */

 /* USER CODE END SysInit */

 /* Initialize all configured peripherals */

 MX_GPIO_Init();

 MX_CAN_Init();

 MX_WWDG_Init();

 /* USER CODE BEGIN 2 */

 sFilterConfig.FilterBank=0;

 sFilterConfig.FilterMode=CAN_FILTERMODE_IDMASK;

 sFilterConfig.FilterScale=CAN_FILTERSCALE_32BIT;

 sFilterConfig.FilterIdHigh=0x0000;

 sFilterConfig.FilterIdLow=0x0000;

 sFilterConfig.FilterMaskIdHigh=0x0000;

 sFilterConfig.FilterMaskIdLow=0x0000;

 sFilterConfig.FilterFIFOAssignment=CAN_RX_FIFO0;

 sFilterConfig.FilterActivation=ENABLE;

 sFilterConfig.SlaveStartFilterBank=14;

 if(HAL_CAN_ConfigFilter(&hcan,&sFilterConfig)!=HAL_OK){

   /* Filter configuration Error */

   Error_Handler();

 }

 if(HAL_CAN_Start(&hcan)!=HAL_OK){

   /* Start Error */

   Error_Handler();

 }

/*активируем обработчик прерывани�?*/

 if (HAL_CAN_ActivateNotification(&hcan, CAN_IT_RX_FIFO0_MSG_PENDING) !=HAL_OK) { Error_Handler(); }

 if (HAL_CAN_ActivateNotification(&hcan, CAN_IT_ERROR) !=HAL_OK) { Error_Handler(); }

   /* Notification Error */

 TxOffHeader.StdId=0x3B3; 0x43E; 0x171; 0x22A; 0x017;

 TxOffHeader.ExtId=0x00;

 TxOffHeader.RTR=CAN_RTR_DATA;

 TxOffHeader.IDE=CAN_ID_STD;

 TxOffHeader.DLC=8;

 TxOffHeader.TransmitGlobalTime=DISABLE;

 TxData[0]=0x10, 0x00, 0x10, 0x10, 0x10, 0x10;

 TxData[1]=0x80, 0x9D, 0x80, 0x80, 0x80, 0x80;

 TxData[2]=0x74, 0x10, 0x74, 0x74, 0x74, 0x74;

 TxData[3]=0x07, 0x80, 0x07, 0x07, 0X07, 0x07;

 TxData[4]=0x0F, 0x00, 0x0F, 0x0F; 0x0F, 0x0F;

 TxData[5]=0xFF, 0x00, 0xFF, 0xFF; 0xFF, 0xFF;

 TxData[6]=0x00, 0x00, 0x00, 0x00; 0x00, 0x00;

 TxData[7]=0x00, 0x00, 0x00, 0x00; 0x00, 0x00;

 /* USER CODE END 2 */

 /* Infinite loop */

 /* USER CODE BEGIN WHILE */

 while (1)

 {

   if(TicksMs == 0){

     TicksMs = PERIOD;

     HAL_CAN_AddTxMessage(&hcan,&TxOffHeader,TxData,&TxMailbox);

     HAL_GPIO_WritePin(Led2_GPIO_Port, Led2_Pin, GPIO_PIN_SET);  //вкл �?ветодиод

   }

  /* USER CODE END WHILE */

/* USER CODE BEGIN 4 */

void HAL_CAN_TxMailbox0CompleteCallback(CAN_HandleTypeDef* hcan){

  //HAL_GPIO_TogglePin(Led1_GPIO_Port, Led1_Pin);

}

void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef* hcan){

  HAL_CAN_GetRxMessage(hcan, CAN_RX_FIFO0, &RxHeader,RxData);

  //HAL_GPIO_TogglePin(Led2_GPIO_Port, Led2_Pin);

}

/* USER CODE END 4 */

10 REPLIES 10

https://youtu.be/_SZnZeglpGM

An example of the work of the can explorer. Five messages sends.