Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Thread

Changing ports from output to input

Changing ports from output to input

2007-01-23 by billsputters

What is the considered wisdom regarding changing a port from output to 
input? I am trying to interface to a LCD display and attempting to 
read the busy flag which is available on the data lines of the device. 
I've looked around and some code just changes the DDR as required and 
some set the outputs of the port to all 0's before this so as not to 
get a flase reading. Is this a belts and braces approach or a 
requirement. BTW, I've tried both versions of changing the port over 
and the LCD does not function how I want, but it's a case of 
eliminating errors. Thanks in advance.

Re: [AVR-Chat] Changing ports from output to input

2007-01-23 by David Kelly

On Tue, Jan 23, 2007 at 09:02:43PM -0000, billsputters wrote:
> What is the considered wisdom regarding changing a port from output to
> input? I am trying to interface to a LCD display and attempting to
> read the busy flag which is available on the data lines of the device. 
> I've looked around and some code just changes the DDR as required and 
> some set the outputs of the port to all 0's before this so as not to 
> get a flase reading. Is this a belts and braces approach or a 
> requirement. BTW, I've tried both versions of changing the port over 
> and the LCD does not function how I want, but it's a case of 
> eliminating errors. Thanks in advance.

Just clobber the DDR bits to toggle between input and output. I get CPUs
confused sometimes so check the documentation for "internal pull ups" on
the ports. No need to change the output value to something else unless
the output value in input mode enables pullups that you need. You
shouldn't need internal pullups, "But what do I know? (about your
hardware)".

And that is likely why you are having problems: when you change the
output values you tell the LCD to do something unexpected and its off
doing that rather than the next thing you tell it to do. Make sure your
R/-W, E, and -CS lines are stable and reasonable for changing data line
values when you change the DDR.

-- 
David Kelly N4HHE, dkelly@HiWAAY.net
========================================================================
Whom computers would destroy, they must first drive mad.

Re: [AVR-Chat] Changing ports from output to input

2007-01-23 by Jim Wagner

Several of the data sheets have comments about changing
port direction. If you don't do it "right", you can get an
unwanted single-instruction transient on the port pin.

At the moment, I don't recall the details but it might be
worth checking one of the newer data sheets (such as
Mega48).

Jim


On Tue, 23 Jan 2007 15:15:26 -0600
 David Kelly <dkelly@hiwaay.net> wrote:
> On Tue, Jan 23, 2007 at 09:02:43PM -0000, billsputters
> wrote:
> > What is the considered wisdom regarding changing a port
> from output to
> > input? I am trying to interface to a LCD display and
> attempting to
> > read the busy flag which is available on the data lines
> of the device. 
> > I've looked around and some code just changes the DDR
> as required and 
> > some set the outputs of the port to all 0's before this
> so as not to 
> > get a flase reading. Is this a belts and braces
> approach or a 
> > requirement. BTW, I've tried both versions of changing
> the port over 
> > and the LCD does not function how I want, but it's a
> case of 
> > eliminating errors. Thanks in advance.
> 
> Just clobber the DDR bits to toggle between input and
> output. I get CPUs
> confused sometimes so check the documentation for
> "internal pull ups" on
> the ports. No need to change the output value to
> something else unless
> the output value in input mode enables pullups that you
> need. You
> shouldn't need internal pullups, "But what do I know?
> (about your
> hardware)".
> 
> And that is likely why you are having problems: when you
> change the
> output values you tell the LCD to do something unexpected
> and its off
> doing that rather than the next thing you tell it to do.
> Make sure your
> R/-W, E, and -CS lines are stable and reasonable for
> changing data line
> values when you change the DDR.
> 
> -- 
> David Kelly N4HHE, dkelly@HiWAAY.net
>
========================================================================
> Whom computers would destroy, they must first drive mad.

---------------------------------------------------------------
The Think Different Store
http://www.thinkdifferentstore.com/
For All Your Mac Gear
---------------------------------------------------------------

Re: [AVR-Chat] Changing ports from output to input

2007-01-23 by David Kelly

On Tue, Jan 23, 2007 at 04:31:33PM -0500, Jim Wagner wrote:
> Several of the data sheets have comments about changing port
> direction. If you don't do it "right", you can get an unwanted
> single-instruction transient on the port pin.
> 
> At the moment, I don't recall the details but it might be worth
> checking one of the newer data sheets (such as Mega48).

Thought after posting to mention changing from output to input shouldn't
be of much trauma. No need to change the output values ahead of time.
However when changing from input to output one ought to preload the
register with the values one desires to see on the output. And once
again make sure the control lines to whatever are in appropriate state
to ignore changes data direction.

-- 
David Kelly N4HHE, dkelly@HiWAAY.net
========================================================================
Whom computers would destroy, they must first drive mad.

Re: [AVR-Chat] Changing ports from output to input

2007-01-24 by James Hatley

Hello,

You probably know this but...

I assume you are reading the PINx bit rather than the PORTx bit on input of
data. (After changing the DDRx, of course.)

I always seem to forget to do this since I've always done so much Moto stuff
in the past. It has got me a number of times.

Jim
Show quoted textHide quoted text
----- Original Message ----- 
From: "billsputters" <richardaustin@eircom.net>
To: <AVR-Chat@yahoogroups.com>
Sent: Tuesday, January 23, 2007 1:02 PM
Subject: [AVR-Chat] Changing ports from output to input


What is the considered wisdom regarding changing a port from output to
input? I am trying to interface to a LCD display and attempting to
read the busy flag which is available on the data lines of the device.
I've looked around and some code just changes the DDR as required and
some set the outputs of the port to all 0's before this so as not to
get a flase reading. Is this a belts and braces approach or a
requirement. BTW, I've tried both versions of changing the port over
and the LCD does not function how I want, but it's a case of
eliminating errors. Thanks in advance.

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.