int write_data(int addr, unsigned char data) { int i, write_ctl_byte = 0xA0; if(addr > 255) { write_ctl_byte = write_ctl_byte | 2; addr = addr - 256; } start(); if(send_byte(write_ctl_byte)) { printf("write_data: device did'nt ack write control byte...\n"); stop(); return -1; } if(send_byte(addr)) { printf("write_data: device did'nt ack write addr byte...\n"); stop(); return -1; } if(send_byte(data)) { printf("write_data: device did'nt ack data byte...\n"); stop(); return -1; } // write begins after a stop stop(); // start ACK polling for(i = 0; i < ACK_POLLING_COUNT; i++) { start(); if (!send_byte(write_ctl_byte)) { // Got an ACK stop(); return 0; } } printf("write_data: device didn't ACK write completion...\n"); stop(); return -1; }