Communication impossible in I2C tennsy3.6

Status
Not open for further replies.
hello,
I am from France and I do not speak English very well (excuse me)

problem 1)
I bought a teensy 3.6 but could not use the I2C bus
I tried doing the i2c Arduino test and i have no answer in the IDE monitor
see code:


#include <i2c_t3.h>

// --------------------------------------
// i2c_scanner
//
// Version 1
// This program (or code that looks like it)
// can be found in many places.
// For example on the Arduino.cc forum.
// The original author is not know.
// Version 2, Juni 2012, Using Arduino 1.0.1
// Adapted to be as simple as possible by Arduino.cc user Krodal
// Version 3, Feb 26 2013
// V3 by louarnold
// Version 4, March 3, 2013, Using Arduino 1.0.3
// by Arduino.cc user Krodal.
// Changes by louarnold removed.
// Scanning addresses changed from 0...127 to 1...119,
// according to the i2c scanner by Nick Gammon
// http://www.gammon.com.au/forum/?id=10896
// Version 5, March 28, 2013
// As version 4, but address scans now to 127.
// A sensor seems to use address 120.
// Version 6, November 27, 2015.
// Added waiting for the Leonardo serial communication.
//
//
// This sketch tests the standard 7-bit addresses
// Devices with higher bit address might not be seen properly.
//



void setup()
{
Wire1.begin();

Serial.begin(9600);
while (!Serial); // Leonardo: wait for serial monitor
Serial.println("\nI2C Scanner");
}


void loop()
{
byte error, address;
int nDevices;

Serial.println("Scanning...");

nDevices = 0;
for(address = 1; address < 127; address++ )
{
// The i2c_scanner uses the return value of
// the Write.endTransmisstion to see if
// a device did acknowledge to the address.
Wire.beginTransmission(address);
error = Wire.endTransmission();

if (error == 0)
{
Serial.print("I2C device found at address 0x");
if (address<16)
Serial.print("0");
Serial.print(address,HEX);
Serial.println(" !");

nDevices++;
}
else if (error==4)
{
Serial.print("Unknow error at address 0x");
if (address<16)
Serial.print("0");
Serial.println(address,HEX);
}
}
if (nDevices == 0)
Serial.println("No I2C devices found\n");
else
Serial.println("done\n");

delay(5000); // wait 5 seconds for next scan
}

I tried with Wire and Wire1 with pins 19,18 or 37; 38 it's the same
The sensor works with an Arduino


I tried with the tennsy example program
see code of the basic scanner

I2C Bus Scanner
// -------------------------------------------------------------------------------------------
//
// This creates an I2C master device which will scan the address space and report all
// devices which ACK. It does not attempt to transfer data, it only reports which devices
// ACK their address.
//
// Pull the control pin low to initiate the scan. Result will output to Serial.
//
// This example code is in the public domain.
// -------------------------------------------------------------------------------------------

#include <i2c_t3.h>

// Function prototypes
void print_scan_status(uint8_t target, uint8_t all);

uint8_t found, target, all;

void setup()
{
pinMode(LED_BUILTIN,OUTPUT); // LED
pinMode(12,INPUT_PULLUP); // pull pin 12 low to show ACK only results
pinMode(11,INPUT_PULLUP); // pull pin 11 low for a more verbose result (shows both ACK and NACK)

// Setup for Master mode, pins 18/19, external pullups, 400kHz, 10ms default timeout
Wire.begin(I2C_MASTER, 0x00, I2C_PINS_18_19, I2C_PULLUP_EXT, 400000);
Wire.setDefaultTimeout(10000); // 10ms

Serial.begin(115200);
}

void loop()
{
// Scan I2C addresses
//
if(digitalRead(12) == LOW || digitalRead(11) == LOW)
{
all = (digitalRead(11) == LOW);
found = 0;

Serial.print("---------------------------------------------------\n");
Serial.print("Starting scan...\n");
digitalWrite(LED_BUILTIN,HIGH); // LED on
for(target = 1; target <= 0x7F; target++) // sweep addr, skip general call
{
Wire.beginTransmission(target); // slave addr
Wire.endTransmission(); // no data, just addr
print_scan_status(target, all);
}
digitalWrite(LED_BUILTIN,LOW); // LED off

if(!found) Serial.print("No devices found.\n");

delay(100); // delay to space out tests
}
}

