MCPcopy Create free account
hub / github.com/SmingHub/Sming / beginTransmission

Method beginTransmission

Sming/Libraries/I2Cdev/I2Cdev.cpp:748–766  ·  view source on GitHub ↗

added by Jeff Rowberg 2013-05-07: Arduino Wire-style "beginTransmission" function (takes 7-bit device address like the Wire method, NOT 8-bit: 0x68, not 0xD0/0xD1)

Source from the content-addressed store, hash-verified

746 // Arduino Wire-style "beginTransmission" function
747 // (takes 7-bit device address like the Wire method, NOT 8-bit: 0x68, not 0xD0/0xD1)
748 byte Fastwire::beginTransmission(byte device) {
749 byte twst, retry;
750 retry = 2;
751 do {
752 TWCR = (1 << TWINT) | (1 << TWEN) | (1 << TWSTO) | (1 << TWSTA);
753 if (!waitInt()) return 1;
754 twst = TWSR & 0xF8;
755 if (twst != TW_START && twst != TW_REP_START) return 2;
756
757 //Serial.print(device, HEX);
758 //Serial.print(" ");
759 TWDR = device << 1; // send device address without read bit (1)
760 TWCR = (1 << TWINT) | (1 << TWEN);
761 if (!waitInt()) return 3;
762 twst = TWSR & 0xF8;
763 } while (twst == TW_MT_SLA_NACK && retry-- > 0);
764 if (twst != TW_MT_SLA_ACK) return 4;
765 return 0;
766 }
767
768 byte Fastwire::writeBuf(byte device, byte address, byte *data, byte num) {
769 byte twst, retry;

Callers 15

readBytesMethod · 0.45
readWordsMethod · 0.45
writeBytesMethod · 0.45
writeWordsMethod · 0.45
initSensitivityMethod · 0.45
readAxisMethod · 0.45
readRawMethod · 0.45
getLightIntensityMethod · 0.45
I2CWriteToMethod · 0.45
WriteMethod · 0.45
Read2Method · 0.45
writeMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected