Pages: [1]   Go Down
Author Topic: FIX : INPUT_PULLUP error/not working on maniacbug 1284/644 cores  (Read 340 times)
0 Members and 1 Guest are viewing this topic.
UK
Offline Offline
God Member
*****
Karma: 17
Posts: 568
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

Code:
#define INPUT 0x0
#define OUTPUT 0x1

with

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

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

at line 35, replace:-

Code:
volatile uint8_t *reg;

with

Code:
volatile uint8_t *reg;
volatile uint8_t *out;

at line 41, replace:-

Code:
reg = portModeRegister(port);

with

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

at line 44, replace:-

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

with

Code:
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 - downloaded 14 times.)
* wiring_digital.c (5.18 KB - downloaded 31 times.)
« Last Edit: December 24, 2013, 06:20:14 pm by tack » Logged

Global Moderator
Boston area, metrowest
Online Online
Brattain Member
*****
Karma: 518
Posts: 26371
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Rapa Nui
Offline Offline
Edison Member
*
Karma: 60
Posts: 2064
Pukao hats cleaning services
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Global Moderator
Boston area, metrowest
Online Online
Brattain Member
*****
Karma: 518
Posts: 26371
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Rapa Nui
Offline Offline
Edison Member
*
Karma: 60
Posts: 2064
Pukao hats cleaning services
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I did select Mighty 1284p..
Logged

UK
Offline Offline
God Member
*****
Karma: 17
Posts: 568
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1]   Go Up
Jump to: