#c #embedded #stm32 #stm32f1
Вопрос:
Я пишу код для stm32f103. Я хочу прочитать CAN-BUS, но прерывания не сработали. Я могу писать, но не умею читать!!!
Вот код для записи и чтения.
Определения :
CAN_FilterTypeDef canfil; //CAN Bus Filter
uint32_t canMailbox; //CAN Bus Mail box variable
canfil.FilterBank = 0;
canfil.FilterMode = CAN_FILTERMODE_IDMASK;
canfil.FilterFIFOAssignment = CAN_RX_FIFO0;
canfil.FilterIdHigh = 0;
canfil.FilterIdLow = 0;
canfil.FilterMaskIdHigh = 0;
canfil.FilterMaskIdLow = 0;
canfil.FilterScale = CAN_FILTERSCALE_32BIT;
canfil.FilterActivation = ENABLE;
canfil.SlaveStartFilterBank = 14;
txHeader.DLC = 8; // Number of bites to be transmitted max- 8
txHeader.IDE = CAN_ID_STD;
txHeader.RTR = CAN_RTR_DATA;
txHeader.StdId = 0x030;
txHeader.ExtId = 0x02;
txHeader.TransmitGlobalTime = DISABLE;
HAL_CAN_ConfigFilter(amp;hcan,amp;canfil); //Initialize CAN Filter
HAL_CAN_Start(amp;hcan); //Initialize CAN Bus
HAL_CAN_ActivateNotification(amp;hcan,CAN_IT_RX_FIFO0_MSG_PENDING);// Initialize CAN Bus
//Rx Interrupt
hcan Init :
hcan.Instance = CAN1;
hcan.Init.Prescaler = 8;
hcan.Init.Mode = CAN_MODE_NORMAL;
hcan.Init.SyncJumpWidth = CAN_SJW_1TQ;
hcan.Init.TimeSeg1 = CAN_BS1_6TQ;
hcan.Init.TimeSeg2 = CAN_BS2_1TQ;
hcan.Init.TimeTriggeredMode = DISABLE;
hcan.Init.AutoBusOff = ENABLE;
hcan.Init.AutoWakeUp = ENABLE;
hcan.Init.AutoRetransmission = DISABLE;
hcan.Init.ReceiveFifoLocked = DISABLE;
hcan.Init.TransmitFifoPriority = DISABLE;
if (HAL_CAN_Init(amp;hcan) != HAL_OK)
{
Error_Handler();
}
Написание кода:
uint8_t csend[] = {'a','b','c','d'}; // Tx Buffer
if (HAL_CAN_AddTxMessage(amp;hcan,amp;txHeader,csend,amp;canMailbox)!= HAL_OK)
{
Error_Handler ();
}
Считывание Кода Прерывания:
void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan)
{
if (HAL_CAN_GetRxMessage(hcan, CAN_RX_FIFO0, amp;rxHeader, canRX) != HAL_OK)
{
Error_Handler();
}
}
Where is my mistake ?