I2C and USB conflict on Atmega32u4 with Leonardo bootloader

Hello,

I am working on a project that involves an Atmega32u4 connected to an I2C display. The 32u4 has the Arduino Leonardo bootloader installed, and is attached to a bare breakout board, as shown here.

Uploading over USB and running various code on it works just as expected so far, as well as USB CDC Serial. Trying to communicate with the display over I2C has led to a problem, however.

Running the following code,

#include "U8glib.h"

U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NO_ACK);

void draw(void) {
  // graphic commands to redraw the complete screen should be placed here  
  u8g.setFont(u8g_font_unifont);
  //u8g.setFont(u8g_font_osb21);
  u8g.drawStr( 0, 22, "Hello World!");
}

void setup(void) {
}

void loop(void) {
  // picture loop
  u8g.firstPage();  
  do {
    draw();
  } while( u8g.nextPage() );
  
  // rebuild the picture after some delay
  delay(50);
}

...results in the device locking up and other unexpected results. Windows will then complain that the USB device has failed/has been disconnected. However, when using the same code on an Arduino Uno, everything works as expected. This problem is not limited to this display either. I have also tested a DS1307, and experienced the same problem.

After lots of experimentation, I found that not connecting the device to USB results in I2C working as expected. (the device was connected to power only, no USB data lines) I have also attempted installing Adafruit's Atmega32u4 breakout bootloader on the device. Unfortunately, it still resulted with the same exact situation. Since USB communications is one of the requirements of this project, I am unable to simply do away with it.

So basically, I2C and USB do not work at the same time on my Atmega32u4. Any help with solving this or any ideas would be greatly appreciated.

Hi

Are there pull-up resistors on the I2C bus?
It might be worth to try to add pull-ups (4.7K Ohm) and check whether this will improve the situation.

Oliver

Unfortunately, adding pull up resistors does not improve the problem. I have tested 4.7K resistors like you recommended, 10K, 22K, and 47K. (most likely not necessary, but you never know)

hmmm... then i also have no other idea.

Oliver

Thank you anyways for the help.

After more testing and experimentation though, I have finally found a solution. It seems that the atmega32u4 will provide a stable I2C and USB connection only if it is being powered off of 3.3 volts. Any connected I2C devices must be going off the same voltage as well.

You think something so simple would be outlined in the datasheet. :~ (either that, or I got a somewhat defective chip)

Saw the same problem with ProMicro design using the Sparkfun boot loader running at 5V. The design is reading a 9534 I2C I/O expander. The code uploaded and then the device disappeared from the IDE. Windows showed it as an unrecognized device. I burned in a new boot loader and the device was discoverable. I could consistently cause this failure.

I checked the code closely and noticed it did not have wire.begin() in the setup. I added wire.begin() and everything is now working normally.

Can't say why the wire.begin() fixed this issue but it did.