while (SDA_READ()==0 && clockCount>0){ should be while (SDA_READ()==0 && clockCount-->0){ i feel that clockCount should be 10 not 20 (eight bit + ack + stop)