Interfacing Multiple ultrasonic sensors with Tiva C Launch pad

I’m trying to interface 6 ultrasoinc sesnors with Tiva C launch pad using FreeRTOS this code is working for only onw sensor but I have some problems when I add more than one I get wrong readings and sometimes when connecting 2 sensors they return the same value ~~~

include “FreeRTOS.h”

include “task.h”

include “UART.h”

include “Ultrasoinc_2.h”

unsigned long Reading1=0; TaskHandlet UltrasonicReadingHandle=NULL; TaskHandlet UtrasoincInterruptHandle=NULL; // Task to send Trigger Every 20 ms void UltrasonicTrigger( void * pvParameters ) { TickTypet xLastWakeTime; while(1) { // Enable interrupt on PB0 pin connected to ultrasonic Echo GPIOPORTBIM_R|=(1<<0);
    // Makes trigger pin high for 10 us then low to send trigger to ultrasonic
    xLastWakeTime = xTaskGetTickCount();
} // Task Resumed from External interrupt at Port B /* At first Echo Flag is low , get the time of rising edge on PB0 , the next time to enter the task echo flag is high , * get time of falling edge and calculate the difference to get the distance measured / void Ultrasoinc_Interrupt_B( void * pvParameters ) { TickType_t Start; for( ;; ) { taskENTER_CRITICAL(); if (!Echo) { // Get rising Edge time Start=xTaskGetTickCount(); Echo=1; } else { Echo=0; // Difference between rising and falling edges pulse = (unsigned long)((xTaskGetTickCount()-Start)170/100); Delayus(100); Reading1=pulse; } taskEXITCRITICAL(); vTaskSuspend(NULL); } } int main(void) { xTaskCreate(UltrasoincInterruptB,”UtrasoincInterrupt”,150,NULL,1,&UtrasoincInterruptHandle); xTaskCreate(UltrasonicTrigger,”UltrasonicReading”,150,NULL,2,&UltrasonicReadingHandle); // Enable system clock SYSCTLRCGCGPIOR|=(1<<0); SYSCTLRCGCGPIOR|=(1<<1); SYSCTLRCGCGPIOR|=(1<<4); // Initialize UART UART0Init(9600,16000000); // Make Trigger pin output and Echo pin input and enable interrupts in echo pin ConfigureEcho(); ConfigureTrigger(); // NVIC register EnableUltrasioncInterrupts(); vTaskStartScheduler();

} // External interrupt ISR void UltrasonicPortBInterrupt() { // Clear Flag GPIOPORTBICRR|= (1<<0); // Resume handling Task BaseTypet check; check = xTaskResumeFromISR(UtrasoincInterruptHandle); portYIELDFROM_ISR(check); } ~~~ I don’t know how to read more than one sensor, as the task handling the interrupt is resumed from ISR so each sensor gives an interrupt enters the same task and I can’t determine the echo is comming from which sensor. Is it better to have separate tasks to send trigger for each sensor? Thanks

Interfacing Multiple ultrasonic sensors with Tiva C Launch pad

I´d propose to use TaskNotification signalled by the ISR(s) to wake-up the sensor handling task waiting resp. blocking on its TaskNotification handle. Simple, lean and the fastest way to manage ISR/task communcation. Better don´t use suspend/resume for signalling events.