2017-12-06 09:27 AM
Hello. I configured stm32 PB11 and PB10 as SDA and SCL pins then i connected GY-30 BH1750 light sensor.
It's address is 0x23 when ADDR pin connected to GND.
POWER_ON 0x01
RESET 0x07
BH1750_CONTINUOUS_HIGH_RES_MODE 0x10
This is function to send the data:
void WriteBuffer(uint8_t I2C_ADDRESS, uint8_t *aTxBuffer, uint8_t TXBUFFERSIZE){
failure=0; while(HAL_I2C_Master_Transmit(&hi2c2, (uint16_t)I2C_ADDRESS<<1, (uint8_t*)aTxBuffer, (uint16_t)TXBUFFERSIZE, (uint32_t)1000)!= HAL_OK) { failure =1 ; if (HAL_I2C_GetError(&hi2c2) != HAL_I2C_ERROR_AF) {Error_Handler();
} }while (HAL_I2C_GetState(&hi2c2) != HAL_I2C_STATE_READY)
{ }}uint8_t buffer[3];
buffer[0] = POWER_ON
and when i call WriteBuffer(0x23, buffer, 1), function return 1 in failure variable and data isn't sent.
I check variables in STM Studio. Where can be problem? Is this code fail or my connections between sensor and STM ?
#i2c-sensor