|
Post by pedrosilva on Jul 3, 2018 10:55:54 GMT
Hi;
I need communicate with a external I/O and with other peripheral using I2C.
There is some example for using two I2C channels at the same time?
|
|
|
Post by pedrosilva on Jul 3, 2018 11:30:31 GMT
Hi again;
#include <Wire.h> #include <SoftwareWire.h>
SoftwareWire SwWire( 6, 7, 0, 0);
void setup() { Wire.setWirePins(UsePins_20_21); Wire.begin();
SwWire.begin(); }
void loop() { Wire.beginTransmission(0x38); Wire.write(0x00 | 0x80); Wire.write(0x03); Wire.endTransmission();
SwWire.beginTransmission(0x42); SwWire.write(140); SwWire.endTransmission(); SwWire.requestFrom(0x42, 1); if (SwWire.available() == 1) { byte value = SwWire.read(); } }
Is this the right way to do it?
Greetings
|
|
|
Post by Admin on Jul 3, 2018 11:31:43 GMT
There is only one hardware I2C channel on the TC275 so you will need to use the software bit-bashed I2C for the second channel. This accessed using the SoftwareWire.h header file.
// Use SW I2C port on any two pins #include <SoftwareWire.h>
// Create Software I2C channel on pin6 (SDA) & pin 7 (SCL) // (uint8_t sdaPin, uint8_t sclPin, boolean pullups, boolean detectClockStretch) SoftwareWire SwWire( 6, 7, 0, 0); /* No pullups, no clock stretch */
void setup() {
SwWire.begin(); // join i2c bus (address optional for master)
}
byte x = 0;
void loop() {
SwWire.beginTransmission(8); // transmit to device #8 SwWire.write("x is "); // sends five bytes SwWire.write(x); // sends one byte SwWire.endTransmission(); // stop transmitting
}
|
|
|
Post by pedrosilva on Jul 3, 2018 11:49:48 GMT
So I can use this pins with the Baudrate of 100kbit/s and the pins 20 and 21 with Baudrate of 400kbit/s at the same time correct?
|
|