Wire1 on Teensy LC ?

MMESSITER

Well-known member
Hello!

I encountered a very interesting issue today using I2C links on a Teensy LC. I wonder if anyone knows why.

I was using a Teensy LC in a new “sensors hub” device, which is part of my LockDownRadioControl project (it’s all on Github).

It uses Wire (SDA0 and SCL0) to read several sensors - in master mode. It also uses Serial1 for a GPS module.

It uses Wire1 (SDA1 and SCL1) to report all results to the radio receiver - in slave mode. The receiver is based on a Teensy 4.0.

The issue was that as soon as the receiver (Teensy 4.0) sent any data at all to the sensors hub (Teensy LC - it’s I2C slave) that data was thereafter infinitely repeated. The I2C slave appeared to receive it over and over again. Of course I looked for bugs and unintended repeats. I found none.

Eventually, I swapped out the Teensy LC for a Teensy 3.2 (by soldering wires to the underside pads for SDA1 and SCL2).

The same code works perfectly on the Teensy 3.2! So my problem has gone away! 😃

But why can it not work on Teensy LC?!

Malcolm Messiter
 
First, make sure Wire1 is enabled. Edit WireKinetis.h and look for this:

Code:
// Teensy LC
#if defined(__MKL26Z64__)
#define WIRE_IMPLEMENT_WIRE
//Wire1 consumes precious memory on Teensy LC
//#define WIRE_IMPLEMENT_WIRE1
#define WIRE_HAS_STOP_INTERRUPT

Make sure the WIRE_IMPLEMENT_WIRE1 line isn't commented out.
 
Yes Wire1 is re-implemented (without which it won’t even compile )
Must check the stop interrupt - seems a likely culprit !
Many thanks!
 
Just curious, did you get it working?

One other explanation is slave mode isn't implemented on Teensy 4.0. Slave mode (so far) only works on the older boards.

If that's not the problem, should I try to reproduce the problem here? Does the problem happen if I just run the Wire library examples like master_writer on Teensy 40 slave_receiver on a Teensy LC?
 
I must confess I didn’t get it working on LC, yet. Instead I used 3.2 and 3.5 and even a 3.6.
If you look briefly at my SendorHubLC under my LockDownRadioControl repo on GitHub you might spot the issue. It’s short. I apologise I’m rather ignorant but learning fast. I was a musician (oboe). I did once use 8086 assembler to write a modem comms app that did well in the 1980s but I only started learning C++ during lockdown so there’s still a lot that’s unfamiliar to me.
… but this radio is working well now thanks to Teensy MCUs and their astonishing speed! I started the project with Arduinos. Then I discovered Teensy 4.x in 2020. I measured the speed (with code to calculate PI 50,000,000 times) as about 600 times faster! Thank you and Bravissimo!!!
Malcolm
 
I must confess I didn’t get it working on LC, yet.
....
If you look briefly at my SendorHubLC under my LockDownRadioControl repo on GitHub you might spot the issue. It’s short.

Can you give me a direct link to this file? I see it's mentioned in msg #1, but no link.
 
That link takes me to a blink page.

If I back up to https://github.com/Mmessiter/LockDownRadioControl I see 12 folders.

Looks like there are 80 .ino files:

