Analog "pinMode(pin, INPUT_PULLUP)" for Atmega168PA

Hi everybody! Tell me, what is the analogue of the "pinMode (pin, INPUT_PULLUP)" command for the ATmega168PA microprocessor? I want to get by with only the C language. I have searched many forums, but have not found the information that interests me.

there isn't any.
pins are INPUT by default and will work fine for analogRead() as well

Really?

Isn't the 168PA only crippled to 16 k Flash, 1 k RAM and 512 EEPROM?

If you are not going to use the Arduino IDE functions you have to set the pin control registers yourself.

Read section 14 of the data sheet and then decide if you really want to do it all yourself.

isn't the question about the need to configure the pin for analogRead() and is anything more than the default needed?

Which pin?

I interpreted the OP ment analogue in the sense "something that is similar or comparable to something else either in general or in some specific detail".

I probably misunderstood the question differently,
like "how to achieve INPUT_PULLUP on an 168"
which is the same as for an 328.

to use a digital pin as an output, the pin needs to be configured as OUTPUT using pinMode. do you need to do same if you want to use the pin as a digital input? or an analog input? do you need to configure the pin differently to use an a digital vs analog input?

no, as far as I know

I thought we were talking about INPUT_PULLUP.

But never mind, I'm out.

Isn't the problem that the pin is being configured "INPUT_PULLUP"? If it is configured that way, won't it always just read the voltage of the pullup resistor and not the analog reading?

To configure an ATmega328p pin with a pull-up, NOT using the Arduino IDE:
set the bit in the appropriate DDR register to make the pin an input. and then set the bit in the matching PORT register to 1 as well.

(This is significantly different than many of the newer chips that have separate "configuration" registers for each of the pins. And also from older chips that lacked any internal pullup capability at all and/or relied on external pull-ups.)

1 Like

It's all in the datasheet starting on page 57:
Atmega168 Datasheet

Why would you want to enable the pullup on a pin you want to take an analog reading from?

I do it, sometimes, when using something like a light dependant resistor or force sensitive resistor. The internal resistor acts as the load resistor. No external resistor required.

1 Like

I've been working with ESP32's too much..... INPUT_PULLDOWN is your best friend sometimes. :smiley:

This is what is needed! Tell me how it will look in code C for pin A5 (use it as a digital input with pulling up the internal resistor).

Well... no... :frowning:
My hint extended about as far as I'm willing to go on something that looks like it might be homework. See the datasheet, and the many links on "Direct port IO"

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.