Hello,
I have an AMS AS7261 light sensor that I'm using with my NRF51422 DK to take a light reading, pull it using nrf_drv_twi_tx/rx, and send it over BLE. However, when I try to read from the virtual registers of interest, nearly each of the registers return 0. Below is my function:
void read_sensor(uint16_t values[], const uint8_t registers[]) { uint8_t reg_addr = registers[0]; //first virtual register to read uint8_t end_reg = registers[1]; uint8_t buf; ret_code_t status; uint16_t value; int counter = 0; while (reg_addr < end_reg) { value = 0; //Read higher byte buf = 0; while(true){ status = nrf_drv_twi_tx(&m_twi, AS72XX_ADDR, ®_addr, sizeof(reg_addr), true); if (status == NRF_SUCCESS) break; } while(true) { status = nrf_drv_twi_rx(&m_twi, AS72XX_ADDR, &buf, sizeof(buf)); if (status == NRF_SUCCESS) break; } printf("Value at register %#x: %#x\r\n", reg_addr, buf); value = (buf<<8); //record higher byte reg_addr++; //Read lower byte buf = 0; while(true){ status = nrf_drv_twi_tx(&m_twi, AS72XX_ADDR, ®_addr, sizeof(reg_addr), true); if (status == NRF_SUCCESS) break; } while(true) { status = nrf_drv_twi_rx(&m_twi, AS72XX_ADDR, &buf, sizeof(buf)); if (status == NRF_SUCCESS) break; } printf("Value at register %#x: %#x\r\n", reg_addr, buf); value += buf; //record lower byte reg_addr++; values[counter] = value; //store raw value in array counter++; } }
I want to read each of the raw data registers, which according to the datasheet are registers 0x08 to 0x13:
The only registers that return a value other than 0 are the last 4, but the values I get are also wrong (in that they do not match up with the values shown in the provided GUI to read these values).
At this point I suspect this may be more of an issue with the sensor or how I'm reading it, but if it is an issue with my code any help is appreciated!
Thank you.