-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1086 from MX682X/master
Mainly fix for #1080 (pulseIn), and accidentaly the Wire edit that is already in the DxCore; added fix for #1090
- Loading branch information
Showing
22 changed files
with
1,076 additions
and
1,388 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
84 changes: 0 additions & 84 deletions
84
megaavr/libraries/Wire/examples/master_and_slave/master_and_slave.ino
This file was deleted.
Oops, something went wrong.
55 changes: 55 additions & 0 deletions
55
megaavr/libraries/Wire/examples/master_read/master_read.ino
This file contains 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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* Wire Master Read | ||
* by MX682X | ||
* | ||
* Demonstrates use of the New Wire library | ||
* Reads data from an I2C/TWI slave device | ||
* Refer to the "Wire Slave Write" example for use with this | ||
* | ||
* This example takes the input from Serial. If the serial input is 'm' or 'M', | ||
* this code requests 4 bytes from the slave with the address 0x54. | ||
* When using together with the complementary example, the slave sends it's millis() value. | ||
* This value is then sent to the serial monitor | ||
* | ||
* To use this, you need to connect the SCL and SDA pins of this device to the | ||
* SCL and SDA pins of a second device running the Wire Slave Write example. | ||
* | ||
* Pullup resistors must be connected between both data lines and Vcc. | ||
* See the Wire library README.md for more information. | ||
*/ | ||
|
||
#define MySerial Serial | ||
|
||
#include <Wire.h> | ||
|
||
int8_t rxLen = 0; | ||
int8_t len = 0; | ||
|
||
void setup() { | ||
Wire.begin(); // initialize master | ||
MySerial.begin(115200); | ||
} | ||
|
||
void loop() { | ||
if (MySerial.available() > 0) { // as soon as the first byte is received on Serial | ||
char c = MySerial.read(); // read the data from serial. | ||
if (c == 'm' || c == 'M') { | ||
sendDataWire(); // send the data over I2C | ||
} | ||
len = 0; // since the data was sent, the position is 0 again | ||
} | ||
} | ||
|
||
void sendDataWire() { | ||
uint32_t ms; | ||
if (4 == Wire.requestFrom(0x54, 4, 0x01)) { // request from slave | ||
while (Wire.available()) { | ||
ms = (uint32_t)Wire.read(); // read out 32-bit wide data | ||
ms |= (uint32_t)Wire.read() << 8; | ||
ms |= (uint32_t)Wire.read() << 16; | ||
ms |= (uint32_t)Wire.read() << 24; | ||
MySerial.println(ms); // print the milliseconds from Slave | ||
} | ||
} else { | ||
MySerial.println("Wire.requestFrom() timed out!"); | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
megaavr/libraries/Wire/examples/master_write/master_write.ino
This file contains 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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* Wire Master Write | ||
* by MX682X | ||
* | ||
* Demonstrates use of the New Wire library | ||
* Writes data to an I2C/TWI slave device | ||
* Refer to the "Wire Slave Read" example for use with this | ||
* | ||
* Enter any data using serial monitor or other console followed by either or | ||
* both of the line ending characters, and it will be sent to the slave, which | ||
* should print it out on it's serial port. | ||
* | ||
* To use this, you need to connect the SCL and SDA pins of this device to the | ||
* SCL and SDA pins of a second device running the Wire Slave Read example. | ||
* | ||
* Pullup resistors must be connected between both data lines and Vcc. | ||
* See the Wire library README.md for more information. | ||
*/ | ||
|
||
#include <Wire.h> | ||
|
||
char input[32]; | ||
int8_t len = 0; | ||
|
||
#define MySerial Serial // The serial port connected to the to the computer. | ||
|
||
void setup() { | ||
Wire.begin(); // initialize master | ||
// MySerial.swap(1); // Remember to swap serial pins if you need to do that with your connections. | ||
MySerial.begin(115200); // Use 115200 baud - this is the 2020's, and these are modern AVRs. | ||
} | ||
|
||
void loop() { | ||
if (MySerial.available() > 0) { // as soon as the first byte is received on Serial | ||
readFromSerial(); // read the data from the Serial interface | ||
if (len > 0) { // after the while-loop, if there was useful data, | ||
sendDataWire(); // send the data over I2C | ||
} | ||
len = 0; // since the data was sent, the position is 0 again | ||
} | ||
} | ||
|
||
void readFromSerial() { | ||
while (true) { // in an endless while-loop | ||
while (MySerial.available() == 0);// means we've taken all the bytes in, and are still waiting for a cr/lf. | ||
char c = MySerial.read(); // read the next char, now that there's one available. | ||
if (c == '\n' || c == '\r') { // until a new line or carriage return is found | ||
break; // if so, break the endless while-loop | ||
} // otherwise | ||
input[len] = c; // save the char | ||
len++; // increment the position | ||
if (len > 30) { // if there was too much data | ||
break; // break the while-loop to avoid buffer overflow | ||
} | ||
} | ||
} | ||
|
||
void sendDataWire() { | ||
Wire.beginTransmission(0x54); // prepare transmission to slave with address 0x54 | ||
for (uint8_t i = 0; i < len; i++) { | ||
Wire.write(input[i]); // Write the received data to the bus buffer | ||
} | ||
Wire.write("\r\n"); // add new line and carriage return for the Serial monitor | ||
Wire.endTransmission(); // finish transmission | ||
} |
Oops, something went wrong.