ATTINY1616 Port Pin write

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

Hello,

 

I am using an ATTiny1616 and when I write to a Port (PORTA_OUTSET = 0x01),  Only the first bit changes to a 1 and all other bits remain unchanged.  In order to change the other bits to "0",  I first have to do a PORTA_OUTCLR = 0xFF.  Is there a way to write a 0x01 to PORTA in general where it will change all 8 bits accordingly to save on Instructions?

 

Thank you,

 

Dave

This topic has a solution.
Last Edited: Fri. Jun 8, 2018 - 06:02 PM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Use the PORTA->OUT field to write the whole OUT register.

 

 - OUTSET will SET all bits in OUT that are set in OUTSET

 - OUTCLR will UNSET all bit in OUT that are set in OUTCLR

 - OUTTGL will CHANGE/TOGGLE all bit in OUT that are set in OUTTGL

 

Basically, OUTSET/OUTCLR/OUTTGL are there to do 'atomic' operations on OUT (and same for IN and DIR)

:: Morten

 

(yes, I work for Atmel, yes, I do this in my spare time, now stop sending PMs)

Last Edited: Fri. Jun 8, 2018 - 05:08 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

dadams8355 wrote:
when I write to a Port (PORTA_OUTSET = 0x01),  Only the first bit changes to a 1 and all other bits remain unchanged

Which is exactly what the datasheet says should happen:

http://ww1.microchip.com/downloads/en/DeviceDoc/40001893B.pdf

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am a novice with the programming of the ATtiny 1616 ....

Actually, I have problems with the configuration of the ports as inputs & outputs ...

Please, can you help me with an example in "C".

 

Thank you.

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

The names to use are in the datasheet and also iotn1616.h

 

Just build an "empty" program that has #include <avr/io.h> then look under "external dependencies" and you will see ioth1616.h listed there so it's then easy to edit it and study the contents.

 

BTW note these new tiny models are really small Xmega chips so the naming follows Xmega standard practice so for a port such as PortB the basic register names will be PORTB_DIR, PORTB_OUT and PORTB_IN. Similarly for other ports. 

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

:: Morten

 

(yes, I work for Atmel, yes, I do this in my spare time, now stop sending PMs)

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

So, we can officially refer to Xmega documentation for the new tiny0, tiny1, and mega0 families?

 

Jim

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

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

No, but the new devices uses the XMEGA header format

:: Morten

 

(yes, I work for Atmel, yes, I do this in my spare time, now stop sending PMs)

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

Sorry, should have been more careful. What I meant was use of Xmega docs for managing register access, the struct system, and such. Much the same way that the basic "principles" documents apply across the standard mega and tiny families. 

 

Thanks

Jim

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

Last Edited: Sat. Jun 23, 2018 - 03:55 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ah, yes

:: Morten

 

(yes, I work for Atmel, yes, I do this in my spare time, now stop sending PMs)