1

I am currently experiencing a really odd I2C problem on a Atmega32u4 based card. I'm trying to use a TLV493D connected by I2C. I know from this thread that before using this device, I have to set the powermode :

Wire.beginTransmission(HallAddressWrite);       // Address the sensor
Wire.write(configReg);              // Address the Configuration register
Wire.write(powerMode);              // Set the Power Mode to Low
errorCode = Wire.endTransmission();             // Stop transmitting

But each time I'm trying to write on the TLV493D register, the device simply disappear from I2C bus ! I know it sounds strange, but I can demonstrate it with a modified version of default I2C scanner

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

  Serial.println("Beginning write test...");
  Wire.beginTransmission(address);
  // no register writing
  errorCode = Wire.endTransmission(); 
  Serial.print("Test ended with code : ");
  Serial.println(errorCode);

  Serial.println("SECOND Beginning write test...");

  Wire.beginTransmission(address);       // Address the sensor
  Wire.write(0x00);              // Address the Configuration register
  Wire.write(0x05);            // Set the Power Mode to Low
  errorCode = Wire.endTransmission(); 
  Serial.print("Test ended with code : ");
  Serial.println(errorCode);

  nDevices++;
}

which gives the output:

I2C device found at address 0x5E  !
Beginning write test...
Test ended with code : 0
SECOND Beginning write test...
Test ended with code : 0

And next scan doesn't find anything. As you can see, I don't lost my device when I don't write anything. But it disappears from my bus as soon as I write something (here, it's for setting low power mode, but any value will do the same).

More informations :

  • My code is correct. I know that because I don't have any problem when using an Arduino Uno or Arduino Mega. Unfortunately, I don't have an Arduino Leonardo to see if my problem comes from Atmega32u4.

  • My wiring is correct. I checked the signal on SDA and SCL pin on the TLV493D with an oscilloscope and everything is as expected : 3.3V and 100kHz.

  • I also have a SRF02 on my I2c bus : it is working as expected.

  • I don't think my TLV493D is damaged. In deed, I thought it was because of that. So I changed it for another one but the problem is still here.

  • I noticed than when beginning an I2C transmission at address 0x00, I am able to see my TLV493D again. But it is pointless since I have to set power mode again and thus, it disappears from bus once again.

  • 1
    Have you checked, that the supply voltage doesn't fall too low, when writing to the TLV via I2C? During reading the datasheet I thought, this maybe would show the seen behavior by resetting it everytime, you write to it. – chrisl Jun 14 '18 at 22:17
  • Hi chrisl, thank you for replying. That actually was a good point, but unfortunately, supply voltage stay constant at 3.3V. – erenaud Jun 15 '18 at 9:21
1

By default the FAST register is set to 0 at power up. When the FAST mode is 0 and you set LOW to 0 you are entering Power Down mode.

Looking at your code it looks like you are not altering the FAST register which means I can simplify your question to "Why does my device disappear from the I2C bus every time I turn it off".

Just looking at page 34 of the English User Manual I would say you have to set FAST to 1 before setting LOW to 0.

Also - Do you have pull-up resistors on the I2C bus? You might encounter problems without them. They are normally around 4.7K for 5V, but I don't know what they should be for 3.3v systems.

  • Thanks for your answer. I am not quite sure I understand though. At which point of my code am I setting LOW to 0 ? I do have a pull-up resistors on my I2C bus. And finally, what I really don't understand is why I have to do all that, knowing that my code is working just fine on Uno and Mega ? I mean, what is the Atmega32u4 difference ? – erenaud Jun 15 '18 at 13:20
  • @erenaud , that is the wrong kind of question. You should do everything right, and then solve any remaining problems. Is your atmega32u4 running at 3.3V? Then you don't need a level shifter. Use pullup resistors. Follow the datasheet. – Jot Jun 15 '18 at 13:43
  • @Jot As I said, I am using pullup resistors. – erenaud Jun 15 '18 at 13:51
  • Sorry I missed the fact that it was "working" on a Uno and Mega. When using it with a Uno/Mega do you use a 5V or 3.3V I2C bus? According to the code you have included above and the datasheet you link to you are writing to Write Register 0 with the value 5. Register 0 is reserved and must not be written to or have I misread the data sheet? – Code Gorilla Jun 15 '18 at 14:12
  • @CodeGorilla I am using 3.3V bus. Indeed, I thought I was writing to register 0 with value 5, but I got mislead by the comment on the code snippet I found on the arduino forum's thread I linked. Actually, I am doing exaclty as the example in page 13 of the user manual. The first writing (0x00) is for the first reserved register. Then, I write (0x05)) to the second register, which set FAST to 0, INT to 1 and LOW to 1. – erenaud Jun 15 '18 at 14:24
0

To sum up this problem : TLV493D configuration work by writing two bytes with I2C. You must begin by writing 0x00, which will be ignored since the first register is reserved. Then, you write a second byte that will actually do the configuration (second register). The three smalest bits enable or disable INT, FAST and LOW mode.

I still don't understand why I am not able to enable INT mode on my Atmega32u4 while it doesn't seem to be a problem on Uno or Mega (on LOW mode). Anyway, two configurations work for me :

0x07 --> INT, FAST and LOW are all enabled

0x01 --> only LOW is enabled

I don't think it's a issue to disable INT. If I understood correctly, it will make the device send an interrupt pulse to request microcontroller reading. If you manage readings by yourself, I don't think you need INT to be enabled.

Many thanks to CodeGorilla for his support.

UPDATE:

I managed to get an Arduino Leonardo. Indeed, all my obsevations on my Atmega32u4 based card are still corrects (writing 0x05 second register make the device disappear from bus, but not with 0x01 or 0x07). But again, it works normally on Uno or Mega... Really odd ! If anyone has an explanation to offer, it would be greatly appreciated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.