Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions EasyTransferI2C/EasyTransferI2C.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,34 @@ void EasyTransferI2C::sendData(uint8_t i2c_address){
_serial->endTransmission();
}

// Sends out struct in binary, with header, length info and checksum
// Pack everything in a buffer, and send in one write
// Use this in the slaves request handler, where only one write is allowed.
// Size must not exceed the twi/Wire buffer length (32 bytes by default)
// Automatic limit could be implemented later
// Tested between arduinos with 64 byte buffer and 34 bytes of data
// Adress should still be the target adress, as it is necessary for the cheksum
void EasyTransferI2C::sendDataPerRequest(uint8_t i2c_address){
byte requestBuffer[size + 4];
uint8_t CS = size;

requestBuffer[0] = 0x06;
requestBuffer[1] = 0x85;
requestBuffer[2] = size;

int i = 0;
while (i<size)
{
CS^=*(address+i);
requestBuffer[i+3] = *(address+i);
i++;
}

requestBuffer[size+3] = CS;

_serial->write(requestBuffer, size + 4);
}

boolean EasyTransferI2C::receiveData(){

//start off by looking for the header bytes. If they were already found in a previous call, skip it.
Expand Down
1 change: 1 addition & 0 deletions EasyTransferI2C/EasyTransferI2C.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class EasyTransferI2C {
public:
void begin(uint8_t *, uint8_t, TwoWire *theSerial);
void sendData(uint8_t address);
void sendDataPerRequest(uint8_t address);
boolean receiveData();
private:
TwoWire *_serial;
Expand Down