2021-12-10 01:21 AM
Hello everybody,
I would need to use the HAL_I2C_Master_Transmit function in an ISR, in particular I would like to use it in the HAL_ADC_ConvCpltCallback function.
I have seen that the HAL_I2C_Master_Transmit function calls HAL_GetTick() so I set the interrupt priority of Tima Base: Syste tick timer to a higher priority than all the others interrupts, but the HAL_ADC_ConvCpltCallback function stops when HAL_I2C_Master_Transmit is called.
Can anyone help me?
This is my NVIC configuration:
2021-12-10 02:13 AM
Calling a blocking HAL function from an ISR is in most cases not a good idea. Whats usually is done is delayed sending from the main loop where the ISR sets only some flag and saves the data, the main loop reads that data, sends it and clears that flag. In more complicated cases, a RTOS task maybe handy for that. You could also try sending the data with a non-blocking HAL function (_IT or _DMA).
PS: If you insist in the blocking function, explain what "function stops" means and investigate the tick values with a debugger etc..
hth
KnarfB
2021-12-10 02:29 AM
I tried to do the same test with a simple HAL_Delay () in the ISR routine. And it stops when the function HAL_GetTick() is called.
I've seen dozens of posts asking for the same issue, but they all say that just apply a higher priority to the SysTick interrupt to solve, I don't understand why it doesn't work in my case.
2021-12-10 02:43 AM
How is the ADC triggered, could it be an ADC error? A little more code might help.
2021-12-10 07:27 AM
yes, ADC is triggered by TIM2.
Attach my entire main.c file, but the only add to the file generate from CubeMX is:
HAL_ADC_Start_DMA(&hadc1, (uint32_t*) ADC_Buffer, ADC_CHANNEL_NUMBER);
HAL_TIM_Base_Start(&htim2); // Start ADC timer
Before the main loop, and this ADC ISR:
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc) {
uint8_t buffer[4] = {0x00};
HAL_I2C_Master_Receive(&hi2c1, 0xF4, buffer, 4, 0xFFF);
}
@KnarfB If useful i can upload the entire project.
2021-12-10 05:32 PM
> I've seen dozens of posts asking for the same issue, but they all say that just apply a higher priority to the SysTick interrupt to solve
As you see, at least half of advises is "just do not do blocking calls in ISRs". Delay to the main loop or a task.