AnsweredAssumed Answered

STM32F100: Problem reading sensor via I²C

Question asked by guenther.pascal on Jul 29, 2015
Latest reply on Sep 17, 2017 by Dimitris Paraskevopoulos

I am new to STM32. I started with the STM32100E-Eval Board which features an STM32F100Z3 MPU and a STLM75 temperature sensor, which connects to the MCU via I²C2.

Using STM32CubeMX, I set up the hardware end enable I2C2 and corresponding I2C2 event interrupt. Now, I try to read the temperature value in no-blocking mode. Unfortuately, I haven't found any application notes or example applications using the HAL no-blocking mode yet. I've tried the following code:
01./**  * @brief  Read an amount of data in no-blocking mode with Interrupt from a specific memory address
* @param  hi2c : Pointer to a I2C_HandleTypeDef structure that contains
                 the configuration information for the specified I2C.
  * @param  DevAddress: Target device address
  * @param  MemAddress: Internal memory address
  * @param  MemAddSize: Size of internal memory address
  * @param  pData: Pointer to data buffer
  * @param  Size: Amount of data to be sent
  * @retval HAL status  */
03.// HAL_StatusTypeDef HAL_I2C_Mem_Read_IT(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size)
05.if(HAL_I2C_Mem_Read_IT(&hi2c2, 0x90, 0x00, 8, (int8_t *)TemperatureBuffer, 2) != HAL_OK)
07.    Error_Handler();
08.    printf("ErrorTEMP");
My first question is: What is the correct value for MemAdressSize? Bits or Bytes?

I guess, this code should trigger an interrupt, but the following printf never gets executed:
1.void HAL_I2C_MemRxCpltCallback ( I2C_HandleTypeDef *hi2c) {
2.    printf("temp");
Is this reading process correct or am I wrong?

If I also enable the I2C2 error interrupt using CubeMX, my program crashes, that means my other tasks (I'm using FreeRTOS) stop.

Thanks in advance.