Coding on an Attiny 817

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

I'm a noob who's been coding on an Attiny817, and an Attiny104. And a lot of people on here have been really helpful, so thanks a ton.

Why is the coding different for them?

 

For example, to set the user LED on, for the 817 you go:

 

PORTC_DIR = (1 << UserLED);

PORTC_PIN0CTRL = 0xff;

 

whereas, for the 104, it seems to be the more oft-used::

 

DDRB = (1 << UserLED);

PORTB = (1 << UserLED);

 

I've heard the term floated around that the 817 doesn't use memory-mapped registers, so it's different.... is that it?

Why the heck they make the 817 different lol? since there's so much open-source code and resources available for the 104's style of coding. 

 

 

 

Last Edited: Sun. Jun 11, 2017 - 05:25 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

a tiny 104 is based on a "normal" AVR, from the time where efficiently and small code matter.

 

the 817 is an xmega cut down, it's more module build, and have many more options you can benefit from when it becomes more complex.

 

the problem is that instructions like in and out barely work on a 817, and yes registers aren't memory mapped, but that is not your problem here. 

 

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

You may find that:

PORTC_DIR = (1 << UserLED);
PORTC_PIN0CTRL = 0xff;

turns on your LED connected to Port C, however setting PORTC.PIN0CTRL/ PORTC_PIN0CTRL to 0xFF, according to page 157 of the datasheet, inverts the IO, enables the pull-up, and all three of the ISC bits appears to come under reserved. So my guess would be that the pull-up doesn't get enabled since you have set the pin to an output in the previous line, but the pin does get inverted, thus setting the pin high and consequently turning on your LED.

A better way of turning on your LED would be...

PORTC_DIR = (1 << UserLED);
PORTC_OUT = (1 << UserLED);

however you can even further improve on this. As sparrow2 mentioned the 817 is a bit like a condensed down Xmega, so you can access the registers like you would an Xmega i.e using the SET, CLR & TGL register exentsions, and using the instances PORT_T of PORT_t. For example:

 

PORTC.DIRSET = UserLED;
PORTC.OUTSET = UserLED;

The great thing about the Xmega style code is that you can write generic peripheral code, as opposed to code that's specific to a particular instance of a peripheral, and simply pass in pointers to instances of that particular peripheral's typedef. For example for IO you could have:

void initPort(PORT_t *port, uint8_t dir, uint8_t out) {
    port->DIR = dir;
    port->OUT = out;
}

Then in use you could do...

initPort(&PORTC, UserLED, UserLED);
Last Edited: Mon. Jun 12, 2017 - 05:18 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I've been wondering where to find resources for the 817's style of coding for so long and now I know haha. Thanks a ton. And thanks for the coding tips