Killed my Teensy 3.1 by running I2C sketch

Status
Not open for further replies.

dmhummel

Well-known member
I am not sure if I can safe my little guy, but thought it was worth a post. I was running the sketch linked below which was a I2C test to try to interface with a Lidar Lite device. After a few runs, it stopped writing to Serial, as well as no longer triggering any activity when plugged into usb.

Any suggestions?

Code:
#include <i2c_t3.h>
#define    LIDARLite_ADDRESS   0x62          // Default I2C Address of LIDAR-Lite.
#define    RegisterMeasure     0x00          // Register to write to initiate ranging.
#define    MeasureValue        0x04          // Value to initiate ranging.
#define    RegisterHighLowB    0x8f          // Register to get both High and Low bytes in 1 call.

int reading = 0;

void setup()
{
  Wire.begin(); // join i2c bus
  Serial1.begin(115200); // start serial communication at 9600bps
}

void loop(){
  Serial1.print(">");
  Serial1.println(readDistance());
  delay(500);
}

int readDistance(){
  uint8_t nackack = 100; // Setup variable to hold ACK/NACK resopnses     
  while (nackack != 0){ // While NACK keep going (i.e. continue polling until sucess message (ACK) is received )
    Wire.beginTransmission(LIDARLite_ADDRESS);
    Wire.write(RegisterMeasure);
    Wire.write(MeasureValue);
    nackack = Wire.endTransmission(I2C_STOP);
     Serial1.print(".");
  //  print_i2c_status(nackack);
    delay(1); // Wait 1 ms to prevent overpolling
  } 
 Serial1.print("-");
  byte distanceArray[2]; // array to store distance bytes from read function
  
  // Read 2byte distance from register 0x8f
  nackack = 100; // Setup variable to hold ACK/NACK responses     
  Serial1.write (RegisterHighLowB);
  while (nackack != 1){ // While NACK keep going (i.e. continue polling until sucess message (ACK) is received )
    Wire.beginTransmission(LIDARLite_ADDRESS);
    Wire.write(RegisterHighLowB);
    nackack = Wire.endTransmission(I2C_NOSTOP);
    Wire.sendRequest(LIDARLite_ADDRESS,2,I2C_STOP);
    Serial1.print(":");
   // print_i2c_status(nackack);
   // nackack = I2c.read(LIDARLite_ADDRESS,RegisterHighLowB, 2, distanceArray); // Read 2 Bytes from LIDAR-Lite Address and store in array
    delay(1); // Wait 1 ms to prevent overpolling
  }

  distanceArray[1] = Wire.readByte();
  distanceArray[0] = Wire.readByte();
  int distance = (distanceArray[0] << 8) + distanceArray[1];  // Shift high byte [0] 8 to the left and add low byte [1] to create 16-bit int
  
  return distance;   // Print Sensor Name & Distance
   
}
 
Have you attempted to load blink to them?

If that pops up an error, does pressing the button get blink loaded?

Lots of ways to interrupt USB coms but the button press should get them back assuming nothing horrible has happened electrically.
 
Can't load any programs on to it unfortunately. I actually cant get my USB hub to even light up or my computer to load a serial port. The device seems dead. I do have a second teensy that works fine so its not a host computer problem. The part that scares me is that I was not doing anything interesting electrically. I had the lidar lite powered by 5v and its I2C should be 3.3v. I had Serial1 connected to a 1.8v Edison (via voltage converter). It was sitting untouched in a small breadboard. That was it.

I am afraid to start running simular code on my other teensy.
 
Just some background, with the Teensy normally the downloader sends a USB message and the Teensy USB code captures it, halts execution and starts the download of new code. If things have gone off beam far enough the USB code is broken pressing the button on the Teensy triggers the separate IC on the board to take control of the main IC and downloads fresh bootloader code to it. This bootloader then commences a normal USB download.

The key thing here is that it's really Really hard for software to break that download of fresh bootloader code and I'm not seeing the Teensy i2C library doing it.

I'd be more suspicious of anything you have connected that is drawing excess power or otherwise holding the Teensy in a reset state. Or basic damage to USB cable or connector. For what it's worth just loaded up your code, and it compiles and runs fine but of course just spews '.' since I don't have any i2C hardware connected. Have now loaded back to blink so nothing malicious there. I take it that things are soldered to the lidar and the Edison making it hard to pare back to the basic Teensy with USB activity?
 
Mr G. Wrangler, thanks for taking the time to run the code. I have removed the teensy and am testing it alone at this point. Things went goofy during the second I2C communication, when it decided to stop booting. I've been using the board for a while now, on a few different projects, maybe it just went bad...but I am still scared to run the code again.
 
Status
Not open for further replies.
Back
Top