首先是CAN过滤器的配置函数,
/***********************CAN通信发送函数***************************/
void CAN_TxMessage(CAN_HandleTypeDef *hcan, CAN_TxHeaderTypeDef * pTxHeader, uint8_t aData[], uint8_t DLC)
{
uint32_t Tx_MailBox;
pTxHeader->DLC = DLC;
while(HAL_CAN_AddTxMessage(hcan, pTxHeader, aData, &Tx_MailBox) != HAL_OK)
{
printf("TxMsg Failed!!");
HAL_Delay(100);
}
printf("\nSend Tx Message Success!!Tx_Mail:%d", Tx_MailBox);
}
void User_CAN1_TxMessage(uint8_t aTxData[], uint8_t DLC)
{
CAN_TxMessage(&hcan, &hCAN1_TxHeader, aTxData, DLC);
}
/*********************** CAN启动测试函数****************************/
void CAN_Configuration(CAN_TxHeaderTypeDef * pTxHeader,
CAN_FilterTypeDef * pFilter,
uint32_t StdId,
uint32_t ExtId,
uint32_t IDE,
uint32_t RTR,
uint32_t DLC,
uint32_t IdHigh,
uint32_t IdLow,
uint32_t MaskIdHigh,
uint32_t MaskIdLow,
uint32_t FIFOAssignment,
uint32_t Bank,
uint32_t Mode,
uint32_t Scale,
uint32_t Activation,
uint32_t SlaveStartFilterBank)
{
CAN_TxHeader_Init(pTxHeader, StdId, ExtId, IDE, RTR, DLC);
CAN_Filter_Init(pFilter, IdHigh, IdLow, MaskIdHigh, MaskIdLow, FIFOAssignment, Bank, Mode, Scale, Activation, SlaveStartFilterBank);
HAL_CAN_ConfigFilter(&hcan, pFilter);
while(HAL_CAN_Start(&hcan) != HAL_OK )
{
printf("\nCAN_Start Failed!!");
HAL_Delay(100);
}
printf("\nCAN_Start Success!!");
HAL_CAN_ActivateNotification(&hcan, CAN_IT_RX_FIFO0_MSG_PENDING);
}
|