jass199012
Posts: 4
Joined: Sun Nov 24, 2019 1:20 pm

GPIO connection with ATmega328p

Sun Nov 24, 2019 2:07 pm

Hi,

I have been using a custom board with my Raspberry Pis, which controls the power to the Pi and adds some other trivial features. The board uses an ATmega328p microcontroller, with its digital pins connected to six GPIO pins of the Pi. ATmega runs on 3.3V and grounds of both ATmega and Pi are connected. Part of the circuit showing the connections:
ChnBoard.jpg
ChnBoard.jpg (186.88 KiB) Viewed 477 times
Here, for example, the GPIO27 is output from Pi and input to ATmega's PD5, and GPIO22 is input to Pi from ATmega's PD6. I am using both these connections as simple flags to communicate the state of each device. So a high GPIO27 tells the ATmega that the Pi is running and a high PD6 tells Pi to initiate a shutdown. The Pi reads GPIO22 (PD6) using a Python script:

Code: Select all

gpio.setup(STATUS_IN, gpio.IN, pull_up_down=gpio.PUD_DOWN)
This board has been working fine for me for many years now (on Pi 2B, 3B). Now, while revising the schematic, I was able to eliminate some pull down resistors connected to ATmega, but I am not able to figure out if removing the ones (shown here) connected to the lines between ATmega and Pi would work or not. I am already using the internal pull down in the Pi so I think it should work. But I would really appreciate some guidance before I finalize the new board for fabrication.

User avatar
DougieLawson
Posts: 38826
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: GPIO connection with ATmega328p

Sun Nov 24, 2019 3:07 pm

The Atmel processor doesn't run at 3V3 if you connect it to pin#2 or #4 on your Raspberry. It WILL run at 5V and connecting any GPIO back from the Atmel to the Raspberry could fry the Raspberry. So be very careful what you connect to Vcc on the Atmel.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

mattmiller
Posts: 2233
Joined: Thu Feb 05, 2015 11:25 pm

Re: GPIO connection with ATmega328p

Sun Nov 24, 2019 3:24 pm

The Atmel processor doesn't run at 3V3
It will run at 3V3 - just not at high clock speeds

User avatar
DougieLawson
Posts: 38826
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: GPIO connection with ATmega328p

Sun Nov 24, 2019 3:38 pm

SO if you run it at 5V you have to buffer any connections between your Atmel and your Raspberry or you WILL SHOOT YOUR RASPBERRY STONE COLD DEAD.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

mattmiller
Posts: 2233
Joined: Thu Feb 05, 2015 11:25 pm

Re: GPIO connection with ATmega328p

Sun Nov 24, 2019 4:02 pm

The OP says they are running the 328 from a 3V3 supply

So there isn't a 5V issue at stake here

jass199012
Posts: 4
Joined: Sun Nov 24, 2019 1:20 pm

Re: GPIO connection with ATmega328p

Mon Nov 25, 2019 8:00 am

The Atmel processor doesn't run at 3V3 if you connect it to pin#2 or #4 on your Raspberry. It WILL run at 5V and connecting any GPIO back from the Atmel to the Raspberry could fry the Raspberry. So be very careful what you connect to Vcc on the Atmel.
SO if you run it at 5V you have to buffer any connections between your Atmel and your Raspberry or you WILL SHOOT YOUR RASPBERRY STONE COLD DEAD.
ATmega328p runs on 3V3 at 8MHz clock using internal clock or using 8MHz external crystal (you just have to set the microcontroller fuses appropriately). And the microcontroller is not connected to Pi's 5V line. In fact, as mentioned in my question, the ATmega328p controls the power to the Pi. So if I power the ATmega328p from Pi's pins, both devices would control power to each other, and none of them would ever switch on :). The microcontroller is powered by a linear regulator (LM1117 3.3V). This was a deliberate design choice in order to get rid of level shifters.

My problem is not related to interfacing of logic levels; I can handle that.
My question is regarding the six resistors in part of the circuit I attached here. I am trying to eliminate these components (and few others not shown here) in order to make room for an I2S DAC IC on the same board. I don't know if the Pi would expect an open drain configuration at the other end if I remove the external pull downs. In my theory it should not, since the external pull down are doing the same thing as internal pull downs, but as I said I am not sure, and I could not find anything online that would help me decide.

sparkyhall
Posts: 166
Joined: Mon Aug 27, 2012 9:14 am

Re: GPIO connection with ATmega328p

Mon Nov 25, 2019 8:48 am

If you have configured the GPIO for internal pull-down then there is no need for the external pull-down resistors. The only thing you need to consider is is the internal 50k(ish) pull-down is enough for your use case.

jass199012
Posts: 4
Joined: Sun Nov 24, 2019 1:20 pm

Re: GPIO connection with ATmega328p

Mon Nov 25, 2019 9:10 am

If you have configured the GPIO for internal pull-down then there is no need for the external pull-down resistors. The only thing you need to consider is is the internal 50k(ish) pull-down is enough for your use case.
Thanks sparkyhall.
In current configuration, the effective resistance is around 8K (50K internal and 10K external in parallel). After I remove the external resistors. the effective would be 50K. Do you think it would have any impact on Pi's GPIOs other than reduced speed of state change? In my case, speed is not of much importance as each of these pins acts as a simple unidirectional flag.

sparkyhall
Posts: 166
Joined: Mon Aug 27, 2012 9:14 am

Re: GPIO connection with ATmega328p

Mon Nov 25, 2019 9:45 am

It'll be fine, just keep connecting cables as short as possible, I would go for < 150mm.

jass199012
Posts: 4
Joined: Sun Nov 24, 2019 1:20 pm

Re: GPIO connection with ATmega328p

Mon Nov 25, 2019 9:51 am

The PCB tracks would be short as the board complies with the HAT specifications. Thanks for the help. Those resistors are finally going to retire! :)

Return to “General discussion”