microcontrollerpicmplabshift-register

shift register(74hc595) and pic in ccs


When I write 8 bit in hc595 shift register, with i2c last bit go to Q0 in second hc595.

Why?

Schematic:

enter image description here

My code:

i2c_write(0b10101010);

latch_led_sensors_out();

delay_ms(200);

Solution

  • It's because of the I2C protocol. Even though you want to send out 8 bits, you are really sending out 9. The way I2C works is the initial frame contains 7 (or 10) bits of address, plus one bit for read/write. After those initial 8 bits are clocked out, the master sends an additional clock pulse to read in the ACK/NACK bit from the slave device. Remember, the master controls the clock, even when the slave is driving the data pin.