Showing results for 
Search instead for 
Did you mean: 

PSoC 5, 3 & 1 MCU

Not applicable

I spent better part of 4 hours trying to figure out why I couldn't communicate with my OLED lcd.  Worked fine on atmel, could see it under BusPirate but with a basic setup on the POSC it kept getting NACK's and freezing on MasterSendStop.  THEN I found out it was sending the wrong address?

I finally came across this line here:

I2C_1_DATA_REG = (uint8) (slaveAddress << I2C_1_SLAVE_ADDR_SHIFT);

Why is it shifting left the address?  I went ahead and change my address to shift left first and now everything is peachy.  Could there be an option in the component to turn this off and just check if the address is even?

PS - For the record I know the LSB is the read/write bit, but  I have yet to come across a device that is pre sifted liike that.

1 Reply
Honored Contributor II

There are two ways of stating an I2C address: with or without the R/W bit. The former is 8 bit, the latter is 7 bit long. You need to look up the data sheets of both the I2C device you are using, and the I2C library, which format they want to use.

In the code above, slaveAddress is a 7-bit-address, whereas the library / MCU wants a 8-bit-adress, so the address is moved one bit to the left.

Since the (UDB) I2C master in the PSoC want to use a 7-bit-address, you don't need the bitshift.