PORTD.OUT Usage scenario

Go To Last Post
11 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

How to store the values of any PORT using the OUT keyword?..and compare the values store in them with a another port using variable?

 

Im using atxmega a3bu.

Nitin Shenoy

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

OUT writes to one of the special function registers in low memory space. To get the value of a PORT, you DO NOT use OUT.

 

The rest is left as an exercise for the student. ONE of the things you can do is read the document about the AVR instruction set. For this document, Google is your friend.

 

Jim

 

 

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

Last Edited: Thu. Jan 10, 2019 - 06:23 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Can you tell me how to read the contents of the Port?.. Is it using IN...and i need to know how to compare the lower values if the PORT.. It'll be great if you helped.. Thank you.

Nitin Shenoy

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Look, YOU can find that out, for yourself, by looking at the instruction set document. Nobody here will tell you such basic information that you can easily find on your own. We DO NOT do student's work for them.

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes, you can read PORTA.OUT if you want. It holds the value that you wrote to the output driver latch.
If you want to read the input value use PORTA.IN. It reflects the current value on the input pins.
.
In other words PORTA.OUT is the same as a Mega PORTA.
And PORTA.IN is the same as PINA
.
Note that you can access Xmega ports with VPORT registers. The Xmega has impressive port driver speed.
.
David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Key to all this is also PORTA.DIR. You have to set this first. Any 1 bits will be output, any 0 bits will be input. You would tend to read the inputs by checking the relevant bits in PORTA.IN and you would drive any outputs by setting their bits in PORTA.OUT

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sorry, I confused this one with:

 

https://www.avrfreaks.net/forum/...

 

And thought the OP was talking about assembler. 

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Clawson.

 

Since you mentioned this.  Do we need to setup anything else prior to the I/O registers such as the DIR register?  For example, do we need to setup the PINnCTRL for a specific pull-up, pull-dn, etc etc configuration?  Or just setup the DIR, then output to the pin using OUT, or read the pin using IN? 

 

Reason I am asking, I am using the xmega256C3 micro, and I have read the datasheet multiple times and doing exactly what it says, but I am having issues reading switches attached to PORTA and PORTB.  The switches are pulled-up externally to a 3.3V rail, yet the when I run the program in "debug" mode, the ports show some weird numbers and not 0xFF, because I am expecting 0xFF.  The only thing I haven't done is check and make sure my PCB is not having electrical issues and I am not getting the true pull-up to 3.3V. 

 

Any ideas?

Thank you.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

YES, you need to configure the port pins before you use them. Direction, pull-up or pul-down, all that, needs attention, first. 

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I don't know xmega, but on regular megas

there is an input synchronizer which delays

any pin changes by one clock cycle.  So if

you change some outputs which are expected

to change the value of some inputs, you need

to include a NOP delay before you read those

pins.

 

--Mike

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

avr-mike wrote:

I don't know xmega, but on regular megas

there is an input synchronizer which delays

any pin changes by one clock cycle.  So if

you change some outputs which are expected

to change the value of some inputs, you need

to include a NOP delay before you read those

pins.

 

--Mike

 

 

 

Thanks for the reply Mike.  But I am not changing any registers.  So I set them up early in the code, as matter of fact, outside the "main" function, I have an initialization function, that I call from in "main" which simply sets up all the registers needed and what not.  Then I start reading the pins using PORTx_IN macro.  And here where I noticed something is not right with the pins. 

 

Regards.