ATTINY1616 Port Pin write

Go To Last Post
3 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...