Skip to main content
RSath.1
Associate II
May 12, 2022
Question

Unable to communicate between stm32 and as7262 sensor

  • May 12, 2022
  • 6 replies
  • 3463 views

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);
 }

This topic has been closed for replies.

6 replies

MFran.4
Senior
May 12, 2022

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?

RSath.1
RSath.1Author
Associate II
May 13, 2022

I have changed the address to 0x92, but unfortunately, I did not get any data. Yes the sensor have acknowledged

Tesla DeLorean
Guru
May 13, 2022

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.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
Tesla DeLorean
Guru
May 12, 2022

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.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
RSath.1
RSath.1Author
Associate II
May 13, 2022

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.