-
Notifications
You must be signed in to change notification settings - Fork 13.3k
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
Closed
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…
ace0b37
fixes with regards to Travis CI help
ba488f7
oh, the warnings. now the goes to default but address needs to be set…
716f3a0
proposing new init method with pins and address, because pins() is de…
f692b85
Merge branch 'master' into i2c_master_slave_example
devyte 0473dbd
type fixed in 3rd party code, removing I2C scanner (duplicate of anot…
d558bfe
type fix in onReceive callback
21dfde2
implemented changes proposed by code review
8d1066a
Merge branch 'i2c_master_slave_example' of github.com:suculent/Arduin…
57bcd96
Merge commit 'cd05bae0e8b69eea94adbf153eca4e7c9b96a901'
8000
; into i2c_mast…
88de8da
partial fixes after travis check; still missing merge of yesterday's …
fe21c28
Merge branch 'master' into i2c_master_slave_example
suculent 9f019a8
Merge branch 'master' into i2c_master_slave_example
suculent 983fc47
no message
4faa715
fixes after functional testing
d18f57e
Merge branch 'master' into i2c_master_slave_example
devyte fabca64
minor style fixes
35f4dac
Merge branch 'i2c_master_slave_example' of github.com:suculent/Arduin…
a8f7d63
style fix and unused variable fix
0272be2
style check fix
20e78d0
Merge branch 'master' into i2c_master_slave_example
devyte File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fixes after functional testing
- Loading branch information
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ | |
|
||
const int16_t I2C_MASTER = 0x42; | ||
const int16_t I2C_SLAVE = 0x08; | ||
int16_t slave_address = I2C_SLAVE; | ||
int16_t slave_address = I2C_SLAVE; | ||
|
||
// Keep this structure in sync with the i2c-P2P-slave example. Should be in shared header. | ||
struct MessageData { | ||
|
@@ -87,7 +87,6 @@ MessageData encodeMessage(const String &instring) { | |
// should be in shared header | ||
bool validateMessage(char* message_bytes, MessageData &tmp) { | ||
|
||
MessageData tmp; | ||
memcpy(&tmp, message_bytes, sizeof(tmp)); | ||
|
||
// Validate PROTOCOL terminator | ||
|
@@ -249,26 +248,26 @@ void loop() { | |
|
||
if (millis() > second_timer) { | ||
Serial.print("Errors/Bytes: "); | ||
Serial.print(error_count); | ||
Serial.print(errorCount); | ||
Serial.print("/"); | ||
Serial.print(byte_count); | ||
Serial.print(byteCount); | ||
Serial.println(" per second"); | ||
error_count = 0; | ||
byte_count = 0; | ||
errorCount = 0; | ||
byteCount = 0; | ||
second_timer = millis() + 1000; | ||
} | ||
|
||
if (millis() > next_ping) { | ||
if (millis() > nextPing) { | ||
digitalWrite(LED_PIN, LOW); | ||
next_ping = millis() + 200; | ||
nextPing = millis() + 200; | ||
Serial.print("[MASTER] Sequence » "); | ||
Serial.println(sequence); | ||
digitalWrite(LED_PIN, HIGH); | ||
sendMessage(sequence, "MESA"); | ||
if (expect_pong) { | ||
error_count++; | ||
if (expectPong) { | ||
errorCount++; | ||
} | ||
expect_pong = true; | ||
expectPong = true; | ||
sequence++; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. seq++ => ++seq |
||
} | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't work as expected on millis() rollover (will enter if statement again immediately in that case instead of waiting). Consider delta time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll fix this as part of the polledTimeout cleanup later