Pages: [1]   Go Down
Author Topic: [SOLVED] Atmega644 - problem with digital read on pins 24 (D18) and 25 (D19)  (Read 980 times)
0 Members and 1 Guest are viewing this topic.
The Netherlands
Offline Offline
Newbie
*
Karma: 0
Posts: 38
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

I'm try to read the state of each switch on a DIP switch.


Code:
void setup(){
pinMode(19, INPUT); // Set pin to input
pinMode(18, INPUT); // Set pin to input
pinMode(15, INPUT); // Set pin to input
digitalWrite(19,HIGH); // enable internal pull-up
digitalWrite(18,HIGH); // enable internal pull-up
digitalWrite(15,HIGH); // enable internal pull-up

if (digitalRead(19)==LOW)
        volumeCtrlLocked=true;
else volumeCtrlLocked=false;
if (digitalRead(18)==LOW)
outputLocked=true;
else outputLocked=false;
if (digitalRead(15)==LOW)
phaseLocked=true;
else phaseLocked=false;
}

The digitalRead on pins 24 (D18) and 25 (D19) always returns LOW for some reason. D15 responds as expected, it only returns LOW when the switch is closed.
It also works fine when I connect the DIP switch to some other digital pins, instead of D18 and D19.

I'm using the Sanguino software and upload the code using an Uno. At first I thought that it might have something to do with the JTAG interface being enabled, but the problem still occurs after disabling it by setting the fuses.

The reason that I want to use this pins is that I have a PCB that connects the DIP switch to these pins, so using other pins in no real option for me.
I must be missing something here...

EDIT: I attached the boards.txt file with the settings of the fuses and other settings as well.

* boards.txt (1.9 KB - downloaded 15 times.)
« Last Edit: December 14, 2012, 07:10:59 pm by corprius » Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I ran this sketch based on yours:

Code:
bool volumeCtrlLocked, outputLocked, phaseLocked;

void setup(){
 
  Serial.begin (115200);
 
  pinMode(19, INPUT); // Set pin to input
  pinMode(18, INPUT); // Set pin to input
  pinMode(15, INPUT); // Set pin to input
  digitalWrite(19,HIGH); // enable internal pull-up
  digitalWrite(18,HIGH); // enable internal pull-up
  digitalWrite(15,HIGH); // enable internal pull-up

  if (digitalRead(19)==LOW)
    volumeCtrlLocked=true;
  else volumeCtrlLocked=false;
 
  if (digitalRead(18)==LOW)
    outputLocked=true;
  else outputLocked=false;
 
  if (digitalRead(15)==LOW)
    phaseLocked=true;
  else phaseLocked=false;
 
  Serial.print ("volumeCtrlLocked = ");
  Serial.println (volumeCtrlLocked, DEC);
  Serial.print ("outputLocked = ");
  Serial.println (outputLocked, DEC);
  Serial.print ("phaseLocked = ");
  Serial.println (phaseLocked, DEC);
}

void loop () { }

Jumpering together pins D18 and D19 worked as expected on my Sanguino board.

My fuse settings are:

Code:
Signature = 0x1E 0x96 0x0A
Processor = ATmega644P
Flash memory size = 65536 bytes.
LFuse = 0xFF
HFuse = 0xDC
EFuse = 0xFD
Lock byte = 0xFF
Clock calibration = 0x84

Note that changing boards.txt doesn't change the fuses on the actual chip unless you re-burn the bootloader.
Logged

The Netherlands
Offline Offline
Newbie
*
Karma: 0
Posts: 38
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks, I did re-burn the bootloader. I`ll try your fuse settings later on today.
Logged

SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 124
Posts: 6634
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
At first I thought that it might have something to do with the JTAG interface being enabled, but the problem still occurs after disabling it by setting the fuses.
this seems like a likely theory.  Are you sure you have the fuse settings correct for disabled JTAG?
Logged

The Netherlands
Offline Offline
Newbie
*
Karma: 0
Posts: 38
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
At first I thought that it might have something to do with the JTAG interface being enabled, but the problem still occurs after disabling it by setting the fuses.
this seems like a likely theory.  Are you sure you have the fuse settings correct for disabled JTAG?

I´m a beginner, so I might have the fuses set wrongly to disable JTAG.

These are all settings:
Code:
atmega644.name=Sanguino W/ ATmega644P

atmega644.upload.protocol=stk500
atmega644.upload.maximum_size=63488
atmega644.upload.speed=57600

atmega644.bootloader.low_fuses=0xFF
atmega644.bootloader.high_fuses=0xD2
atmega644.bootloader.extended_fuses=0xFF
atmega644.bootloader.path=atmega
atmega644.bootloader.file=ATmegaBOOT_168_atmega644p.hex
#atmega644.bootloader.file=ATmegaBOOT_644P.hex
atmega644.bootloader.unlock_bits=0x3F
atmega644.bootloader.lock_bits=0x0F

atmega644.build.mcu=atmega644p
atmega644.build.f_cpu=16000000L
atmega644.build.core=arduino
atmega644.build.variant=standard
Logged

The Netherlands
Offline Offline
Newbie
*
Karma: 0
Posts: 38
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I changed the fuse settings:
Code:
atmega644.bootloader.low_fuses=0xFF
atmega644.bootloader.high_fuses=0xD2
atmega644.bootloader.extended_fuses=0xFD

Now I can use D18 and D19 for reading the dipswitch.

Thanks!
Logged

Pages: [1]   Go Up
Jump to: