AtTiny404 port manipulation

Hi there.
I am working on a project that involves using the AtTiny404.
It only has 4KB of program storage space, which is not enough for my code.
I find that Arduino creates a lot of overhead with its versatility of functions. Therefore, it seems like a good idea to use direct port manipulation and only set things that are really needed. The problem is that I'm a bit lost on the direct port manipulation so I'm hoping someone can help me out here.

I am not sure how to set up and use PWM on PB0, PB1 and PB2. Another thing is to detect long and short button presses - perhaps this could be achieved by keeping the millis() functionality.

Thanks in advance for your help

It is a good learning exercise to start with a poorly specified microcontroller (MCU). The Attiny404 is one of the Tinyavr 0-series microcontrollers. To use it with Arduino you need a board package, say: GitHub - SpenceKonde/megaTinyCore: Arduino core for the tinyAVR 0/1/2-series - Ones's digit 2,4,5,7 (pincount, 8,14,20,24), tens digit 0, 1, or 2 (featureset), preceded by flash in kb. Library maintainers: porting help available!
Start with a sketch which blinks a LED. You'll soon have to get familiar with the data sheet for this MCU.

I guess that this is school work so you should show that you have tried things before getting help here.

A blink sketch using direct port manipulation may look something like this:

#include <util/delay.h>   // must be after #define F_CPU
  
void setup() {
  PORTA.DIRSET = PIN2_bm;  // pinMode( led , OUTPUT);  PA2 package pin 12
}

void loop() {
  PORTA.OUTSET = PIN2_bm;  // digitalWrite(led, HIGH);  
  _delay_ms(100) ;  // delay(100);   
  PORTA.OUTCLR = PIN2_bm;  // digitalWrite(led, LOW); 
  _delay_ms(900) ;    // delay(900);                       
}
1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.