AnsweredAssumed Answered

STM32 I2C HAL read out data from HMC5883L

Question asked by Stefan Meyre on Apr 6, 2015
Latest reply on Apr 7, 2015 by Stefan Meyre
Hi all,
this sounds so simple but I did spend too many hours trying to just read data out from my  HMC5883L 3-axis Magnetometer. I admitt I just switched from 8bit to the 32bit world, so bare with me... The "new" HAL drivers lack a bit of description and exsamples on the web so I ask you for help. Here the code; Cube MX generated on a 32F303 discovery board.

/* I2C2 init function */
void MX_I2C2_Init(void)

  hi2c2.Instance = I2C2;
  hi2c2.Init.Timing = 0x00201D2D;
  hi2c2.Init.OwnAddress1 = 0;
  hi2c2.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
  hi2c2.Init.DualAddressMode = I2C_DUALADDRESS_DISABLED;
  hi2c2.Init.OwnAddress2 = 0;
  hi2c2.Init.OwnAddress2Masks = I2C_OA2_NOMASK;
  hi2c2.Init.GeneralCallMode = I2C_GENERALCALL_DISABLED;
  hi2c2.Init.NoStretchMode = I2C_NOSTRETCH_DISABLED;

    /**Configure Analogue filter
  HAL_I2CEx_AnalogFilter_Config(&hi2c2, I2C_ANALOGFILTER_DISABLED);


#define HMC5883L_MASTER_ADDR   0x13


   X_axis = make_word(readHMC5883LBuffer[0],readHMC5883LBuffer[1]);
  Z_axis = make_word(readHMC5883LBuffer[2],readHMC5883LBuffer[3]);
  Y_axis = make_word(readHMC5883LBuffer[4],readHMC5883LBuffer[5]);

The SCL pin goes low a few cycles and then time out gets called...

Thanks for some suggestions!