cancel
Showing results for 
Search instead for 
Did you mean: 

integrate X-CUBE-53L1A1 SimpleRangingExamples in multi i2c thread

Professional
Senior

Hello

i tried to integrate SimpleRangingExamples of  X-CUBE-53L1A1 in a multi-thread FreeRTOS environement (4 threads also access the I2C)

The SimpleRangingExamples of X-CUBE-53L1A1 running alone in a thread is OK. I want to add this thread to the 4 other thread accessing the I2C.

I have protected the i2c with semaphore : the 4 threads share well the I2C.

to add the SimpleRangingExamples in a new thread , i have the following definitions :

define VL53L1_GetI2cBus(...) CO_Mutex_get() osMutexWait(i2c_mutex_id, osWaitForever)

define VL53L1_PutI2cBus(...) CO_Mutex_put() //(void)0 //CTT osMutexRelease(i2c_mutex_id)

the thread is the following :

void PY_TASK(void const * argument)

{

   int status;

   Dev->I2cHandle = &hi2c1;

   Dev->I2cDevAddr = 0x52;

//CO_Mutex_get();

 status = VL53L1_WaitDeviceBooted(Dev);

 status = VL53L1_DataInit(Dev);

 status = VL53L1_StaticInit(Dev);

 status = VL53L1_SetDistanceMode(Dev, VL53L1_DISTANCEMODE_LONG);

 status = VL53L1_SetMeasurementTimingBudgetMicroSeconds(Dev, 50000);

 status = VL53L1_SetInterMeasurementPeriodMilliSeconds(Dev, 500);

 status = VL53L1_StartMeasurement(Dev);

   if(status){

      snprintf(dataOut, DATA_SIZE, "PY =VL53L1_StartMeasurement failed\r\n" );

      HAL_UART_Transmit(&huart2, (uint8_t*)dataOut, strlen(dataOut), 0xFFFF);

   }

   else

   {

      snprintf(dataOut, DATA_SIZE, "PY =VL53L1_StartMeasurement OK\r\n" );

      HAL_UART_Transmit(&huart2, (uint8_t*)dataOut, strlen(dataOut), 0xFFFF);

   }

   do // interrupt mode

   {

   //__WFI();

   if(MA_IntCount !=0 ){

      MA_IntCount=0;

      

         status = VL53L1_GetRangingMeasurementData(Dev, &RangingData);

        

         if(status==0)

         {

            snprintf(dataOut, DATA_SIZE, "PY =%d\r\n", RangingData.RangeMilliMeter );

            //snprintf(dataOut, DATA_SIZE, "PY =\r\n" );

            HAL_UART_Transmit(&huart2, (uint8_t*)dataOut, strlen(dataOut), 0xFFFF);

         }

        

         status = VL53L1_ClearInterruptAndStartMeasurement(Dev);

       

      }

   }

   while(1);

;

}

the programm hangs weither in hard failure or in RTOS functions...

Do you know how to integrate this example in a multi thread environement ?

thanks for any help

regards

0 REPLIES 0