Using port register D

Just a (probably stupid) question :

I'm trying to use the port register D to read/set the analog pins 0 to 7 (with DDRD, PORTD and PIND instructions).

In The Reference page "Port Registers" I read :

"It would be very easy to accidentally cause your serial port to stop working by changing pin 0 into an output pin! Now that would be very confusing when you suddenly are unable to receive serial data, wouldn't it?"

So, pins O ("RX") and 1 ("TX") appear to be be particular. What could exactly happen if my code set pin 0 into an output pin (or set pin 1 into an imput pin ?) And how could I fix the serial communication problem mentionned ?

If it's an output pin then you can't receive anything. You could switch it back to an input pin and it will resume normal operation.

These kinds of port operations should only be done when you really need the port function. 99% of the time the standard digitalWrite() or fastDigitalWrite() are better. You make your code harder to read and much harder to transfer onto new hardware when you buy an Arduino Zero or Mega.

I'm trying to use the port register D to read/set the analog pins 0 to 7

I hope you meant "digital pins 0 to 7" - the analog pins are on port C.

I also set pins 0-7 as outputs. I use them for audio output.

I saw the warning you're talking about. (Scary). But nothing bad happened.

I think when you boot an updated sketch, the reset function properly sets pins 0 & 1 back to their original condition so you can upload your new sketch. The warning simply meant you won't be able to use these pins as your serial port while the sketch is running.

When you want to write data to a port do NOT do it like this

PORTD = B11001100;
because that changes all the pins

Instead use

PORTD &= B0000011;
to clear certain pins to 0. ANDing with a 1 won't change a pin

and use

PORTD |= B11111100;
to set certain pins to 1. ORing with a 0 won't change a pin

...R
PS - hope I have that the correct way round