8000 proposal for I2C master/slave example by suculent · Pull Request #5360 · esp8266/Arduino · GitHub
[go: up one dir, main page]

Skip to content

proposal for I2C master/slave example #5360

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
a1b60e0
added proposal for I2C peer-to-peer communication (master/slave) exam…
Nov 21, 2018
ace0b37
fixes with regards to Travis CI help
Nov 21, 2018
ba488f7
oh, the warnings. now the goes to default but address needs to be set…
Nov 21, 2018
716f3a0
proposing new init method with pins and address, because pins() is de…
Nov 21, 2018
f692b85
Merge branch 'master' into i2c_master_slave_example
devyte Nov 23, 2018
0473dbd
type fixed in 3rd party code, removing I2C scanner (duplicate of anot…
Nov 26, 2018
d558bfe
type fix in onReceive callback
Nov 26, 2018
21dfde2
implemented changes proposed by code review
Nov 26, 2018
8d1066a
Merge branch 'i2c_master_slave_example' of github.com:suculent/Arduin…
Nov 26, 2018
57bcd96
Merge commit 'cd05bae0e8b69eea94adbf153eca4e7c9b96a901' into i2c_mast…
Nov 26, 2018
88de8da
partial fixes after travis check; still missing merge of yesterday's …
Nov 26, 2018
fe21c28
Merge branch 'master' into i2c_master_slave_example
suculent Nov 28, 2018
9f019a8
Merge branch 'master' into i2c_master_slave_example
suculent Dec 8, 2018
983fc47
no message
Dec 8, 2018
4faa715
fixes after functional testing
Dec 8, 2018
d18f57e
Merge branch 'master' into i2c_master_slave_example
devyte Dec 8, 2018
fabca64
minor style fixes
Dec 8, 2018
35f4dac
Merge branch 'i2c_master_slave_example' of github.com:suculent/Arduin…
Dec 8, 2018
a8f7d63
style fix and unused variable fix
Dec 9, 2018
0272be2
style check fix
Dec 9, 2018
20e78d0
Merge branch 'master' into i2c_master_slave_example
devyte Dec 9, 2018
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
8000
Prev Previous commit
Next Next commit
minor style fixes
  • Loading branch information
Matěj Sychra committed Dec 8, 2018
commit fabca64db0ca8be2596ae213dbfa6c5a543d8f0c
24 changes: 12 additions & 12 deletions libraries/Wire/examples/i2c-P2P-master/i2c-P2P-master.ino
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/*
* ESP8266 I2C master-slave communication, requires Arduno Core with I2C Slave Support (2.5.0+)
*
* Expects two ESP8266 devices with three pins connected: GND, SDA and SCL. This is master.
* Will send "MESA" messages to predefined slave address and then expect "PONG" response,
* or request to retransfer if message was misunderstood (e.g. CRC check failed).
* Message can be up to 26 bytes long (plus wrapper).
*
* 21-11-2018: initial drop by Matej Sychra (github.com/suculent)
*/
ESP8266 I2C master-slave communication, requires Arduno Core with I2C Slave Support (2.5.0+)

Expects two ESP8266 devices with three pins connected: GND, SDA and SCL. This is master.
Will send "MESA" messages to predefined slave address and then expect "PONG" response,
or request to retransfer if message was misunderstood (e.g. CRC check failed).
Message can be up to 26 bytes long (plus wrapper).

09-12-2018: initial drop by Matej Sychra (github.com/suculent)
*/

#include <Wire.h>
#include "crc16.h"
Expand Down Expand Up @@ -52,7 +52,7 @@ bool validateMessage(const char* bytes, MessageData &tmp);
// should be in shared header
uint16_t calculateCRC16(uint8_t *data, size_t length) {
crc.clearCrc();
uint16_t value = (uint16_t)crc.XModemCrc(data,0,length);
uint16_t value = (uint16_t)crc.XModemCrc(data, 0, length);
Serial.print("crc = 0x");
Serial.println(value, HEX);
return value;
Expand Down Expand Up @@ -176,8 +176,8 @@ void receiveEvent(const size_t howMany) {
unsigned long interval = 100;
unsigned long currentMillis = millis();
unsigned long previousMillis = millis();
// message duration may not exceed 100 ms (100 bytes, 3x buffer retransferred)
if(currentMillis - previousMillis & 8000 gt; interval) {
// message duration may not exceed 100 ms (100 bytes, 3x buffer retransferred)
if (currentMillis - previousMillis > interval) {
previousMillis = currentMillis;
// this must be fast, keep free from logging to serial here if possible
while (0 < Wire.available()) { // loop through all but the last
Expand Down
30 changes: 15 additions & 15 deletions libraries/Wire/examples/i2c-P2P-slave/i2c-P2P-slave.ino
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/*
* ESP8266 I2C master-slave communication, requires Arduno Core with I2C Slave Support (2.5.0+)
*
* Expects two ESP8266 devices with three pins connected: GND, SDA and SCL. This is slave.
* Will wait for "MESA" message and then respond with "PONG" message,
* or request retransfer if message was misunderstood (e.g. CRC check failed).
* Message can be up to 26 bytes long (plus wrapper).
*
* 21-11-2018: initial drop by Matej Sychra (github.com/suculent)
*/
ESP8266 I2C master-slave communication, requires Arduno Core with I2C Slave Support (2.5.0+)

Expects two ESP8266 devices with three pins connected: GND, SDA and SCL. This is slave.
Will wait for "MESA" message and then respond with "PONG" message,
or request retransfer if message was misunderstood (e.g. CRC check failed).
Message can be up to 26 bytes long (plus wrapper).

09-12-2018: initial drop by Matej Sychra (github.com/suculent)
*/

#include <Wire.h>
#include "crc16.h"
Expand Down Expand Up @@ -156,9 +156,9 @@ void receiveEvent(const size_t howMany) {
// Parses first byte for sequence number, contains recovery logic...
if (index == 0) {

Serial.print("Remote Sequence: "); Serial.println((int)c);
Serial.print("Remote Sequence: "); Serial.println((int)c);

if ( c!= seq && ((c > seq - 4) || (c < seq + 4)) && c != seq + 1) {
if ( c != seq && ((c > seq - 4) || (c < seq + 4)) && c != seq + 1) {
Serial.print("[DIFF] Sequence offset [!]: ");
Serial.println(c - seq);
Serial.print("Re-assigning sequence number: ");
Expand Down Expand Up @@ -196,12 +196,12 @@ void receiveEvent(const size_t howMany) {
Serial.println(String(chars));

if (requestRetransfer) {
String event = String("R") + String(seq) + String('\0');
sendMessage(seq, event);
} else {
String event = String("R") + String(seq) + String('\0');
sendMessage(seq, event);
} else {

}

Serial.print("Decoding data of size: "); Serial.println(sizeof(chars));
bool success = validateMessage(chars, message);

Expand Down
0