MCUdude / MegaCore

Arduino hardware package for ATmega64, ATmega128, ATmega165, ATmega169, ATmega325, ATmega329, ATmega640, ATmega645, ATmega649, ATmega1280, ATmega1281, ATmega2560, ATmega2561, ATmega3250, ATmega3290, ATmega6450, ATmega6490, AT90CAN32, AT90CAN64 and AT90CAN128
Other
384 stars 118 forks source link

AT90CAN128 stucked in Wire.endTransmission() #151

Closed sebashb closed 3 years ago

sebashb commented 3 years ago

Hi,

I'm trying to use the AT90CAN128 to read data from a INA226 with peterus/INA226Lib library but my code is getting blocked in the ina.configure() more precisely in the writeRegister16(INA226_REG_CONFIG, config); Wire.endTransmission(); call. I have checked twi.c and chip is blocked in the while in line 277:

// wait for write operation to complete
  while(wait && (TWI_MTX == twi_state)){
    continue;
  }

The library should not be the problem since I have already used it before with a Teensy 3.2.

I'm using the Simple.ino example of the library, and I have already checked my connection between the INA and the AT90. Schematic is below:

Schematic

image

PS: Pull-up resistors on I2C bus are 10 kΩ on the PCB.

sebashb commented 3 years ago

@MCUdude I have just tried the example in MegaCore/avr/libraries/Wire/examples/i2c_scanner/ and the same thing happened, the AT90CAN128 gets sucked on the Wire.endTransmission(); have you tried I2C before on this chip?

MCUdude commented 3 years ago

I just hooked up an i2c LCD 1602 driver, and I'm able to "ping" the i2c bus with an AT90CAN128. Note that Wire is blocking, so the program will hang if either the SDA or SCL line is held low.

Output:

I2C Scanner
Scanning...
I2C device found at address 0x20  !
done

Scanning...
I2C device found at address 0x20  !
done

Scanning...
I2C device found at address 0x20  !
done

...
sebashb commented 3 years ago

Hi MCUdude, meanwhile I have desolder the INA226 and I was also able to ping the I2C bus but since I had no devices on the bus I have not closed this issue. I will test with a new INA during this week.

sebashb commented 3 years ago

I have had the opportunity to solder a new INA226 to the PCB and now it's working the way it should. Sorry for the trouble. The INAs are quite sensitive, the go bad really easily.