//---------------------------------------------------------- // EEPROM書き込み // 引数(スレーブアドレス,アドレス,データ,バイト数) void i2c_2_write( unsigned char addr, unsigned char* data, unsigned char bytecnt) { i2c_start(); i2c_writebyte(0xD0); // SLA + W i2c_writebyte(addr); // address(high 8bits) while(bytecnt > 0){ i2c_writebyte(*data++); bytecnt--; } i2c_stop(); }
//---------------------------------------------------------- // EEPROM読み込み // 引数(スレーブアドレス,アドレス,データ,バイト数) void i2c_2_read( unsigned char addr, unsigned char* data, unsigned char bytecnt) { i2c_start(); i2c_writebyte(0xD0); // SLA + W i2c_writebyte(addr); // address(high 8bits) i2c_start(); i2c_writebyte(0xD1); // SLA + R while(bytecnt > 0){ *data++ = i2c_readbyte(bytecnt == 1); bytecnt--; } i2c_stop(); }
// // Originally, 'endTransmission' was an f(void) function. // It has been modified to take one parameter indicating // whether or not a STOP should be performed on the bus. // Calling endTransmission(false) allows a sketch to // perform a repeated start. // // WARNING: Nothing in the library keeps track of whether // the bus tenure has been properly ended with a STOP. It // is very possible to leave the bus in a hung state if // no call to endTransmission(true) is made. Some I2C // devices will behave oddly if they do not see a STOP. // uint8_t TwoWire::endTransmission(uint8_t sendStop) { int err; if (sendStop == true) { // transmit buffer (blocking) if (txBufferLength > 1) err = i2c_writebytes(i2c_fd, txBuffer, txBufferLength); else if (txBufferLength == 1) err = i2c_writebyte(i2c_fd, *txBuffer); else /* FIXME: A zero byte transmit is typically used to check for an * ACK from the slave device. I'm not sure if this is the * correct way to do this. */ err = i2c_readbyte(i2c_fd); // empty buffer txBufferLength = 0; if (err < 0) return 2; return 0; } else { /* sendStop = false * pretend we have held the bus while * actually waiting for the next operation */ // i2c_add_to_buf(txAddress, 0, txBuffer, txBufferLength); // i2c_transfer = 1; return 0; } }
void i2c_writebuffer (uint8 BusNR, uint8* buf, uint8 size) { uint8 cnt; for (cnt = 0; cnt < size; cnt++) { i2c_writebyte(BusNR, buf[cnt]); } }