/* USER CODE BEGIN 2 */
/* CAN Filter Setting */
canFilter1.FilterBank = 0;
canFilter1.FilterMode = CAN_FILTERMODE_IDMASK;
canFilter1.FilterScale = CAN_FILTERSCALE_32BIT;
canFilter1.FilterIdHigh = 0x0000;
canFilter1.FilterIdLow = 0x0000;
canFilter1.FilterMaskIdHigh = 0x0000; // 0x00000000 = 모든 ID를 받아들이겠다
canFilter1.FilterMaskIdLow = 0x0000;
canFilter1.FilterFIFOAssignment = CAN_RX_FIFO0;
canFilter1.FilterActivation = ENABLE;
canFilter1.SlaveStartFilterBank = 14;
if (HAL_CAN_ConfigFilter(&hcan1, &canFilter1) != HAL_OK)
{
/* Filter configuration Error */
Error_Handler();
}
canFilter2.FilterBank = 0;
canFilter2.FilterMode = CAN_FILTERMODE_IDMASK;
canFilter2.FilterScale = CAN_FILTERSCALE_32BIT;
canFilter2.FilterIdHigh = 0x0000;
canFilter2.FilterIdLow = 0x0000;
canFilter2.FilterMaskIdHigh = 0x0000; // 0x00000000 = 모든 ID를 받아들이겠다
canFilter2.FilterMaskIdLow = 0x0000;
canFilter2.FilterFIFOAssignment = CAN_RX_FIFO0;
canFilter2.FilterActivation = ENABLE;
canFilter2.SlaveStartFilterBank = 20; // CAN2의 FilterBank시작 위치, CAN2를 사용한다면 FilterBank를 SlaveStartFilterBank보다 크게 설정해야 함.
if (HAL_CAN_ConfigFilter(&hcan2, &canFilter2) != HAL_OK)
{
/* Filter configuration Error */
Error_Handler();
}
/* Configure Transmission process */
canTxHeader.StdId = 0x321; // Standard Identifier, 0 ~ 0x7FF
canTxHeader.ExtId = 0x01; // Extended Identifier, 0 ~ 0x1FFFFFFF
canTxHeader.RTR = CAN_RTR_DATA; // 전송하는 메세지의 프레임 타입, DATA or REMOTE
canTxHeader.IDE = CAN_ID_STD; // 전송하는 메세지의 식별자 타입, STD or EXT
canTxHeader.DLC = 8; // 송신 프레임 길이, 0 ~ 8 byte
canTxHeader.TransmitGlobalTime = DISABLE; // 프레임 전송 시작될 때 timestamp counter 값을 capture.
/* Set the data to be transmitted */
can1Tx0Data[0] = 1;
can1Tx0Data[1] = 2;
can1Tx0Data[2] = 3;
can1Tx0Data[3] = 4;
can1Tx0Data[4] = 5;
can1Tx0Data[5] = 6;
can1Tx0Data[6] = 7;
can1Tx0Data[7] = 8;
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
/* Activate CAN RX notification */
if (HAL_CAN_ActivateNotification(&hcan1, CAN_IT_RX_FIFO0_MSG_PENDING) != HAL_OK)
{
/* Notification Error */
Error_Handler();
}
if (HAL_CAN_ActivateNotification(&hcan2, CAN_IT_RX_FIFO0_MSG_PENDING) != HAL_OK)
{
/* Notification Error */
Error_Handler();
}
/* Can Start */
if (HAL_CAN_Start(&hcan1) != HAL_OK)
{
/* Start Error */
Error_Handler();
}
if (HAL_CAN_Start(&hcan2) != HAL_OK)
{
/* Start Error */
Error_Handler();
}
/* Start the Transmission process */
if (HAL_CAN_AddTxMessage(&hcan1, &canTxHeader, can1Tx0Data, &TxMailBox) != HAL_OK)
{
Error_Handler();
}
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}