Pullup Resistors Cannot Be Enabled

For Adafruit customers who seek help with microcontrollers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
PorkRhombus
 
Posts: 30
Joined: Sun Jun 28, 2009 4:29 am

Pullup Resistors Cannot Be Enabled

Post by PorkRhombus »

Greetings one and all.

My otherwise delightful Duemilanove refuses to let me enable the pullup resistors. After perusing the ATmega328P datasheet, I suspect that the PUD bit of the MCUCR register may be set for some reason. If some kind soul could supply a line of assembler to write a zero to the offending bit I would be much obliged.

Ta.

=PR=

mtbf0
 
Posts: 1645
Joined: Sat Nov 10, 2007 12:59 am

Re: Pullup Resistors Cannot Be Enabled

Post by mtbf0 »

it's not assembler, but have you tried

Code: Select all

  MCUCR &= ~(1 << PUD);
though i don't see how it would be set if you haven't set it yourself. have you tried printing the value in MCUCR?

PorkRhombus
 
Posts: 30
Joined: Sun Jun 28, 2009 4:29 am

Re: Pullup Resistors Cannot Be Enabled

Post by PorkRhombus »

No. I have no idea how to do that. Perhaps you could tell me how to print the contents of PUOE and PUOV as well. Thanks.

PorkRhombus
 
Posts: 30
Joined: Sun Jun 28, 2009 4:29 am

Re: Pullup Resistors Cannot Be Enabled

Post by PorkRhombus »

OK ... I figured out how to get the MCUCR values and they are all zero (normal) including PUD.
So I tried sending two pins high using PORTC |= B1100; and guess what: pullups enabled! Which presumably means that the compiler (Arduino IDE 0015) was not correctly handling the digitalWrite commands to these ports. I wonder if anyone else is having this problem and doesn't realize it because they have not tested to see if the pins are actually pulled high.

Further input and comments welcome.

=PR=

mtbf0
 
Posts: 1645
Joined: Sat Nov 10, 2007 12:59 am

Re: Pullup Resistors Cannot Be Enabled

Post by mtbf0 »

may we see the code that didn't work? i don't see anything in the wiring code that would mess things up.

PorkRhombus
 
Posts: 30
Joined: Sun Jun 28, 2009 4:29 am

Re: Pullup Resistors Cannot Be Enabled

Post by PorkRhombus »

// This does not pull analog input 5 high:

void setup()
{
pinMode(5,INPUT);
digitalWrite(5,HIGH);
}

void loop(){}


// But this does:

void setup()
{
pinMode(5,INPUT);
PORTC |= B100000;
}

void loop(){}
Last edited by PorkRhombus on Sun Jun 28, 2009 6:51 pm, edited 1 time in total.

User avatar
westfw
 
Posts: 2008
Joined: Fri Apr 27, 2007 1:01 pm

Re: Pullup Resistors Cannot Be Enabled

Post by westfw »

I don't see any code in 168/328 bootloaders (official Arduino bootloaders, not Adaboot (which I didn't look at)) or core that changes the MCUCR register at all, except for "attach interrupt" which zeros them (actually, it looks like a random value sent to attachInterrupt as "mode" could set PUD to a random value...)

I also don't see a clear statement in the chip datasheet that says the bit defaults to zero, which tends to make me a bit nervous.

mtbf0
 
Posts: 1645
Joined: Sat Nov 10, 2007 12:59 am

Re: Pullup Resistors Cannot Be Enabled

Post by mtbf0 »

analog 5 is digital 19. so what you want is.

Code: Select all

  pinMode (19, INPUT);
  digitalWrite (19, HIGH);

PorkRhombus
 
Posts: 30
Joined: Sun Jun 28, 2009 4:29 am

Re: Pullup Resistors Cannot Be Enabled

Post by PorkRhombus »

Thanks. I don't recall seeing this information anywhere, so I don't feel altogether foolish. On the plus side, I have learned about some lower level programming options AND got to read the data sheet ! I decided not to use the internal pullup anyway because it only pulls up to 4.9V. Thank you to all who took an interest.

=PR=

Locked
Please be positive and constructive with your questions and comments.

Return to “Microcontrollers”