cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to communicate between stm32 and as7262 sensor

RSath.1
Associate II

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

6 REPLIES 6
MFran.4
Senior

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?

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
Up vote any posts that you find helpful, it shows what's working..

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

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.

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
Up vote any posts that you find helpful, it shows what's working..

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?0693W00000NptRfQAJ.jpg