Good Morning All!
I'm getting two LIDAR's (Garmin Lidar Lite V3 (not HP)) together running from one Teensy 3.2. Had this working once a year back, but am having an issue getting back to where it was....
The LIDAR enable pins are tied to DIO 16, and 17. SCL0 and SDA0 are pulled up with 2.5K, and am getting 100% good I2C transactions for distance reads. It'll spit out distances for days and days without error. I'm using i2c_t3.h.
Anyway, not time to get them both working together at separate addresses......
I'm starting by just trying to read back the LIDAR address from the 0x16 and 0x17 registers. Would like to confirm they read back OK before charging ahead. The output of the code below is: "High:48 Low:128" Since 0x62 ( 0000 0000 0110 0010 ) is the default address, I was expecting something like "High:0 Low:98".
Does anything jump out at anyone? Also, I'm only checking nackack's returning from Wire.endTransmission(), if anyone can suggest a way to
check at every read or write, that would be really nice.
Here's the code........
/* Registers to change default I2C addresses
* Available addresses are 7 bit values with a '0' at the LSB. i.e. even hex numbers
* 1. Read high and low address bytes from 0x16 and 0x17
* 2. Write high byte to 0x18
* 3. Write low byte to 0x19
* 4. Write new I2C address to 0x1a
* 5. Write 0x08 to 0x1e to disable old I2C address
* The default I2C addresses will be restored after a power cycle.
#define UNIT_ID_HIGH 0x16 // Read serial number high byte
#define UNIT_ID_LOW 0x17 // Read serial number low byte
#define I2C_ID_HIGH 0x18 // Write high byte for SN unlock
#define I2C_ID_LOW 0x19 // Write low byte for SN unlock
#define I2C_SEC_ADDR 0x1a // Write new I2C address after unlock
#define I2C_CONFIG 0x1e // Write 0x08 to 0x1e to disable default (0x62) address
******************************/
void MoveLidar_1_Address(void){
uint8_t nackack = 100;
byte reading_HighAddr, reading_LowAddr;
digitalWrite(PIN_LIDAR_1_PWR_ENAB_LOW, LOW); // Just one LIDAR selected for address change.
digitalWrite(PIN_LIDAR_2_PWR_ENAB_LOW, HIGH); delay(10);
while (nackack != 0) {
Wire.beginTransmission(0x62); //Default LIDAR address
Wire.write(UNIT_ID_HIGH); // Set up Garmin to return data as two sequential I2C reads.
nackack = Wire.endTransmission(I2C_STOP, 1000);
Error_I2C_LIDAR (nackack); // routine to count the errors.
}
Wire.requestFrom(0x62, 1, I2C_STOP, 1000 ); //Request 1 byte from slave (the LIDAR)
reading_HighAddr = Wire.readByte() ;
nackack = 100; // nackack was 0 after the last I2C transaction, reset it.
while (nackack != 0) { //While NACK keep going (i.e. continue polling until success message 0 is received ) Need a watchdog.
Wire.beginTransmission(0x62); //Hardcode now to det default address
Wire.write(UNIT_ID_LOW); // Set up Garmin to return data as two sequential I2C reads.
nackack = Wire.endTransmission(I2C_STOP, 1000);
Error_I2C_LIDAR (nackack);
}
Wire.requestFrom(0x62, 1, I2C_STOP, 1000 ); //Request 1 byte from slave (the LIDAR)
reading_LowAddr = Wire.readByte() ;
Error_I2C_LIDAR (nackack); //For now, to echo errors returned from LIDAR to serial monitor.
Serial.print("High:"); Serial.print(reading_HighAddr); Serial.print(" Low:"); Serial.println(reading_LowAddr);
delay(3000);
/* Code to execute the remaining steps will go here....
* for now, just trying to confirm that one can get back the
* default (0x62) address
* I2C_ID_HIGH 0x18 // Write high byte for SN unlock
* I2C_ID_LOW 0x19 // Write low byte for SN unlock
* I2C_SEC_ADDR 0x1a // Write new I2C address after unlock
* I2C_CONFIG 0x1e // Write 0x08 to 0x1e to disable default (0x62) address */
return;
}
int Error_I2C_LIDAR (int ErrCode) { // Code to branch calling routine toward recovery from error.
switch (ErrCode) {
case 0: break; //success, continue I2C transaction by reading the data next.
case 1: Serial.print(ErrCode); Serial.println(" - Data too long"); err_cnt += 1; break;
case 2: Serial.print(ErrCode); Serial.println(" - Received ADDR NACK"); err_cnt += 1; break;
case 3: Serial.print(ErrCode); Serial.println(" - Received DATA NACK"); err_cnt += 1; break;
case 4: Serial.print(ErrCode); Serial.print(" - Other Error "); err_cnt += 1;
Serial.println(err_cnt); break;
default: break;
}
return err_cnt;
}
I'm getting two LIDAR's (Garmin Lidar Lite V3 (not HP)) together running from one Teensy 3.2. Had this working once a year back, but am having an issue getting back to where it was....
The LIDAR enable pins are tied to DIO 16, and 17. SCL0 and SDA0 are pulled up with 2.5K, and am getting 100% good I2C transactions for distance reads. It'll spit out distances for days and days without error. I'm using i2c_t3.h.
Anyway, not time to get them both working together at separate addresses......
I'm starting by just trying to read back the LIDAR address from the 0x16 and 0x17 registers. Would like to confirm they read back OK before charging ahead. The output of the code below is: "High:48 Low:128" Since 0x62 ( 0000 0000 0110 0010 ) is the default address, I was expecting something like "High:0 Low:98".
Does anything jump out at anyone? Also, I'm only checking nackack's returning from Wire.endTransmission(), if anyone can suggest a way to
check at every read or write, that would be really nice.
Here's the code........
/* Registers to change default I2C addresses
* Available addresses are 7 bit values with a '0' at the LSB. i.e. even hex numbers
* 1. Read high and low address bytes from 0x16 and 0x17
* 2. Write high byte to 0x18
* 3. Write low byte to 0x19
* 4. Write new I2C address to 0x1a
* 5. Write 0x08 to 0x1e to disable old I2C address
* The default I2C addresses will be restored after a power cycle.
#define UNIT_ID_HIGH 0x16 // Read serial number high byte
#define UNIT_ID_LOW 0x17 // Read serial number low byte
#define I2C_ID_HIGH 0x18 // Write high byte for SN unlock
#define I2C_ID_LOW 0x19 // Write low byte for SN unlock
#define I2C_SEC_ADDR 0x1a // Write new I2C address after unlock
#define I2C_CONFIG 0x1e // Write 0x08 to 0x1e to disable default (0x62) address
******************************/
void MoveLidar_1_Address(void){
uint8_t nackack = 100;
byte reading_HighAddr, reading_LowAddr;
digitalWrite(PIN_LIDAR_1_PWR_ENAB_LOW, LOW); // Just one LIDAR selected for address change.
digitalWrite(PIN_LIDAR_2_PWR_ENAB_LOW, HIGH); delay(10);
while (nackack != 0) {
Wire.beginTransmission(0x62); //Default LIDAR address
Wire.write(UNIT_ID_HIGH); // Set up Garmin to return data as two sequential I2C reads.
nackack = Wire.endTransmission(I2C_STOP, 1000);
Error_I2C_LIDAR (nackack); // routine to count the errors.
}
Wire.requestFrom(0x62, 1, I2C_STOP, 1000 ); //Request 1 byte from slave (the LIDAR)
reading_HighAddr = Wire.readByte() ;
nackack = 100; // nackack was 0 after the last I2C transaction, reset it.
while (nackack != 0) { //While NACK keep going (i.e. continue polling until success message 0 is received ) Need a watchdog.
Wire.beginTransmission(0x62); //Hardcode now to det default address
Wire.write(UNIT_ID_LOW); // Set up Garmin to return data as two sequential I2C reads.
nackack = Wire.endTransmission(I2C_STOP, 1000);
Error_I2C_LIDAR (nackack);
}
Wire.requestFrom(0x62, 1, I2C_STOP, 1000 ); //Request 1 byte from slave (the LIDAR)
reading_LowAddr = Wire.readByte() ;
Error_I2C_LIDAR (nackack); //For now, to echo errors returned from LIDAR to serial monitor.
Serial.print("High:"); Serial.print(reading_HighAddr); Serial.print(" Low:"); Serial.println(reading_LowAddr);
delay(3000);
/* Code to execute the remaining steps will go here....
* for now, just trying to confirm that one can get back the
* default (0x62) address
* I2C_ID_HIGH 0x18 // Write high byte for SN unlock
* I2C_ID_LOW 0x19 // Write low byte for SN unlock
* I2C_SEC_ADDR 0x1a // Write new I2C address after unlock
* I2C_CONFIG 0x1e // Write 0x08 to 0x1e to disable default (0x62) address */
return;
}
int Error_I2C_LIDAR (int ErrCode) { // Code to branch calling routine toward recovery from error.
switch (ErrCode) {
case 0: break; //success, continue I2C transaction by reading the data next.
case 1: Serial.print(ErrCode); Serial.println(" - Data too long"); err_cnt += 1; break;
case 2: Serial.print(ErrCode); Serial.println(" - Received ADDR NACK"); err_cnt += 1; break;
case 3: Serial.print(ErrCode); Serial.println(" - Received DATA NACK"); err_cnt += 1; break;
case 4: Serial.print(ErrCode); Serial.print(" - Other Error "); err_cnt += 1;
Serial.println(err_cnt); break;
default: break;
}
return err_cnt;
}