FIX : INPUT_PULLUP error/not working on maniacbug 1284/644 cores

The maniacbug mighty1284 core for ATMega1284, which can also be used on ATMega644, was before the introduction of INPUT_PULLUP to the Arduino core.

If you try to use

pinMode(pin, INPUT_PULLUP);

the compiler will throw an error to say that INPUT_PULLUP is not defined.

In order to fix this you need to change a few lines in two files. A copy of each of the amended files is attached to this post

*** No guarantee or warranty is given or implied. Please take a back up of your original files before making any changes ***

In the 1284/644 core file Arduino.h:-

From line 21, replace:-

#define INPUT 0x0
#define OUTPUT 0x1

with

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

In core file wiring_digital.c, in the pinMode function...

at line 35, replace:-

	volatile uint8_t *reg;

with

	volatile uint8_t *reg;
	volatile uint8_t *out;

at line 41, replace:-

	reg = portModeRegister(port);

with

	reg = portModeRegister(port);
	out = portOutputRegister(port);

at line 44, replace:-

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

with

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

On completion of the changes to both files, test that INPUT_PULLUP now works:-

  1. Wire an LED between any pin and Gnd, with a suitable resistor.
  2. Set the pinMode as OUTPUT and digitalWrite HIGH to ensure the LED lights normally
  3. Set the pinMode as INPUT and digitalWrite HIGH to ensure the LED lights dimly (old method of activating pullup)
  4. Set the pinMode as INPUT and ensure the LED does not light
  5. Set the pinMode as INPUT_PULLUP to ensure the LED lights dimly (new method of activating pullup)

If you compile OK and see the correct results for step 2 to 4 above then you now have INPUT_PULLUP functionality inserted into your 1284/644 core successfully..

Arduino.h (5.56 KB)

wiring_digital.c (5.18 KB)

The files seem to compile for 1284 with them in the
/arduino/hardware/mighty1284/cores folder.
Had to completely take the old ones out. Leaving old-Ardiuno.h, old-wiring_digital.c, or prior-Arduino.h, prior-wiring_digital.c in the folder, they kept getting called out with the same pinMode errors! So things wouldn't compile until just Arduino.h and wiring_digital.c were left in the folder.

My computer has a solid state hard drive that is used in concert with the terabyte platter-based hard drive, seems like it was keeping track of the files called out for the compiler thru the name change.

With
pinMode(2, INPUT_PULLUP);
I do not get any error message with uecide 0.8.1c and Mighty board set...

You selected Bobuino as the board type? That was the one that had issues.

I did select Mighty 1284p..

CrossRoads:
You selected Bobuino as the board type? That was the one that had issues.

The Software Serial issue, due to pins_arduino.h, was the Bobuino variant specific one

The INPUT_PULLUP was more general for the shared core across all 1284 variants.