cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 4 MCU

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
Reply
1 Solution
Esteemed Contributor II

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
Reply
2 Replies
Employee

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

Thanks,

Hima

0 Likes
Reply
Esteemed Contributor II

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
Reply