Pages: [1]   Go Down
Author Topic: INPUT_PULLUP compiling problem with ATtiny4313  (Read 696 times)
0 Members and 1 Guest are viewing this topic.
California, USA
Offline Offline
Newbie
*
Karma: 1
Posts: 39
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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
Logged

Wahiawa, Hawaii
Offline Offline
God Member
*****
Karma: 29
Posts: 582
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#define INPUT 0x0
#define OUTPUT 0x1
#define INPUT_PULLUP 0x2

\hardware\tiny\cores\tiny\wiring_digital.c, replace the pinMode function with this:
Code:
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;
}
}

Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 199
Posts: 12768
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


@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.
Logged

California, USA
Offline Offline
Newbie
*
Karma: 1
Posts: 39
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That's it! Thanks hiduino. And thanks Coding for the tiny cores update!
« Last Edit: May 24, 2013, 04:26:26 pm by Zoran Djurisic » Logged

Pages: [1]   Go Up
Jump to: