INPUT_PULLUP

An advanced Arduino-compatible board with ATmega1284P and ATmega32u2 MCUs for experienced users. More RAM than a Mega, but in a convenient Uno-style form factor. [Product page]
Post Reply
bvernham
Posts: 3
Joined: Tue Dec 17, 2013 5:49 pm

INPUT_PULLUP

Post by bvernham » Tue Dec 17, 2013 5:53 pm

For the Godilocks 20 I tried compiling a sketch with I used with the UNO and got the following error:

receive_j1939_log_Serial.ino: In function 'void setup()':
receive_j1939_log_Serial:302: error: 'INPUT_PULLUP' was not declared in this scope

Isn't INPUT PULLUP supported?

feilipu
Posts: 52
Joined: Fri Jul 19, 2013 6:17 am

Re: INPUT_PULLUP

Post by feilipu » Thu Dec 19, 2013 11:37 am

That's unusual. Haven't seen this issue previously.

Can you add a little more code and background to make it easier to diagnose, please?

hiduino
Posts: 12
Joined: Thu Aug 29, 2013 2:17 pm

Re: INPUT_PULLUP

Post by hiduino » Fri Dec 20, 2013 6:59 am

It's not supported in the current core that Goldilocks is based on. If it was based on the mightyp core then it is older than Arduino IDE v1.0.1. Which is when INPUT_PULLUP support was added.

The support was added to the core file wiring_digital.c file.

Current Goldilocks core wiring_digital.c file:

Code: Select all

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;
	}
}
This is what was added from IDE v1.0.1 and up:

Code: Select all

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;
	}
}

bvernham
Posts: 3
Joined: Tue Dec 17, 2013 5:49 pm

Re: INPUT_PULLUP

Post by bvernham » Tue Dec 24, 2013 12:43 am

How do we implement this for the Goldilocks?

Thanks

Bruce

hiduino
Posts: 12
Joined: Thu Aug 29, 2013 2:17 pm

Re: INPUT_PULLUP

Post by hiduino » Tue Dec 24, 2013 5:16 am

If you are comfortable you can modify the file yourself.
Under where your sketch folder is edit this file ../Arduino/hardware/Goldilocks/cores/arduino/wiring_digital.c

Replace the pinmode() routine with the one I posted in my other message.

Also in the same folder edit this file,../Arduino/hardware/Goldilocks/cores/arduino/Arduino.h
Below these lines.

Code: Select all

#define INPUT 0x0
#define OUTPUT 0x1
Add this line in the file.

Code: Select all

#define INPUT_PULLUP 0x2

Post Reply