Go Down

Topic: Using Digital Pins 0 and 1 (PD0, PD1) (Read 1 time) previous topic - next topic

armandas

Apr 18, 2009, 11:46 pm Last Edit: Apr 19, 2009, 10:04 am by armandas Reason: 1
Hi, I have an Arduino Duemilanove with ATmega328P. I need to be able to set low bits of PORTD, but my code doesn't work (leds don't blink).
Code: [Select]
#define F_CPU 16.000E6
#include <avr/io.h>
#include <util/delay.h>

int main(void)
{

   // set PORTD as output
   DDRD = 0xff;

   for(;;)                                    
   {
       PORTD = 0x03;
       _delay_ms(100);
       PORTD = 0x00;
       _delay_ms(100);
   }
   return 0;      
}

Nowhere on the website it says that it is not possible to use these pins (just not recommended). Any ideas?

Thanks!

P.S. not using those pins is not an option.

FusiveResonance

Code: [Select]
   // set PORTB as output
   DDRB = 0xff;


Shouldn't you be setting DDRD and not DDRB

armandas

Sorry, that was missed in this example only. The question remains. Thanks.

mem

#3
Apr 19, 2009, 10:29 am Last Edit: Apr 19, 2009, 10:30 am by mem Reason: 1
I think the reason pins 0 and 1 are not recommended is because they are used by the Serial port.

If you really have to use them you may want to try commenting out the creation of the Serial Object in HardwareSerial.cpp

armandas

#4
Apr 19, 2009, 10:44 am Last Edit: Apr 19, 2009, 10:46 am by armandas Reason: 1
The thing is that I am not using Arduino's IDE. I use avr-gcc to compile and load the code with avrdude. I don't see how HardwareSerial.cpp could be affecting anything. I thought it may be the bootloader or something. That's why I'm here - to find out.

What I do is I try to use Arduino only as a prototyping board (which it is). I hope one day to pop-out the micro and use it in my project. For this I need it to behave like a normal micro.

mem

Pins 0 and 1 are connected through 1k resistors to the serial hardware, that my be affecting your output.

You may be better off with a runtime board that does not have the serial hardware.

armandas

Sounds reasonable. I guess I'll just have to try to assemble the circuit on breadboard. Thanks.

Go Up