Pages: 1 [2]   Go Down
Author Topic: Digital Write D0 & D1 LOW doesn't drive the pin low  (Read 2000 times)
0 Members and 1 Guest are viewing this topic.
Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

nr Bundaberg, Australia
Online Online
Tesla Member
***
Karma: 126
Posts: 8472
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Rob Gray aka the GRAYnomad www.robgray.com

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 74
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

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

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

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

Pages: 1 [2]   Go Up
Jump to: