Hello,
I have some trouble in I2C. My I2C_I2CMasterSendStart() returns I2C_I2C_MSTR_ERR_LB_NAK. According to the description of the datasheet, this constant indicates "Last byte was NAKed". I don't know how to solve this problem. Can you help me?
My I2C master is PSoC 4 BLE and slave is MAX30100(here is datasheet link, https://www.maximintegrated.com/en/products/analog/sensors-and-sensor-in...)
Here is code that I try to read temperature value:
static uint16 temp1,temp2;
static double temp = 30;
// Mode Configuration
I2C_I2CMasterSendStart(0xae,I2C_I2C_WRITE_XFER_MODE); // MAX30100 WRITE ADDRESS is 0xae
I2C_I2CMasterWriteByte(0x06); //Mode Configuration's register address is 0x06
I2C_I2CMasterWriteByte(0x0a); // the value I write
I2C_I2CMasterSendStop();
// wait a momment
CyDelay(20);
// read integer value of temperature
I2C_I2CMasterSendStart(0xae,I2C_I2C_WRITE_XFER_MODE);
I2C_I2CMasterWriteByte(0x16); //Integer Value's reg_addr is 0x16
I2C_I2CMasterSendRestart(0xaf,I2C_I2C_READ_XFER_MODE); //MAX30100 READ ADDRESS is 0xaf
temp1 = I2C_I2CMasterReadByte(I2C_I2C_NAK_DATA); // read integer value
I2C_I2CMasterSendStop();
// read fraction value of temperature
I2C_I2CMasterSendStart(0xae,I2C_I2C_WRITE_XFER_MODE);
I2C_I2CMasterWriteByte(0x17); //Fraction Value's reg_addr is 0x17
I2C_I2CMasterSendRestart(0xaf,I2C_I2C_READ_XFER_MODE);
temp2 = I2C_I2CMasterReadByte(I2C_I2C_NAK_DATA);
I2C_I2CMasterSendStop();
temp = temp1 + (temp2 / 100);
CyDelay(100);
Any guidance would be greatly appreciated! Thank you.