Hi.
I'm trying to read data of MAX30102 using TWI, it has 8 bits of data in the FIFO_DATA register.
The library I'm using for data extraction and processing was written for Arduino, so changed the basic read/write and time functions according to NRF52 SDK.
So my r/w functions look like
ret_code_t I2C_register_write(uint8_t device_address, uint8_t reg_address, uint8_t data) ret_code_t I2C_register_read(uint8_t device_address, uint8_t reg_address, uint8_t *data)
Coming back to the MAX30102 library, apart from the read/write functions, there is this function:
_i2cPort->requestFrom(MAX30102_ADDRESS, toGet)
After looking at Arduino's documentation, what I understood is that it reads "toGet" number of bytes from the device.
The i2c communication was initiated a few lines ago with these:
_i2cPort->beginTransmission(MAX30105_ADDRESS); _i2cPort->write(MAX30105_FIFODATA); _i2cPort->endTransmission();
So I'm thinking that my functions should be like this:
uint8_t FIFO_data; err_code = I2C_register_read(MAX30105_ADDRESS, MAX30105_FIFODATA, &FIFO_data);
This would give me the 8 bits (or one byte) in the FIFO register.
But in the library, they are are reading bytes like this:
//Burst read three bytes - RED temp[3] = 0; temp[2] = _i2cPort->read(); temp[1] = _i2cPort->read(); temp[0] = _i2cPort->read();
Then after some if statements, they are repeating the same 4 lines to read more data from same register two more times.
//Burst read three more bytes - IR temp[3] = 0; temp[2] = _i2cPort->read(); temp[1] = _i2cPort->read(); temp[0] = _i2cPort->read(); //Burst read three more bytes - Green temp[3] = 0; temp[2] = _i2cPort->read(); temp[1] = _i2cPort->read(); temp[0] = _i2cPort->read();
I'm confused on how to implement it in my functions.
Should I just repeat my read function 4 times? Wouldn't it give me the same data?
Or should I pass the pointer to an array in my read function like this:
byte temp[4]; err_code = I2C_register_read(MAX30105_ADDRESS, MAX30105_FIFODATA, &temp); temp[3] = 0;
If the data is changing every time I read it, how do I know that the current 4 bytes I have read belong to the same group (RED or IR or GREEN)