Where is that task BLOCKING to wait for the signal and let the other task run.
You need to read about the basics of how tasks work. Look at how a Semaphore works for instance.
A computer only does one thing at a time, so the code needs to let the OS know it doesn’t need to be running at the moment, so it knows it can give time elsewhere.
One way to do is to use task notification. The following pseudo code tries to explain the idea -
static TaskHandle_t xADCReaderTaskHandle = NULL;
void ADCReaderTask( void * pvParams )
{
( void ) pvParams;
for( ; ; )
{
/* Wait for a notification from the ISR. The CPU will be
* free to execute other tasks till a notification is
* received. Block indefinitely (without a timeout, so no
* need to check the function's return value) to wait for a
* notification. NOTE! Real applications should not block
* indefinitely, but instead time out occasionally in order
* to handle error conditions that may prevent the interrupt
* from sending any more notifications. */
ulTaskNotifyTake( pdTRUE, /* Clear the notification value before exiting. */
portMAX_DELAY ); /* Block indefinitely. */
/* Read the ADC and process the value. */
}
}
/*-----------------------------------------------------------*/
void ADCReadyISR( void )
{
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
/* Notify the task that the ADC is ready. */
vTaskNotifyGiveFromISR( xADCReaderTaskHandle, &xHigherPriorityTaskWoken );
/* If xHigherPriorityTaskWoken is now set to pdTRUE then a context switch
* should be performed to ensure the interrupt returns directly to the highest
* priority task. The macro used for this purpose is dependent on the port in
* use and may be called portEND_SWITCHING_ISR(). */
portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
}
/*-----------------------------------------------------------*/
As you meant task notification is notified whether the interrupt is raised or not.
is that right.??
If so interrupt was raised from the callback function means so how can i notify with ISR, i didn’t get it clearly.
First, sorry for the inconvenience. I thought it’s like that i will explain what actually i am doing to read the ADC data and then how i am running two ADCs.
Using ADS1256 IC with SPI communication of port2(SPI2) and here waiting for DRDY pin to go LOW,
Using TIM2 for microsecond delay.
Once DRDY goes LOW, read the analog data and converted it into a voltage value.
Similarly for ADC2, with port4 (SPI4) and TIM3 for micro second delay.
while coming to simultaneous run, keeping both ADCs in one task like default task it’s running successfully. but in separate tasks, it’s stuck in the DRDY pin to go LOW while debugging.
so i kept ADC1 in default task with semophoreAcquire() & release and then task2 with another ADC2 without semophoreAquire(), the result was same. so now i am reading the book which you suggested try to work on ulTaskNotifyTake API.
Can you elaborate what are you trying to achieve? If you want to make sure that only one task interacts with ADC at a time, you can acquire mutex before reading it and release afterwards. Something like -
If you have two data ready interrupt, you will need two data ready semaphores, one for each, and each task waits on its semaphore Which will be given in the appropriate ISR when it detects the data ready interrupt for that channel.
Actually, i am using two sensors called differential pressure sensor and pressure sensor and need both pressure sensor values at a time, that’s why i am trying to achieve the two ADC reading simultaneously, I hope you understand.
And what triggers the ADC to start its sampling and converting? THAT is what you need to be as simultaneous as possible.
If you have an external signal triggering the conversion, if it goes into the two ADCs they will be simultaneous. (And you need two ADC to do what you want, not two channels of one chip).
If you are using a SPI triggered conversion, you will need to try to trigger the sending of the SPI command to start the conversion as close as possible with each other. The STM provided SPI driver probably doesn’t do a good job at this.
The reading of the data after it is converted isn’t critical timing, it just needs to be done before the next sample occurs, unless you have a time critical requirement between making and using the measurement.
but the thing is i need to run multiple tasks like
task1 is dedicated for ADC1
task2 is dedicated for ADC2
task3 is dedicated to RELAYS operation
task4 is dedicated to Nextion Display
task5 is dedicated to UART
task6 is dedicated to RTC
so as i said before I tried by kept both ADC1 and ADC2 in task1 it’s working and when I add the RELAYS operation some data are lost and ADC reading was stuck.
Then i planned to run both ADCs with different tasks and after that, you know the whole drama.
Sorry, didn’t get what you asking, is that like the previous call to a hard fault.??
From your previous description, it seems like you get hard fault when you run task2. Please take the complete screenshot of the IDE and share when you hard fault.