Suspending a thread also blocks I2C

Hello,

I have a thread that is reading sensor data over I2C. When I suspend it I cant access I2C from another thread that's reading another I2C device. 

I tried isolating the I2C read function with mutex so only one device can access it at a time and when thread goes to sleep to release the mutex but it did not help.

Any ideas why?

Regards, 

Parents
  • Hello,

    Can you please share some snippets showing the issue? Or perhaps an application that I can build and run on a DK to replicate the issue?

    Are you finished reading the I2C before going to sleep? Or were you interrupted by another thread?

    Best regards,

    Edvin

  • code is part of huge project. 

    I have two I2C devices connected. 

    One is Accelerometar

      const struct i2c_dt_spec spec = {
        .bus  = dev_I2C,
        .addr = 0x6A
      };
    other is RTC
    const struct i2c_dt_spec spec_rtc = {
       .bus  = dev_I2C,
       .addr = 0x68
    };
    Accelerometar is beeing read in its thread by calling 
    static inline int readSensorData(int16_t* acceleration, int16_t* angular_rate) {
      // unsigned int key;
    
      // k_mutex_lock(&i2c_access_mutex, K_FOREVER);
      // key = irq_lock();
    
      int err = lsm6dso_acceleration_raw_get(gdev, acceleration);
      if (err) {
        printf("Error reading acceleration: %d\n", err);
        return err;
      }
    
      err = lsm6dso_angular_rate_raw_get(gdev, angular_rate);
      if (err) {
        printf("Error reading gyroscope: %d\n", err);
        return err;
      }
    
      // irq_unlock(key);
      // k_mutex_unlock(&i2c_access_mutex);
      return 0;
    }
    

    without success. When I suspent that thread and try to read RTC the entire device hangs without any errors. 
  • IvanR said:
    without success.

    What does that mean? Does readSensorData() return anything other than 0?

    IvanR said:
    When I suspent that thread and try to read RTC the entire device hangs without any errors

    Where does it hang? Do you have any other threads? Are they still running?

    From where are you calling readSensorData? From main()? From an interrupt (timer, perhaps)?

    Best regards,

    Edvin

Reply
  • IvanR said:
    without success.

    What does that mean? Does readSensorData() return anything other than 0?

    IvanR said:
    When I suspent that thread and try to read RTC the entire device hangs without any errors

    Where does it hang? Do you have any other threads? Are they still running?

    From where are you calling readSensorData? From main()? From an interrupt (timer, perhaps)?

    Best regards,

    Edvin

Children
Related