//
// print scan status
//
void print_scan_status(uint8_t target, uint8_t all)
{
switch(Wire.status())
{
case I2C_WAITING:
Serial.printf("Addr: 0x%02X ACK\n", target);
found = 1;
break;
case I2C_ADDR_NAK:
if(all) Serial.printf("Addr: 0x%02X\n", target);
break;
default:
break;
}
}
The result is the same, no display in the monitor, the program is blocked?


Problem 2)
I tried to compile the Sparkfun program for the MPL3115A2 sensor

See code:
#include <i2c_t3.h>
#include "SparkFunMPL3115A2.h"

//Create an instance of the object
MPL3115A2 myPressure;

void setup()
{
Serial.begin(9600); // Start serial for output
Wire1.begin(); // Join i2c bus


myPressure.begin(); // Get sensor online

//Configure the sensor
myPressure.setModeAltimeter(); // Measure altitude above sea level in meters
//myPressure.setModeBarometer(); // Measure pressure in Pascals from 20 to 110 kPa

myPressure.setOversampleRate(7); // Set Oversample to the recommended 128
myPressure.enableEventFlags(); // Enable all three pressure and temp event flags
}

void loop()
{
float altitude = myPressure.readAltitude();
Serial.print("Altitude(m):");
Serial.print(altitude, 2);

//float altitude = myPressure.readAltitudeFt();
//Serial.print(" Altitude(ft):");
//Serial.print(altitude, 2);

float pressure = myPressure.readPressure();
Serial.print("Pressure(Pa):");
Serial.print(pressure, 2);

//float temperature = myPressure.readTemp();
//Serial.print(" Temp(c):");
//Serial.print(temperature, 2);

float temperature = myPressure.readTempF();
Serial.print(" Temp(f):");
Serial.print(temperature, 2);

Serial.println();
}

But I have the following error

Arduino : 1.8.1 (Windows 10), TD: 1.35, Carte : "Teensy 3.6, Serial, 180 MHz, Fast, US English"

In file included from C:\Users\jcc\Documents\Arduino\libraries\SparkFun_MPL3115A2_Altitude_and_Pressure_Sensor_Breakout\src/SparkFunMPL3115A2.h:19:0,

from C:\Users\jcc\AppData\Local\Temp\arduino_modified_sketch_41314\SparkFunAltimeter.ino:36:

C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Wire/Wire.h:104:16: error: conflicting declaration 'TwoWire Wire'

extern TwoWire Wire;

^

In file included from C:\Users\jcc\AppData\Local\Temp\arduino_modified_sketch_41314\SparkFunAltimeter.ino:35:0:

C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\i2c_t3/i2c_t3.h:987:15: error: 'Wire' has a previous declaration as 'i2c_t3 Wire'

extern i2c_t3 Wire;

^

Erreur de compilation pour la carte Teensy 3.6

Ce rapport pourrait être plus détaillé avec
l'option "Afficher les résultats détaillés de la compilation"
activée dans Fichier -> Préférences.

Thank you for your help

Regards

jean-claude
 
Did you connect real pullup resistors on the SDA and SCL wires?

With many Arduino boards, the chip has (very weak) internal pullup resistors.

Teensy 3.x does NOT have internal pullup resistors on SDA & SCL. You need to physically connect resistors between those pins and 3.3V.
 
For testing I2C, use File > Examples > Wire > Scanner. Please check if the simpler Wire library works before using the more complex i2c_t3 library.
 
hello,
Thank you for your help
With pullup resistance the I2C bus is operational on pins 18 and 19
with File > Examples > Wire > Scanner; run with <i2c_t3.h> and <Wire.h>
With basic_scanner the program crashes with <i2c_t3.h> And does not compile with <wire.h>
the problem 1(see up) is identical with <i2c_t3.h> but run with <wire.h> but impossible to use Wire1 and Wire2....
I tried with a BMP280 sensor and the program sparkfun
Work correctly with Wire.h but no compile with <i2C_t3.h>
see below program and error


I2C_ReadAllData.ino
BME280 Arduino and Teensy example
Marshall Taylor @ SparkFun Electronics
May 20, 2015
https://github.com/sparkfun/SparkFun_BME280_Arduino_Library

This sketch configures the BME280 to read all measurements. The sketch also
displays the BME280's physical memory and what the driver perceives the
calibration words to be.

Resources:
Uses Wire.h for I2C operation
Uses SPI.h for SPI operation

Development environment specifics:
Arduino IDE 1.6.4
Teensy loader 1.23

