From 1f842a31834813db3b040c470eae960bf71543fe Mon Sep 17 00:00:00 2001 From: deadlywolf90 Date: Thu, 14 Apr 2016 22:37:54 +0200 Subject: [PATCH 1/2] Update EasyTransferI2C.cpp Added a function to be used in the slave-sender's request handler. I didn't modify your great cheksum system just crammed the message in a buffer and sent all in one write, because in the request handler only one write is allowed. Works great but it is limited to the buffer size this way. (Although that can be increased) Thanks for the great library. --- EasyTransferI2C/EasyTransferI2C.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/EasyTransferI2C/EasyTransferI2C.cpp b/EasyTransferI2C/EasyTransferI2C.cpp index fd7a190..10a2188 100644 --- a/EasyTransferI2C/EasyTransferI2C.cpp +++ b/EasyTransferI2C/EasyTransferI2C.cpp @@ -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 (iwrite(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. From 50ccb0d5e7f335a604aa41e0808f9dab0f4b82d7 Mon Sep 17 00:00:00 2001 From: deadlywolf90 Date: Thu, 14 Apr 2016 22:42:00 +0200 Subject: [PATCH 2/2] Update EasyTransferI2C.h --- EasyTransferI2C/EasyTransferI2C.h | 1 + 1 file changed, 1 insertion(+) diff --git a/EasyTransferI2C/EasyTransferI2C.h b/EasyTransferI2C/EasyTransferI2C.h index 15a6861..0da5b58 100644 --- a/EasyTransferI2C/EasyTransferI2C.h +++ b/EasyTransferI2C/EasyTransferI2C.h @@ -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;