初级会员
- 积分
- 134
- 金钱
- 134
- 注册时间
- 2018-3-26
- 在线时间
- 286 小时
|
20金钱
请教大家一下,我用HAL配置的CAN,程序不进回调函数,这是HAL库CAN程序- void MX_CAN_Init(void)
- {
- hcan1.Instance = CAN1;
- hcan1.Init.Prescaler = 8;
- hcan1.Init.Mode = CAN_MODE_NORMAL;
- hcan1.Init.SyncJumpWidth = CAN_SJW_1TQ;
- hcan1.Init.TimeSeg1 = CAN_BS1_4TQ;
- hcan1.Init.TimeSeg2 = CAN_BS2_4TQ;
- hcan1.Init.TimeTriggeredMode = DISABLE;
- hcan1.Init.AutoBusOff = ENABLE;
- hcan1.Init.AutoWakeUp = DISABLE;
- hcan1.Init.AutoRetransmission = ENABLE;
- hcan1.Init.ReceiveFifoLocked = DISABLE;
- hcan1.Init.TransmitFifoPriority = DISABLE;
- if (HAL_CAN_Init(&hcan1) != HAL_OK)
- {
- Error_Handler();
- }
- }
复制代码- HAL_StatusTypeDef CAN_Filter_Init(CAN_HandleTypeDef *h_can)
- {
- CAN_FilterTypeDef sFilterConfig;
-
- sFilterConfig.FilterBank = 2; //chenal 0
- sFilterConfig.FilterMode = CAN_FILTERMODE_IDMASK; //????????
- sFilterConfig.FilterScale = CAN_FILTERSCALE_16BIT; //????????32?
- sFilterConfig.FilterIdHigh = 0xB000; //??????
- sFilterConfig.FilterIdLow = 0xC400; //??????
- //MASK bit 0 means don't care,bit 0 means match
- sFilterConfig.FilterMaskIdHigh = 0xFE1F; //????? //?????????????,????????????????
- sFilterConfig.FilterMaskIdLow = 0xFE1F; //?????
- sFilterConfig.FilterFIFOAssignment = CAN_FILTER_FIFO0; //FIFO0????FIFO1????????,?????????????FIFO0?
- sFilterConfig.FilterActivation = CAN_FILTER_ENABLE; //enable filter
- sFilterConfig.SlaveStartFilterBank = 0; //???can????????,????CAN??,????????
- HAL_CAN_ConfigFilter(h_can, &sFilterConfig);
- HAL_CAN_ActivateNotification(h_can, CAN_IT_RX_FIFO0_MSG_PENDING);
- return HAL_OK;
- }
复制代码- int main(void)
- {
- HAL_Init();
- SystemClock_Config();
- MX_GPIO_Init();
-
- MX_USART1_UART_Init();
- HAL_CAN_MspInit(&hcan1);
- MX_CAN_Init();
- CAN_Filter_Init(&hcan1);
复制代码- void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *h_can)
- {
- printf("111111");
- if(h_can->Instance==CAN1)
- {
- HAL_CAN_GetRxMessage(h_can, CAN_RX_FIFO0, &RxMessage, RxData) ;
- printf(" %02X, %02X, %02X, %02X, %02X, %02X, %02X, %02X\r\n",RxData[0], RxData[1], RxData[2], RxData[3],RxData[4], RxData[5], RxData[6], RxData[7]);
- }
- }
复制代码 这是HAL配置
不知道为何,就是不进去
|
|