0
\$\begingroup\$

Hello I am currently trying to use my atmega88p micro-controller to display something on the SSD1306 OLED display. In the attached image you can see my setup to connect the mcu to the display. I tested numerous libraries like AVR-OLED-SSD1306-IIC-DRIVER that all did not work. After debugging with a LED that I integrated into my setup, I found out that the code always hangs when trying to use the Two Wire Interface (TWI) to connect to the display. The following code illustrates where the program hangs in all the libraries I tested and during the attempts of writing some code on my own:

TWCR = (1 << TWEN) | (1 << TWSTA) | (1 << TWINT);
while (!(TWCR & (1 << TWINT))); // <-- hangs here

By activating and deactivating the pins inside the while loop that my LED was connected to, I noticed that the loop never finishes.

After a online research I found a post that stated the SDA and SCL lines might be pulled low somewhere indicating that my pull-up resistors might not be chosen correctly. I am using two 1kΩ resistors as pull-ups.

I am very new to mcu developing therefor I want to apologies in advance if my setup has a obvious flaw that cause the TWINT never to be cleared.

I have tested if the display is working using a arduino nano with the examples for the display in the arduino IDE and everything worked as expected even without using external pull-up resistors.

With the minimal knowledge that I have I currently believe the setup is missing something that results it the mcu to be unable to finish the transmission of the START condition.

Setup on Breadboard connecting atmega88p to SSD1306 using 3,3V Power on VCC enter image description here

\$\endgroup\$
5
  • \$\begingroup\$ It looks like the value of TWCR is never updated inside the while loop. I assume that's not intentional, right? \$\endgroup\$
    – Hearth
    Commented Sep 28, 2023 at 4:36
  • \$\begingroup\$ Hey @Hearth that is the intended way to use the Two wire interface where the TWINT bit is supposed to be set by the hardware as soon as the transmission is finished. Datasheet Page 220 there is also a code example on page 232. The loop is a way for the program to check when the hardware finishes the transmission of the start condition. \$\endgroup\$
    – Linus S.
    Commented Sep 28, 2023 at 7:26
  • \$\begingroup\$ Check the states of SDA and SCL with an oscilloscope or a multimeter. The start condition will only succeed when both SDA and SCL are high. I would also double check that the pins used for SDA and SCL are properly configured for IIC operation (i.e. the pins are configured to be controlled by the IIC controller, and that they are open drain). \$\endgroup\$ Commented Sep 28, 2023 at 13:45
  • \$\begingroup\$ Thank you for that answer @SteveMathwig. I will check as soon as I can get my hands on the equipment. I wasn't aware of the term "open drain" and am still not entirely sure if I understand correctly how to configure SDA and SCL to be open drain. After some research I wanted to ask if it is correct that I just set the corresponding bits (Bit 4 and 5) in PORTC to make them open drain? \$\endgroup\$
    – Linus S.
    Commented Sep 28, 2023 at 21:02
  • \$\begingroup\$ Configuring the port pins for SDA and SCL "should" automatically make the pins open drain (called HI-Z in that datasheet). You can double check by checking the port settings after configuring the pins. \$\endgroup\$ Commented Oct 2, 2023 at 14:25

1 Answer 1

0
\$\begingroup\$

there are a few things I noticed with your setup (looking at your image).

It's unclear to me where the 3.3V are supplied on the breadboard. It isn't particularly clear for me wether it is the blue jumper cable or the dark green one. I'm assuming 3.3V are supplied over the blue jumper cable. (Switching them up may be a source of error)

First of all you don't seem to power your board correctly. Looking at the pinout in the datasheet, there are two power supply pins. VCC and AVCC. screenshot of pinout from the datasheet

You seem to only provide 3.3V to the AVCC-Pin (Pin 20), which, according to the datasheet is for the ADC. description of the AVCC pin from the datasheet

You may want to connect 3.3V also to the VCC-Pin (Pin 7).

Also please try to connect 100nF bypass capacitors to the supply pins.

Maybe those things are already fixing your problem. If not, you can try 4k7 Ohm resistors as pull ups. The code doesn't seem to be the issue. But it could be, that the TWINT Flag is never set, which would be the reason the processor is stuck in an endless loop.

\$\endgroup\$
6
  • \$\begingroup\$ Thanks alot @EeEmDee, I connected the VCC-Pin to the 3.3V. Unfortunatly I do not have either 100nF capacitors nor 4k7 ohm resitors, but I will order some. Do I just connect the capacitors to VCC and ground and AVCC and ground? \$\endgroup\$
    – Linus S.
    Commented Sep 29, 2023 at 21:33
  • \$\begingroup\$ @LinusS. did it work with only vcc connected? alternativley you can connect some resistors in series, depending on what you have laying around. \$\endgroup\$
    – EeEmDee
    Commented Sep 30, 2023 at 8:15
  • \$\begingroup\$ it did not work with just connecting Vcc. \$\endgroup\$
    – Linus S.
    Commented Sep 30, 2023 at 19:24
  • \$\begingroup\$ @LinusS. all right. when you can, try to use some higher value pull up resistors. whatever you have laying around between 2k and 10k. the 100nF are connected like you said. one end on vcc the other to gnd, and the other respectively for avcc. btw pls share your whole code or a minimal example, which you have tried and failed with. \$\endgroup\$
    – EeEmDee
    Commented Sep 30, 2023 at 19:41
  • \$\begingroup\$ I apologize for my delayed response. I met a friend yesterday who gave me an ATmega88 instead of an ATmega88P. Surprisingly, my initial setup worked perfectly with the ATmega88. Unfortunately, I had broken one of the pins on the MCU shown in the initial picture. I decided to replace it with a new ATmega88P and tried the setup again, and it worked flawlessly this time too. The only difference between my initial picture and the current setup is the extra line I added to connect it to Vcc, following your instructions. Thanks for your guidance! \$\endgroup\$
    – Linus S.
    Commented Oct 5, 2023 at 20:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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