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)
| 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; |
no outgoing calls
no test coverage detected