Go Down

Topic: INPUT_PULLUP compiling problem with ATtiny4313 (Read 818 times) previous topic - next topic

Zoran Djurisic

I have run into a problem trying to declare a pin as INPUT_PULLUP - the following compiles fine on Nano or Pro Mini, but throws 'INPUT_PULLUP' was not declared in this scope when compiled for ATtiny 4313:

Code: [Select]
pinMode (4, INPUT_PULLUP)

Other modes (INPUT, OUTPUT) compile fine. Trying pinMode (4, 2) gets the code compiled, but the code does not seem to work properly. Looking at the datasheet, ATtiny 4313 seems to have the pull-up resistors the same way the 328p does...

I am using Arduino IDE 1.0.4 with avr-gcc updated from WinAVR2010, and with ATtiny cores from Arduino-Tiny

hiduino

You need to add support for it to the tiny-core files.  I believe INPUT_PULLUP is a newer feature support that was added after tiny-core was developed.

\hardware\tiny\cores\tiny\wiring.h:
Code: [Select]

#define INPUT 0x0
#define OUTPUT 0x1
#define INPUT_PULLUP 0x2


\hardware\tiny\cores\tiny\wiring_digital.c, replace the pinMode function with this:
Code: [Select]
void pinMode(uint8_t pin, uint8_t mode)
{
uint8_t bit = digitalPinToBitMask(pin);
uint8_t port = digitalPinToPort(pin);
volatile uint8_t *reg, *out;

if (port == NOT_A_PIN) return;

// JWS: can I let the optimizer do this?
reg = portModeRegister(port);
out = portOutputRegister(port);

if (mode == INPUT) {
uint8_t oldSREG = SREG;
                cli();
*reg &= ~bit;
*out &= ~bit;
SREG = oldSREG;
} else if (mode == INPUT_PULLUP) {
uint8_t oldSREG = SREG;
                cli();
*reg &= ~bit;
*out |= bit;
SREG = oldSREG;
} else {
uint8_t oldSREG = SREG;
                cli();
*reg |= bit;
SREG = oldSREG;
}
}



Coding Badly


@hiduino, thank you for posting the fix.

I believe INPUT_PULLUP is a newer feature support that was added after tiny-core was developed.


True but not why I have not updated the core.  In any case, it's now fixed.

Zoran Djurisic

#3
May 24, 2013, 11:01 pm Last Edit: May 24, 2013, 11:26 pm by Zoran Djurisic Reason: 1
That's it! Thanks hiduino. And thanks Coding for the tiny cores update!

Go Up