2022-05-12 01:35 AM
I'm using stm32 discovery board and connecting with as7262 sensor. The datasheet for as 7262 sensor is https://ams.com/en/as7262
I am unable to retrieve the data using I2C communication. I have uploaded my code below.
#define AS7262_ADD 0x93
#define STATUS_REG 0x00
#define WRITE_REGT 0x01
#define READ_REGT 0x02
#define TX_VALID 0x02
#define RX_VALID 0x01
while(1){
HAL_I2C_Mem_Read(&hi2c1, AS7262_ADD, STATUS_REG, 1, &status, 1, 100);
HAL_I2C_Mem_Read(&hi2c1, AS7262_ADD, TX_VALID, 1, &tx_check, 1, 100);
if((status && tx_check) == 0){
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, SET);
break;
}
}
uint8_t virtualReg = 0x08;
HAL_I2C_Mem_Write(&hi2c1, AS7262_ADD, WRITE_REGT, 1, &virtualReg, 2, 100)
while(1){
HAL_I2C_Mem_Read(&hi2c1, AS7262_ADD, STATUS_REG, 1, &status, 1, 100);
HAL_I2C_Mem_Read(&hi2c1, AS7262_ADD, RX_VALID, 1, &rx_check, 1, 100);
if((status && rx_check) != 0){
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_13, SET);
break;
}
HAL_I2C_Mem_Read(&hi2c1, AS7262_ADD, READ_REGT, 1, &data, 2, 100);
}
2022-05-12 03:16 AM
I guess you should change AS7262_ADD to 0x92
Check the return values of the HAL_I2C functions you call for more info (there are ERROR and TIMEOUT).
Does the sensor Acknowledge its address?
2022-05-12 03:32 AM
Assume you'll need to debug your own HW and SW
The address should be 0x92, ST is supposed to set the low order bit based on read/write.
Make sure the chip is jumpered for I2C operation, and that you have pull-ups on the SDA/SCL
Make sure the pins and I2C peripheral on the STM32 are properly configured.
2022-05-12 06:10 PM
I have changed the address to 0x92, but unfortunately, I did not get any data. Yes the sensor have acknowledged
2022-05-12 06:13 PM
I have changed the address to 0x92, but same result. Yes the I2C peripheral are properly configured, and the pull-up resistors are on the SCL/SDA.
2022-05-12 06:18 PM
Then you're going to want to keep reading the specifications, and reviewing what you're doing with a scope or logic analyzer.
The number of people using this part on the forum approaches zero.
Read and dump the 0x2C registers [0x00..0x2B], confirm you see the expected Chip IDs and content.
2022-05-12 08:20 PM
I think I have made a mistake in programming, I have attached the picture of pseudo code and sample code image from datasheet, can you please confirm whether my code and the sample code matches?