Go Down

Topic: Digital Write D0 & D1 LOW doesn't drive the pin low (Read 2699 times) previous topic - next topic

Nick Gammon

We can explain the 17 mA that I measured on D1, because if the LED had a 1.9V voltage drop, then I = (5 - 1.9) / 150 which gives about 20 mA. Close enough. And this is because once you initialize the serial port, it is the job of the UART to keep the Tx line high unless it is sending something.

But what about the Rx line? (D0). That's an input, right? Well it's an input on the Atmega328, but an output on the Atmega8U2 USB interface chip. However it goes through a 1K resistor before hitting D0. Now the Atmega8U2 doesn't know whether or not the "main" chip is listening for serial data, so it has to keep that pin high (M8TXD). So, I = (5 - 1.9) / (1000 + 150) giving 2.7 mA.

Now since I measured 2.67 mA going through the LED that agrees exactly with the theory.

But what if you set the pinMode? Doesn't that override the USART? Well, no. According to page 197 of the datasheet:

Quote
Bit 4 - RXENn: Receiver Enable n

Writing this bit to one enables the USART Receiver. The Receiver will override normal port operation for the RxDn pin when enabled.

Bit 3 - TXENn: Transmitter Enable n

Writing this bit to one enables the USART Transmitter. The Transmitter will override normal port operation for the TxDn pin when enabled.


So in other words, once you enable serial comms, the "normal operation" of D0 and D1 is overridden.

And even if you don't, you have to contend with D1 being driven high by the Atmega8U2 chip (through the 1K resistor).
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Graynomad

Quote
The Receiver will override normal port operation for the RxDn pin when enabled.

Interesting and thanks Nick. I guess that's what data sheets are for eh?

______
Rob
Rob Gray aka the GRAYnomad www.robgray.com

irethedo

Is there a way to turn the Serial functions off and force the atmel part to use pins D0 & D1 exclusively as an input or output instead of  RXD or TXD or snything else for that matter?

Thanks for the tips everyone... this issue has me a little befuddled to say the least...

Nick Gammon

Don't use Serial.begin().

But remember what I said above about the Rx line being pushed high by the USB chip. Maybe find another way.

Of course, if you have a "bare bones" board (not a development board like the Uno) then you won't have this problem.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Nick Gammon


Thanks for the tips everyone... this issue has me a little befuddled to say the least...


The board is designed to be easy to use. Hence the USB interface. You pay a price for that ease of use.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Go Up