PaulStoffregen
Well-known member
Ok, I've updated here. This version will be in the 1.23 installer.
#include <i2c_t3.h>
void setup()
{
Wire.begin(I2C_MASTER, 0, I2C_PINS_18_19, I2C_PULLUP_INT, I2C_RATE_100);
Serial.begin(9600);
}
void loop()
{
Serial.println("send Request");
Wire.requestFrom(1,5);
while(Wire.available()){
Serial.print(Wire.read());
Serial.print(" ");
}
delay(1000);
}
#include <i2c_t3.h>
void setup()
{
Serial.begin(9600);
Wire.begin(I2C_SLAVE, 1, I2C_PINS_18_19, I2C_PULLUP_INT, I2C_RATE_100);
Wire.onRequest(answer);
}
void loop()
{
}
void answer(){
Wire.write("Hello");
}
void print_i2c_status(void)
{
switch(Wire.status())
{
case I2C_WAITING: Serial.print("I2C waiting, no errors\n"); break;
case I2C_ADDR_NAK: Serial.print("Slave addr not acknowledged\n"); break;
case I2C_DATA_NAK: Serial.print("Slave data not acknowledged\n"); break;
case I2C_ARB_LOST: Serial.print("Bus Error: Arbitration Lost\n"); break;
case I2C_TIMEOUT: Serial.print("I2C timeout\n"); break;
case I2C_BUF_OVF: Serial.print("I2C buffer overflow\n"); break;
default: Serial.print("I2C busy\n"); break;
}
}
Wire.requestFrom(...);
print_i2c_status();
kito, did you modify if(digitalRead(12) == LOW || digitalRead(11) == LOW) to //if(digitalRead(12) == LOW || digitalRead(11) == LOW)
that is what I do to make sure I do successful scanning without the need to hook pin12 / pin11 to GND.
As Headroom mentioned there is no reason to run i2c_t3 and Wire together. The i2c_t3 library is a superset of the Wire API, so it implements all the functions already. Moreover they use the same hardware peripheral, so running both of them at once is likely to cause problems.
#if defined (TEENSYDUINO)
#include <i2c_t3.h>
#else
#include <Wire.h>
#endif
If something like this is in your sketch there is no library mod? :
Yes but it's not about my sketch, it's about the 3rd party library.
For instance I use the Adafruit_INA219 lib and it's header Adafruit_INA219.h includes <Wire.h> (see the code there).
So I would need to modify that header.
--Markk
how about if you define TwoWire_h on the very top of your sketch. Anything that #includes Wire.h will then not use the wire library since TwoWire_h is already defined.
Yes but it's not about my sketch, it's about the 3rd party library.
For instance I use the Adafruit_INA219 lib and it's header Adafruit_INA219.h includes <Wire.h> (see the code there).
So I would need to modify that header.
<sketchbook>/myproj/myproj.ino <-- single-file Arduino project "myproj"
<sketchbook>/libraries/i2c_t3/i2c_t3.* <-- original unpack location for i2c_t3.h and i2c_t3.cpp
<sketchbook>/libraries/Wire/
<sketchbook>/libraries/Wire/Wire.cpp
<sketchbook>/libraries/Wire/Wire.h
#include "Wire.h"
Multiple libraries were found for "Wire.h"
Used: <sketchbook>/libraries/Wire
I understood external pull-ups were required for I2C to work when I started with Digistump SPARKS and OLED's - and since internal pull-ups are not sufficient on Teensy - a section on that up front could save lots of the traffic I've seen on that issue. The software 'I2C_PULLUP_INT' could be tagged as on the PJRC.com page-
Teensy 3.0 requires pullup resistors to +3.3V. The on-chip pullups are not used. 4.7K resistors are recommended for most applications. :: "I2C_PULLUP_EXT" required.