This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

RTOS I2C communication fail....

Hi, I using the Keil RTOS with STM32F4 uC, I want to communicate with MPU-9250 via I2C. I build the project, I connected the two panels together but when I want to send something, I get HAL_ERROR . I did a default i2c initialisation via CubeMX. Then:

/* Private variables ---------------------------------------------------------*/
#define    MPU9250_ADDRESS            0x68
#define    MAG_ADDRESS                0x0C

#define    GYRO_FULL_SCALE_250_DPS    0x00
#define    GYRO_FULL_SCALE_500_DPS    0x08
#define    GYRO_FULL_SCALE_1000_DPS   0x10
#define    GYRO_FULL_SCALE_2000_DPS   0x18

#define    ACC_FULL_SCALE_2_G        0x00
#define    ACC_FULL_SCALE_4_G        0x08
#define    ACC_FULL_SCALE_8_G        0x10
#define    ACC_FULL_SCALE_16_G       0x18


in main:

  [some inits and other stuff...]

  // Set the device's registers (i.e. 0x19 (hex int value) register) to a value.
  HAL_I2C_Mem_Write(&hi2c1, MPU9250_ADDRESS, 0x19, 1, (uint8_t *)0x07, 1, 100);
  HAL_I2C_Mem_Write(&hi2c1, MPU9250_ADDRESS, 0x1A, 1, (uint8_t *)0x00, 1, 100);
  HAL_I2C_Mem_Write(&hi2c1, MPU9250_ADDRESS, 0x1B, 1, (uint8_t *)GYRO_FULL_SCALE_2000_DPS, 1, 100);
  HAL_I2C_Mem_Write(&hi2c1, MPU9250_ADDRESS, 0x1C, 1, (uint8_t *)ACC_FULL_SCALE_16_G, 1, 100);
  HAL_I2C_Mem_Write(&hi2c1, MPU9250_ADDRESS, 0x6B, 1, (uint8_t *)0x00, 1, 100);
  HAL_I2C_Mem_Write(&hi2c1, MPU9250_ADDRESS, 0x37, 1, (uint8_t *)0x02, 1, 100);
  HAL_I2C_Mem_Write(&hi2c1, MAG_ADDRESS, 0x0A, 1, (uint8_t *)0x01, 1, 100);

  uint8_t Buf[14];
  //Read Accelometer and Gyroscope from started a specified register (0x3B).
  HAL_I2C_Mem_Read(&hi2c1, MPU9250_ADDRESS, 0x3B, 1, Buf, 14, 100);

  [do stuf with accelo and gyro data...]

  uint8_t ST1;
  do
  {
    //Read magnet sensor ready byte.
    HAL_I2C_Mem_Read(&hi2c1, MAG_ADDRESS, 0x02, 1, &ST1, 1, 1000);
  }
  while (!(ST1&0x01));

  uint8_t Mag[7];
  //Read magnet sensor data.
  HAL_I2C_Mem_Read(&hi2c1, MAG_ADDRESS, 0x03, 1, Mag, 7, 100);

  [do stuf with magnet sensor data...]

I get HAL_ERROR at the first HAL_I2C_Mem_Write (and then at the others too). What am I doing wrong? How can I communicate with I2C? (set and read registers from a device?)