Pages: [1]   Go Down
Author Topic: Using Digital Pins 0 and 1 (PD0, PD1)  (Read 994 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 4
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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.
« Last Edit: April 19, 2009, 03:04:21 am by armandas » Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 175
---
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Shouldn't you be setting DDRD and not DDRB
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 4
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6252
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
« Last Edit: April 19, 2009, 03:30:17 am by mem » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 4
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: April 19, 2009, 03:46:25 am by armandas » Logged

London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6252
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

0
Offline Offline
Newbie
*
Karma: 0
Posts: 4
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1]   Go Up
Jump to: