PROC Blocking I2C

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

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?

0 Likes
1 Solution

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

View solution in original post

0 Likes
2 Replies
himam_31
Employee
Employee
50 likes received 25 likes received 10 likes received

Can you give more details about the slave. Also can you attach the project?

Thanks,

Hima

0 Likes

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

0 Likes