cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F100: Problem reading sensor via I²C

pascal23
Associate
Posted on July 29, 2015 at 13:47

Hello,

I am new to STM 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:


/** * @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 */


// 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)


if
(HAL_I2C_Mem_Read_IT(&hi2c2, 0x90, 0x00, 8, (int8_t *)TemperatureBuffer, 2) != HAL_OK)

{

Error_Handler();

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''
);
3.
}

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. #stm32f100-i2c
3 REPLIES 3
pascal23
Associate
Posted on July 30, 2015 at 16:07

Hi again,

I almost got it to work. Now I can read the temperature register [HIGH], but the [LOW] value always reads 0x80 (meaning 0.5 ). The same effect occurs when I try to read the TOS or THYS registers of LM My code is:


/* USER CODE BEGIN PV */

/* Private variables ---------------------------------------------------------*/

__IO int8_t SensorData[2];


[...]


if
(HAL_I2C_Mem_Read_IT(&hi2c2, 0x90, 0x00, 0x08, (uint8_t*)SensorData, 2) != HAL_OK)

{

HAL_GPIO_WritePin(GPIOF, GPIO_PIN_7, GPIO_PIN_SET);

}


[...]


/* USER CODE BEGIN 4 */

void
HAL_I2C_MemRxCpltCallback(I2C_HandleTypeDef *hi2c)

{

//if (SensorData[1] <0) SensorData[1] = 5;

printf
(
''%x %x''
, SensorData[0], (uint8_t) SensorData[1]);


}

Do you have any ideas?
Posted on September 17, 2017 at 04:43

Well I have actually gotten to read the temp register but I can't read the other registers config, thyst and tos.

Your call to HAL_I2C_Mem_Read_IT is almost correct

correct one is

HAL_I2C_Mem_Read_IT(&hi2c2, 0x90, 0x00, 0x01, (uint8_t*)SensorData, 2)

Posted on September 17, 2017 at 08:57

Hello !

Also your I2C2 DMA settings transfers only a BYTE. to memory (the last)

0690X00000608GfQAI.png

Check the increment address box to transfer to ''

SensorData'' all bytes requested.