cancel
Showing results for 
Search instead for 
Did you mean: 

CAN 2addres to 2 massive.

RKama.4
Associate

good afternoon friends.

I am learning to work with SUN.

I want to receive parcels from 2 addresses. In principle, it works, but the values ​​from two addresses are written to one array.

How to make it so that values from different addresses are written to different arrays?

void MX_CAN_Init(void)

{

 /* USER CODE BEGIN CAN_Init 0 */

 CAN_FilterTypeDef sFilterConfig;

 CAN_FilterTypeDef sFilterConfig_pravite;

 /* USER CODE END CAN_Init 0 */

 /* USER CODE BEGIN CAN_Init 1 */

 /* USER CODE END CAN_Init 1 */

 hcan.Instance = CAN1;

 hcan.Init.Prescaler = 8;

 hcan.Init.Mode = CAN_MODE_NORMAL;

 hcan.Init.SyncJumpWidth = CAN_SJW_1TQ;

 hcan.Init.TimeSeg1 = CAN_BS1_3TQ;

 hcan.Init.TimeSeg2 = CAN_BS2_5TQ;

 hcan.Init.TimeTriggeredMode = DISABLE;

 hcan.Init.AutoBusOff = DISABLE;

 hcan.Init.AutoWakeUp = DISABLE;

 hcan.Init.AutoRetransmission = DISABLE;

 hcan.Init.ReceiveFifoLocked = ENABLE;

 hcan.Init.TransmitFifoPriority = ENABLE;

 if (HAL_CAN_Init(&hcan) != HAL_OK)

 {

  Error_Handler();

 }

 /* USER CODE BEGIN CAN_Init 2 */

 sFilterConfig.FilterBank = 0;

 sFilterConfig.FilterMode = CAN_FILTERMODE_IDLIST;

 sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;

 sFilterConfig.FilterIdLow = (uint16_t)(0x18FEEE00 << 3) | 0x04;

 sFilterConfig.FilterMaskIdHigh = (uint16_t)(0x18FEEE00 >> 13);

 sFilterConfig.FilterMaskIdLow = (uint16_t)(0x18FEEE00 << 3) | 0x04;

 sFilterConfig.FilterFIFOAssignment = CAN_RX_FIFO0;

 sFilterConfig.FilterActivation = ENABLE;

 sFilterConfig.SlaveStartFilterBank = 14;

  

 sFilterConfig_pravite = sFilterConfig;

 sFilterConfig_pravite.FilterBank = 1;

 sFilterConfig_pravite.FilterIdHigh = (uint16_t)(0x0CF00300 >> 13);

 sFilterConfig_pravite.FilterIdLow = (uint16_t)(0x0CF00300 << 3) | 0x04;

 sFilterConfig_pravite.FilterMaskIdHigh = (uint16_t)(0x0CF00300 >> 13);

 sFilterConfig_pravite.FilterMaskIdLow = (uint16_t)(0x0CF00300 << 3) | 0x04;

 sFilterConfig_pravite.FilterIdHigh = (uint16_t)(0x18FEEE00 >> 13);

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

 {

  Error_Handler();

 }

 if(HAL_CAN_ConfigFilter(&hcan, &sFilterConfig_pravite) != HAL_OK)

 {

  Error_Handler();

 }

  

 /* USER CODE END CAN_Init 2 */

}

void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan)

{

 if(HAL_CAN_GetRxMessage(hcan, CAN_RX_FIFO0, &RxHeader, RxDataa) == HAL_OK)

 {

  HAL_GPIO_TogglePin(LED_plate_GPIO_Port, LED_plate_Pin); 

 }

}

2 REPLIES 2

Perhaps starts by filling the structures properly, and directing different messages to different FIFOs.

Or as you pull the data into a holding buffer decode the address and then direct it into the appropriate queue in your implementation. ​

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

help how to do it?