Direct Port Manipulation #347
Replies: 1 comment
-
The ATtiny3216 is a modern AVR, (specifically a tinyAVR 1-series). Like all modern AVR parts (all AVR devices released since 2016) they use a different structure for the port registers. On the"modern" AVR devices (not official word. I asked my contact in microchip what they call these two broad families of parts (pre-2016/classic and post=2016 woth all the new goodies). He indicated that they didn't have a word, but were talking about it internally because it was b ecoming evident that they need one, which I could have told them in 2014 when the new parts were still diagrams on whiteboards.)... those devices have 2 sets of registers. There are the "VPORTx registers - VPORTx.IN, VPORTx.OUT, VPORTx.DIR, VPORTx.INTFLAGS, and there are the full service PORTx registers Writing to the VPORTx.IN toggles the VPORTx.OUT just like on classic devices (though the pullup is not controlled in the same way -for that you need to use the full fledged PORTx registers). The VPORTx registers are located in the "low I/O space" so you can do VPORTA.OUT |= 1 << x; (where x is constant known at compiletime) and it will compile to a single sbi instruction which executes in a single clock cycle (if that same line is compiled for an unknown value of x that is between 0 and 7, it's like 20-24 bytes of flash and (Because of a mini loop in the middle) I counted around 40 clock cycles to execute it! Note that the ATtiny3216 is not related to ATTinyCore - it is supported by megaTinyCore over here - https://github.com/SpenceKonde/megaTinyCore/discussions and there is a page in the documentation going over this: https://github.com/SpenceKonde/megaTinyCore/blob/master/megaavr/extras/DirectPortManipulation.md |
Beta Was this translation helpful? Give feedback.
-
I've referred to the Port Manipulation reference on the Arduino documentation, and am intending to use the said methods in my latest project. Here is the page in question (https://www.arduino.cc/en/Reference/PortManipulation) and here is the code I've written:
I cannot compile my code when the Arduino IDE is set to
Boards > megaTinyCore > ATtiny3216/.../406 (Optiboot)
. I am intending to deploy to the ATtiny3216 using a Serial interface with another Arduino. I tested compiling the code with the board type set to Uno, and it worked, however I don't really care because I'm not using the Uno for my project, I simply used that fact to narrow down cause of the error (which is'PORTB' was not declared in this scope
and a handful other similar errors) to a misunderstanding of this library. I've perused the datasheet and tried some other register names, but I am yet to find one that works. I would like to ask:Thanks.
Beta Was this translation helpful? Give feedback.
All reactions