digitalRead not working for atmega644 and mightyCore

I am using Arduino with mightyCore for software development.
I'm debugging a circuit board that has an atmega644 chip and has 3 pushbuttons (UI1, UI2, and UI3).
Each pushbutton is connected to a digital input with internal pullup.
I have verified with a DMM that these inputs are at 5V when pushbutton is not pressed and 0V when pressed.
But in this test program (button.ino) digitalRead always reports 0 whether or not the pushbutton is pressed.

It's hard to believe that a simple function like that isn't working.
Am I overlooking something simple?


// ============================================================================
//  buttons.ino  check digitalRead()
// ============================================================================

#define UI2       PIN_PC2
#define UI1       PIN_PC3
#define UI3       PIN_PC4

// init I/O pins
void iopin_init() {
  pinMode(UI1,      INPUT_PULLUP);
  pinMode(UI2,      INPUT_PULLUP);
  pinMode(UI3,      INPUT_PULLUP);
}

#define BAUD 115200

// startup init
void setup() {
  iopin_init();
  Serial.begin(BAUD);
}

uint8_t button1;
uint8_t button2;
uint8_t button3;

// main loop
void loop() {

  button1 = digitalRead(UI1);
  button2 = digitalRead(UI2);
  button3 = digitalRead(UI3);

  Serial.print(" ");
  Serial.print(button1);
  Serial.print(" ");
  Serial.print(" ");
  Serial.print(button2);
  Serial.print(" ");
  Serial.print(" ");
  Serial.print(button3);
  Serial.print("\r\n");
  delay(500);
}
// ============================================================================
//  buttons.ino  check digitalRead()
// ============================================================================

#define UI2       PC2
#define UI1       PC3
#define UI3       PC4

// init I/O pins
void iopin_init() {
  pinMode(UI1,      INPUT_PULLUP);
  pinMode(UI2,      INPUT_PULLUP);
  pinMode(UI3,      INPUT_PULLUP);
}

#define BAUD 115200

// startup init
void setup() {
  iopin_init();
  Serial.begin(BAUD);
}

uint8_t button1;
uint8_t button2;
uint8_t button3;

// main loop
void loop() {

  button1 = digitalRead(UI1);
  button2 = digitalRead(UI2);
  button3 = digitalRead(UI3);

  Serial.print(" ");
  Serial.print(button1);
  Serial.print(" ");
  Serial.print(" ");
  Serial.print(button2);
  Serial.print(" ");
  Serial.print(" ");
  Serial.print(button3);
  Serial.print("\r\n");
  delay(500);
}

Hi kolaha

Your proposed fix is not correct according to this documentation:

Thanks,

Does a simple blink sketch work?

Yes

Solved by disabling JTAG fuse (changed hfuse from 0X9F to 0xDF)

Refer to this post: [SOLVED] Atmega644 - problem with digital read on pins 24 (D18) and 25 (D19)

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.