- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello everyone.
I am having an issue with the i2c functions when performing a read using the blocking functions. For some reason the first I2CMasterReadByte(0); is ignored and returns 0xE0.
Below is the code to read 3 bytes from the eeprom, but it actually only reads 2. First, the address that you want to read is sent, then the read operation begins. Attached is an image from the logic analyzer.
i2c_error = I2C_Master_I2CMasterSendStart(0b1010000,0);
I2C_Master_I2CMasterWriteByte(0); // address high byte
I2C_Master_I2CMasterWriteByte(3); // address low byte
i2c_error = I2C_Master_I2CMasterSendStop();
I2C_Master_I2CMasterSendStart(0b1010000,1);
byte0 = I2C_Master_I2CMasterReadByte(0);
byte1 = I2C_Master_I2CMasterReadByte(0);
byte2 = I2C_Master_I2CMasterReadByte(1);
i2c_error = I2C_Master_I2CMasterSendStop();
To actually read 3 bytes I have to add an extra I2CMasterReadByte(0), after the start function. Attached is also an image of the logic analyzer
i2c_error = I2C_Master_I2CMasterSendStart(0b1010000,0);
I2C_Master_I2CMasterWriteByte(0); // address high byte
I2C_Master_I2CMasterWriteByte(3); // address low byte
i2c_error = I2C_Master_I2CMasterSendStop();
I2C_Master_I2CMasterSendStart(0b1010000,1);
I2C_Master_I2CMasterReadByte(0);
byte0 = I2C_Master_I2CMasterReadByte(0);
byte1 = I2C_Master_I2CMasterReadByte(0);
byte2 = I2C_Master_I2CMasterReadByte(1);
i2c_error = I2C_Master_I2CMasterSendStop();
Does anyone know why this behavior is occurring?
Solved! Go to Solution.
- Labels:
-
BLE
- Tags:
- i2c
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I would suggest not to use
i2c_error = I2C_Master_I2CMasterSendStop();
I2C_Master_I2CMasterSendStart(0b1010000,1);
but
I2C_Master_I2CMasterSendRestart(0b1010000,1);
Some slaves really need that.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Can you give more details about the slave. Also can you attach the project?
Thanks,
Hima
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I would suggest not to use
i2c_error = I2C_Master_I2CMasterSendStop();
I2C_Master_I2CMasterSendStart(0b1010000,1);
but
I2C_Master_I2CMasterSendRestart(0b1010000,1);
Some slaves really need that.
Bob