Uno as Duemilanove replacement - Port manipulation problem

Hello,

I’ve bought Uno (as the Duemilanove’s are discontinued) for my project.

I use port manipulation commands (DDRB and PINB) in my project and they are not working anymore on the Uno. As far as I now, there is nothing changed to the digital IO’s.

When I exchanged the Atmel 328 chips, I was able to read the inputs with the Duemilanove board and Uno Atmel chip! So, the Uno Atmel chip seems to be OK. But I was not able to read inputs with the Uno board and the Duemilanove Atmel chip.

Have anybody else experienced this or knows a solution?

This is the code that I’m using:

#include "pins_arduino.h"

int lastDigital = 0x0000;

void setup() {
  DDRD &= B00000011; // 1-2 serial port (don't set) | 3-8 digital IN
  DDRB &= B11000000; // 1-2 digital IN  | 3-5 board ID | 6 sync | 7-8 nothing (don't set)

  Serial.begin(19200);
}
 
void loop() {
  byte temp1 = PIND & B11111100;
  byte temp2 = PINB & B00111111;
  
    int result = 0xf800 | (unsigned(temp1) >> 2) | (temp2 << 6);
  
    if (result != lastDigital) {
      if ((result & 0x00ff) != 0x0000) {
        Serial.write(result >> 8);
        Serial.write(result);   
        Serial.write((byte)0x00);
        Serial.write((byte)0xff);
      }
      
      lastDigital = result;
  }  
}

What do you mean “doesn’t work”?

In terms of providing a connection between the ATmega328 chip and the header pins, there is no difference between an Uno board and Duemilanove board.

James,

"doesn't work": if I set a 5v signal on pin 2, nothing is written over the serial line. This still works on the Duemilanove with the same piece of software.

If I use the arduinolib function digitalRead, everything works fine. But it's to slow for my application.

The schematics of both board are equal regarding the header pins. So, I don't know why it's not working on the Uno. Is there something changed in the bootloader?

The bootloader has nothing to do with your code.

Are you leaving the input pin floating or are you using a pull-down?

For testing, I've put shortly 5v on pin 2 and connected pin 2 to ground. It's working on the Duemilanove board.

I was thinking that my Uno board has a manufacturing issue but I've tested another Uno board and it had the same result.