I am new as µC programmmer. having dealing with GPIO on the STM32091C-Eval, I wanted to go a step forward working with I2C Interface.enter image description here

On the board i have soldered the SB1 to configure the temperature sensor with the address: 1001001. Using STM32CubeMax, i have configure pin PB7 and PB6 as SDA and SCL with pull resistor because on the hardware, we do not have any pull up resistor.

Reading the sensor datasheet I can see two reading mode configuration. The Preset pointer locations and the pointer setting

Considering the default mode of the STLM75M2F, I choose the pointer setting configuration to directly read the temperature value. the initialisation code is as follow:

uint8_t I2C_SLAVE_ADDRESS   =   0x92; //slave address
uint8_t Temp_reg = 0x00; //Temperature register address
uint8_t RxBuf[4] = {0,0,0,0};
if(HAL_I2C_IsDeviceReady(&hi2c1,I2C_SLAVE_ADDRESS,3,1000) != HAL_OK)
      return HAL_ERROR;

when debbugging at the first time this code step into hardFault_handler. by second time it is being skipped.

HAL_I2C_Master_Transmit(&hi2c1,I2C_SLAVE_ADDRESS,&Temp_reg,1,1); //pointer to temp_reg to read the temperature value

In the while loop I implement the following code to test the functionnality:


in my Rxbuf array I am always getting the value RxBuff = {0x20'',0x00,0x00,0x00}

Could somebody explain or tell me why thos probleme are occuring? and why I am not able to read the temperature value?

I will be delighted to get any help

  • \$\begingroup\$ It seems odd that you had to modify the board to use an on-board peripheral, maybe you started from a point of misunderstanding. Try to find examples for the sensor, perhaps in the old pre-cube standard peripheral library examples. You are not checking the return value of the I2C functions so not seeing that they have failed and the data is meaningless - the cause of failure likely being missing MCU configuration, wrong address, or modification mistakes. To debug the I2C bus itself, use a scope or a $12 CY7C68013A USB-based logic analyzer with sigrok software. \$\endgroup\$ – Chris Stratton Jul 25 at 15:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.