Code:
./SensorHubT32/lib/TinyGPSPlus-master/examples/KitchenSink/KitchenSink.ino
./SensorHubT32/lib/TinyGPSPlus-master/examples/DeviceExample/DeviceExample.ino
./SensorHubT32/lib/TinyGPSPlus-master/examples/BasicExample/BasicExample.ino
./SensorHubT32/lib/TinyGPSPlus-master/examples/FullExample/FullExample.ino
./SensorHubT32/lib/TinyGPSPlus-master/examples/SatelliteTracker/SatelliteTracker.ino
./SensorHubT32/lib/TinyGPSPlus-master/examples/UsingCustomFields/UsingCustomFields.ino
./SensorHubT32/lib/TinyGPSPlus-master/examples/SatElevTracker/SatElevTracker.ino
./SensorHubT32/lib/Adafruit_INA219/examples/getcurrent/getcurrent.ino
./SensorHubT32/lib/Adafruit_INA219/examples/ina_poweroled/ina_poweroled.ino
./SensorHubT32/lib/Adafruit_BMP280_Library/examples/bmp280test/bmp280test.ino
./SensorHubT32/lib/Adafruit_BMP280_Library/examples/bmp280_sensortest/bmp280_sensortest.ino
./SensorHubT32/lib/Adafruit_Unified_Sensor/examples/sensortest/sensortest.ino
./SensorHubT32/lib/Adafruit_BusIO/examples/spi_readwrite/spi_readwrite.ino
./SensorHubT32/lib/Adafruit_BusIO/examples/i2c_readwrite/i2c_readwrite.ino
./SensorHubT32/lib/Adafruit_BusIO/examples/i2corspi_register/i2corspi_register.ino
./SensorHubT32/lib/Adafruit_BusIO/examples/spi_register_bits/spi_register_bits.ino
./SensorHubT32/lib/Adafruit_BusIO/examples/i2c_registers/i2c_registers.ino
./SensorHubT32/lib/Adafruit_BusIO/examples/spi_registers/spi_registers.ino
./SensorHubT32/lib/Adafruit_BusIO/examples/i2c_address_detect/i2c_address_detect.ino
./SensorHubT32/lib/Adafruit_BusIO/examples/spi_modetest/spi_modetest.ino
./SensorHubTeensy3_6/lib/TinyGPSPlus-master/examples/KitchenSink/KitchenSink.ino
./SensorHubTeensy3_6/lib/TinyGPSPlus-master/examples/DeviceExample/DeviceExample.ino
./SensorHubTeensy3_6/lib/TinyGPSPlus-master/examples/BasicExample/BasicExample.ino
./SensorHubTeensy3_6/lib/TinyGPSPlus-master/examples/FullExample/FullExample.ino
./SensorHubTeensy3_6/lib/TinyGPSPlus-master/examples/SatelliteTracker/SatelliteTracker.ino
./SensorHubTeensy3_6/lib/TinyGPSPlus-master/examples/UsingCustomFields/UsingCustomFields.ino
./SensorHubTeensy3_6/lib/TinyGPSPlus-master/examples/SatElevTracker/SatElevTracker.ino
./SensorHubTeensy3_6/lib/Adafruit_INA219/examples/getcurrent/getcurrent.ino
./SensorHubTeensy3_6/lib/Adafruit_INA219/examples/ina_poweroled/ina_poweroled.ino
./SensorHubTeensy3_6/lib/Adafruit_BMP280_Library/examples/bmp280test/bmp280test.ino
./SensorHubTeensy3_6/lib/Adafruit_BMP280_Library/examples/bmp280_sensortest/bmp280_sensortest.ino
./SensorHubTeensy3_6/lib/Adafruit_Unified_Sensor/examples/sensortest/sensortest.ino
./SensorHubTeensy3_6/lib/Adafruit_BusIO/examples/spi_readwrite/spi_readwrite.ino
./SensorHubTeensy3_6/lib/Adafruit_BusIO/examples/i2c_readwrite/i2c_readwrite.ino
./SensorHubTeensy3_6/lib/Adafruit_BusIO/examples/i2corspi_register/i2corspi_register.ino
./SensorHubTeensy3_6/lib/Adafruit_BusIO/examples/spi_register_bits/spi_register_bits.ino
./SensorHubTeensy3_6/lib/Adafruit_BusIO/examples/i2c_registers/i2c_registers.ino
./SensorHubTeensy3_6/lib/Adafruit_BusIO/examples/spi_registers/spi_registers.ino
./SensorHubTeensy3_6/lib/Adafruit_BusIO/examples/i2c_address_detect/i2c_address_detect.ino
./SensorHubTeensy3_6/lib/Adafruit_BusIO/examples/spi_modetest/spi_modetest.ino
./ReceiverCode/lib/Adafruit_GPS_Library/examples/GPS_HardwareSerial_Timing/GPS_HardwareSerial_Timing.ino
./ReceiverCode/lib/Adafruit_GPS_Library/examples/GPS_HardwareSerial_EchoTest/GPS_HardwareSerial_EchoTest.ino
./ReceiverCode/lib/Adafruit_GPS_Library/examples/shield_sdlog/shield_sdlog.ino
./ReceiverCode/lib/Adafruit_GPS_Library/examples/GPS_SoftwareSerial_Parsing/GPS_SoftwareSerial_Parsing.ino
./ReceiverCode/lib/Adafruit_GPS_Library/examples/GPS_I2C_EchoTest/GPS_I2C_EchoTest.ino
./ReceiverCode/lib/Adafruit_GPS_Library/examples/GPS_SPI_EchoTest/GPS_SPI_EchoTest.ino
./ReceiverCode/lib/Adafruit_GPS_Library/examples/GPS_HardwareSerial_LOCUS_Status/GPS_HardwareSerial_LOCUS_Status.ino
./ReceiverCode/lib/Adafruit_GPS_Library/examples/GPS_SoftwareSerial_EchoTest/GPS_SoftwareSerial_EchoTest.ino
./ReceiverCode/lib/Adafruit_GPS_Library/examples/GPS_I2C_OLEDdebug/GPS_I2C_OLEDdebug.ino
./ReceiverCode/lib/Adafruit_GPS_Library/examples/GPS_HardwareSerial_LOCUS_Start/GPS_HardwareSerial_LOCUS_Start.ino
./ReceiverCode/lib/Adafruit_GPS_Library/examples/GPS_SoftwareSerial_LOCUS_Status/GPS_SoftwareSerial_LOCUS_Status.ino
./ReceiverCode/lib/Adafruit_GPS_Library/examples/NMEA_EXTENSIONS/NMEA_EXTENSIONS.ino
./ReceiverCode/lib/Adafruit_GPS_Library/examples/GPS_SoftwareSerial_LOCUS_DumpBasic/GPS_SoftwareSerial_LOCUS_DumpBasic.ino
./ReceiverCode/lib/Adafruit_GPS_Library/examples/GPS_HardwareSerial_LOCUS_Erase/GPS_HardwareSerial_LOCUS_Erase.ino
./ReceiverCode/lib/Adafruit_GPS_Library/examples/GPS_HardwareSerial_Parsing/GPS_HardwareSerial_Parsing.ino
./ReceiverCode/lib/Adafruit_GPS_Library/examples/blank/blank.ino
./ReceiverCode/lib/Adafruit_GPS_Library/examples/GPS_SoftwareSerial_LOCUS_Erase/GPS_SoftwareSerial_LOCUS_Erase.ino
./ReceiverCode/lib/Adafruit_GPS_Library/examples/GPS_SoftwareSerial_LOCUS_Start/GPS_SoftwareSerial_LOCUS_Start.ino
./ReceiverCode/lib/Adafruit_GPS_Library/examples/GPS_HardwareSerial_LOCUS_DumpBasic/GPS_HardwareSerial_LOCUS_DumpBasic.ino
./ReceiverCode/lib/Adafruit_GPS_Library/examples/GPS_I2C_Parsing/GPS_I2C_Parsing.ino
./SensorHubLC/lib/TinyGPSPlus-master/examples/KitchenSink/KitchenSink.ino
./SensorHubLC/lib/TinyGPSPlus-master/examples/DeviceExample/DeviceExample.ino
./SensorHubLC/lib/TinyGPSPlus-master/examples/BasicExample/BasicExample.ino
./SensorHubLC/lib/TinyGPSPlus-master/examples/FullExample/FullExample.ino
./SensorHubLC/lib/TinyGPSPlus-master/examples/SatelliteTracker/SatelliteTracker.ino
./SensorHubLC/lib/TinyGPSPlus-master/examples/UsingCustomFields/UsingCustomFields.ino
./SensorHubLC/lib/TinyGPSPlus-master/examples/SatElevTracker/SatElevTracker.ino
./SensorHubLC/lib/Adafruit_INA219/examples/getcurrent/getcurrent.ino
./SensorHubLC/lib/Adafruit_INA219/examples/ina_poweroled/ina_poweroled.ino
./SensorHubLC/lib/Adafruit_BMP280_Library/examples/bmp280test/bmp280test.ino
./SensorHubLC/lib/Adafruit_BMP280_Library/examples/bmp280_sensortest/bmp280_sensortest.ino
./SensorHubLC/lib/Adafruit_Unified_Sensor/examples/sensortest/sensortest.ino
./SensorHubLC/lib/Adafruit_BusIO/examples/spi_readwrite/spi_readwrite.ino
./SensorHubLC/lib/Adafruit_BusIO/examples/i2c_readwrite/i2c_readwrite.ino
./SensorHubLC/lib/Adafruit_BusIO/examples/i2corspi_register/i2corspi_register.ino
./SensorHubLC/lib/Adafruit_BusIO/examples/spi_register_bits/spi_register_bits.ino
./SensorHubLC/lib/Adafruit_BusIO/examples/i2c_registers/i2c_registers.ino
./SensorHubLC/lib/Adafruit_BusIO/examples/spi_registers/spi_registers.ino
./SensorHubLC/lib/Adafruit_BusIO/examples/i2c_address_detect/i2c_address_detect.ino
./SensorHubLC/lib/Adafruit_BusIO/examples/spi_modetest/spi_modetest.ino

All of these look like examples for various libraries. Can you tell me more specifically which file I should try to use?
 
That code (with appropriate changes) works on Teensy 3.x and Arduino. But not on Teensy LC yet! Thank you for investigating! I’m very new to all this. I’m a musician really. But the radio control works really well! 😁👍
 
Not to worry! Thanks anyway. The only changes for Arduino (… and other Teensys) are unavoidably the I2C PIN numbers. But I guess you know that!
… I can simply use another type of Teensy.

I love the Teensys!
 
Back
Top