This code is released under the [MIT License](http://opensource.org/licenses/MIT).
Please review the LICENSE.md file included with this example. If you have any questions
or concerns with licensing, please contact techsupport@sparkfun.com.
Distributed as-is; no warranty is given.
******************************************************************************/

#include <stdint.h>
#include "SparkFunBME280.h"
//Library allows either I2C or SPI, so include both.
#include "i2c_t3.h"
#include "SPI.h"

//Global sensor object
BME280 mySensor;

void setup()
{
//***Driver settings********************************//
//commInterface can be I2C_MODE or SPI_MODE
//specify chipSelectPin using arduino pin names
//specify I2C address. Can be 0x77(default) or 0x76

//For I2C, enable the following and disable the SPI section
mySensor.settings.commInterface = I2C_MODE;
mySensor.settings.I2CAddress = 0x77;

//For SPI enable the following and dissable the I2C section
//mySensor.settings.commInterface = SPI_MODE;
//mySensor.settings.chipSelectPin = 10;


//***Operation settings*****************************//

//renMode can be:
// 0, Sleep mode
// 1 or 2, Forced mode
// 3, Normal mode
mySensor.settings.runMode = 3; //Normal mode

//tStandby can be:
// 0, 0.5ms
// 1, 62.5ms
// 2, 125ms
// 3, 250ms
// 4, 500ms
// 5, 1000ms
// 6, 10ms
// 7, 20ms
mySensor.settings.tStandby = 0;

//filter can be off or number of FIR coefficients to use:
// 0, filter off
// 1, coefficients = 2
// 2, coefficients = 4
// 3, coefficients = 8
// 4, coefficients = 16
mySensor.settings.filter = 4;

//tempOverSample can be:
// 0, skipped
// 1 through 5, oversampling *1, *2, *4, *8, *16 respectively
mySensor.settings.tempOverSample = 1;

//pressOverSample can be:
// 0, skipped
// 1 through 5, oversampling *1, *2, *4, *8, *16 respectively
mySensor.settings.pressOverSample = 1;

//humidOverSample can be:
// 0, skipped
// 1 through 5, oversampling *1, *2, *4, *8, *16 respectively
mySensor.settings.humidOverSample = 1;

Serial.begin(57600);
Serial.print("Program Started\n");
Serial.print("Starting BME280... result of .begin(): 0x");

//Calling .begin() causes the settings to be loaded
delay(10); //Make sure sensor had enough time to turn on. BME280 requires 2ms to start up.
Serial.println(mySensor.begin(), HEX);

Serial.print("Displaying ID, reset and ctrl regs\n");

Serial.print("ID(0xD0): 0x");
Serial.println(mySensor.readRegister(BME280_CHIP_ID_REG), HEX);
Serial.print("Reset register(0xE0): 0x");
Serial.println(mySensor.readRegister(BME280_RST_REG), HEX);
Serial.print("ctrl_meas(0xF4): 0x");
Serial.println(mySensor.readRegister(BME280_CTRL_MEAS_REG), HEX);
Serial.print("ctrl_hum(0xF2): 0x");
Serial.println(mySensor.readRegister(BME280_CTRL_HUMIDITY_REG), HEX);

Serial.print("\n\n");

Serial.print("Displaying all regs\n");
uint8_t memCounter = 0x80;
uint8_t tempReadData;
for(int rowi = 8; rowi < 16; rowi++ )
{
Serial.print("0x");
Serial.print(rowi, HEX);
Serial.print("0:");
for(int coli = 0; coli < 16; coli++ )
{
tempReadData = mySensor.readRegister(memCounter);
Serial.print((tempReadData >> 4) & 0x0F, HEX);//Print first hex nibble
Serial.print(tempReadData & 0x0F, HEX);//Print second hex nibble
Serial.print(" ");
memCounter++;
}
Serial.print("\n");
}


Serial.print("\n\n");

Serial.print("Displaying concatenated calibration words\n");
Serial.print("dig_T1, uint16: ");
Serial.println(mySensor.calibration.dig_T1);
Serial.print("dig_T2, int16: ");
Serial.println(mySensor.calibration.dig_T2);
Serial.print("dig_T3, int16: ");
Serial.println(mySensor.calibration.dig_T3);

Serial.print("dig_P1, uint16: ");
Serial.println(mySensor.calibration.dig_P1);
Serial.print("dig_P2, int16: ");
Serial.println(mySensor.calibration.dig_P2);
Serial.print("dig_P3, int16: ");
Serial.println(mySensor.calibration.dig_P3);
Serial.print("dig_P4, int16: ");
Serial.println(mySensor.calibration.dig_P4);
Serial.print("dig_P5, int16: ");
Serial.println(mySensor.calibration.dig_P5);
Serial.print("dig_P6, int16: ");
Serial.println(mySensor.calibration.dig_P6);
Serial.print("dig_P7, int16: ");
Serial.println(mySensor.calibration.dig_P7);
Serial.print("dig_P8, int16: ");
Serial.println(mySensor.calibration.dig_P8);
Serial.print("dig_P9, int16: ");
Serial.println(mySensor.calibration.dig_P9);

Serial.print("dig_H1, uint8: ");
Serial.println(mySensor.calibration.dig_H1);
Serial.print("dig_H2, int16: ");
Serial.println(mySensor.calibration.dig_H2);
Serial.print("dig_H3, uint8: ");
Serial.println(mySensor.calibration.dig_H3);
Serial.print("dig_H4, int16: ");
Serial.println(mySensor.calibration.dig_H4);
Serial.print("dig_H5, int16: ");
Serial.println(mySensor.calibration.dig_H5);
Serial.print("dig_H6, uint8: ");
Serial.println(mySensor.calibration.dig_H6);

Serial.println();
}

void loop()
{
//Each loop, take a reading.
//Start with temperature, as that data is needed for accurate compensation.
//Reading the temperature updates the compensators of the other functions
//in the background.

Serial.print("Temperature: ");
Serial.print(mySensor.readTempC(), 2);
Serial.println(" degrees C");

Serial.print("Temperature: ");
Serial.print(mySensor.readTempF(), 2);
Serial.println(" degrees F");

Serial.print("Pressure: ");
Serial.print(mySensor.readFloatPressure(), 2);
Serial.println(" Pa");

Serial.print("Altitude: ");
Serial.print(mySensor.readFloatAltitudeMeters(), 2);
Serial.println("m");

Serial.print("Altitude: ");
Serial.print(mySensor.readFloatAltitudeFeet(), 2);
Serial.println("ft");

Serial.print("%RH: ");
Serial.print(mySensor.readFloatHumidity(), 2);
Serial.println(" %");

Serial.println();

delay(1000);

}




error with i2c_t3 library

Arduino : 1.8.1 (Windows 10), TD: 1.35, Carte : "Teensy 3.6, Serial, 180 MHz, Fast, US English"

C:\Users\jcc\AppData\Local\Temp\arduino_build_846279\libraries\Wire\Wire.cpp.o: In function `i2c0_isr':

C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Wire/Wire.cpp:376: multiple definition of `i2c0_isr'

C:\Users\jcc\AppData\Local\Temp\arduino_build_846279\libraries\i2c_t3\i2c_t3.cpp.o:C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\i2c_t3/i2c_t3.cpp:1387: first defined here

c:/program files (x86)/arduino/hardware/tools/arm/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/bin/ld.exe: Disabling relaxation: it will not work with multiple definitions

C:\Users\jcc\AppData\Local\Temp\arduino_build_846279\libraries\Wire\Wire.cpp.o: In function `TwoWire::flush()':

C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Wire/Wire.cpp:507: multiple definition of `Wire'

C:\Users\jcc\AppData\Local\Temp\arduino_build_846279\libraries\i2c_t3\i2c_t3.cpp.o:C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\i2c_t3/i2c_t3.h:911: first defined here

c:/program files (x86)/arduino/hardware/tools/arm/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/bin/ld.exe: Warning: size of symbol `Wire' changed from 20 in C:\Users\jcc\AppData\Local\Temp\arduino_build_846279\libraries\i2c_t3\i2c_t3.cpp.o to 16 in C:\Users\jcc\AppData\Local\Temp\arduino_build_846279\libraries\Wire\Wire.cpp.o

collect2.exe: error: ld returned 1 exit status

Plusieurs bibliothèque trouvées pour "i2c_t3.h"
Utilisé : C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\i2c_t3
Non utilisé : C:\Users\jcc\Documents\Arduino\libraries\i2c_t3-master
Erreur de compilation pour la carte Teensy 3.6

Ce rapport pourrait être plus détaillé avec
l'option "Afficher les résultats détaillés de la compilation"
activée dans Fichier -> Préférences.



thank for your help
 
I have a version of Wire library that supports the multiple buses: It is up at: https://github.com/KurtE/Wire/tree/Support-Wire1/2/3
I have a PR to the master library: but my gut says it may not ever be pulled in. But you might give it a try.

One problem with Wire and i2c_t3 is they both generate some of the same objects, so if a program includes both, it won't compile.

A hack that might get you around this, is to create a dummy Wire library in your <arduino Sketch folders>/libraries/Wire
Which has Wire.h which simply includes i2c_t3
i.e.
Code:
#include <i2c_t3.h>
You may also want to include an empty Wire.cpp file...

This might work for some cases, but won't cover them all. That is if any code that calls the wire members to set the SCL or SDA, they are not defined in I2C. Also won't work if some classes allow you to pass in pointer or reference to a wire object as the object class names are different.

But it might work for your stuff.

Kurt
 
Thanks Kurt
I just started arduino only two months ago and your explanations are difficult for me.
If I have no other solutions, I need multiple I2c I will use your library. But in this case this will remove or conflict with the wire.h updated by Arduino?
My problem is that I use the same computer for Arduino and Teensy, so do not I break what works properly with the various Arduino
What is your advice?

All the best

Jean-Claude
 
i had an issue, multiple i2c devices on the same bus, with SOME not working (5v sda/scl) on the teensy (3.5), using a level shifter has ressolved it. and never had issues since.

just throwing it out there
 
Sorry, there is not an easy answer here. The most complete answer is to use i2c_t3 for the multiple I2c support, plus some other cool things.

But if you wish for the code to be supported on various Arduinos including Teensy, harder to give good answer. My version that I made I have tried out some on T3.x boards, but not on any AVR boards. So not sure if it would work properly on those or not.

If you update the Wire library with my stuff in the location where teensyduino install puts the files, it will be overwritten by the next time you install teensyduino. If you put it in the location I mentioned it will also be used when you try to build for other Arduinos...

If it were me and I wanted to use i2c_t3 on my Teensy boards and standard stuff on other AVR boards, I would probably create a hybrid solution and copy the AVR version to my <sketch>/libraries folder and then hack it

That is edit the copy of SPI.h, I mentioned, to do something like:
Code:
#if defined(KINETISK) || defined(__MKL26Z64__)
#include <i2c_t3.h>
#else
    (the contents of the current wire.h file )
#endif
[code]
And edit the wire.cpp file to not include anything for the T3.x files.
[code]
#if defined(KINETISK) || defined(__MKL26Z64__)
// Using i2c_t3 library for these boards
#else
    (the contents of the current wire.cpp file )
#endif
Again I don't know how well this will work. Also don't know how well this would work if you tried to do some of the other ARM based Arduinos, like DUE or M0 or...

So again not sure what the best answer is here, except wishing support for Wire1, Wire2... was native in the Wire library

Sorry
 
Sounds like a plan. Things to talk about this includes:
a) I am using sub-classes for each of the Wire objects, with the Base class the same as Arduino including their ARM setups. But looking over their ARM setup, they use one class, where they pass in some data to create it... Wondering if I should try to convert over to that type of setup, as I believe the Adafruit M0 code is using that setup as well...

b) I am mallocing the buffers only if the object is used. I was not sure if we wanted to allocate yet more buffers on boards like the T-LC unless the object is used. At times I wonder if similar things should be done for things like UARTS, so if code only uses Serial and Serial1, we don't use up memory for Serial2 and Serial3...

But it will be fun to play with the USB stuff once you have it up and working!

Kurt

P.S. - I am not sure how you find enough hours in the day to get all of your stuff done!
 
Conditional compile defines for all Teensy 3.X (and LC too?)

Does
Code:
#if defined(KINETISK) || defined(__MKL26Z64__)
catch all versions of Teensy 3.X? And LC?
I've been using
Code:
#if defined (__MK20DX256__) || defined (__MK20DX128__) 	// Teensy 3.1 or 3.2 || Teensy 3.0
Where can I look up all these available manifest constants and their meanings?
 
These are set in arduino/hardware/teensy/avr/boards.txt as compiler flags:

LC: __MKL26Z64__
3.0: __MK20DX128__
3.1/3.2: __MK20DX256__
3.5: __MK64FX512__
3.6: __MK66FX1M0__

These are set in arduino/hardware/teensy/avr/cores/teensy3/kinetis.h:
LC: KINETISL
3.x: KINETISK
 
Status
Not open for further replies.
Back
Top