ATtiny804 Pin Mapping Discrepancy with megaTinyCore Library #1053
-
Dear megaTinyCore Community, I'm using the megaTinyCore library to program an ATtiny804 microcontroller. I've noticed a discrepancy between the physical pin numbers and the program pin configuration for setting pin modes. As shown in the provided image (https://github.com/SpenceKonde/megaTinyCore/assets/157563241/3554bd8e-6baa-4fd4-9706-bceb3f7f1574), the ATtiny804 has 14 pins. However, when setting pin modes in the code, we need to use different numbers ("program pin configuration") than the physical pin numbers. For example, to set physical pin 2 as an output high, we need to use pinMode(0, OUTPUT, HIGH). This mismatch can be confusing, especially when referencing pins in libraries. Here are my specific questions:
Clarifying this pin mapping discrepancy would be greatly appreciated by users of the megaTinyCore library. Thank you for your time and assistance. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
This is all described under the "How to refer to pins" section of the readme (which it sounds as though you have not read), where I describe the preferred method to refer to pins: PIN_Pxn (where x is a capital letter for the port, and n is is the number of the pin.) Ex: In the variant file, where the Arduino pin numbers are defined and the tables that map the arduino pin numbers to port/bit are located, I always have PIN_Pxn defines for every pin on the part to point to the arduino pin number assigned to that port/bit. This also means that if we ever end up forced to support an inferior pin mapping, if you've been using PIN_Pxn, you can use that pin mapping or the old one and the code will behave identically [except for binary size and execution speed, see below]. If some aliexpress vendor whose defective piece of junk I give a scathing review, or a customer who is unhappy with my customer service also happens to be a madman, and I was killed by a mailbomb a month after writing the review, and someone else took over the core and said "Well the first thing I'm doing is fixing this pinmapping" and renumbers the pins in the most optimal way - assuming he didn't bungle it, your code would work without modification as long as you used PIN_Pxn notation! Aside about mapping optimality: See, depending on the order in which you number the pins (and no other changes, and PIN_Pxn notation used so the behavior of the sketch is the same) - just through use of a different numbering scheme, the execution speed of code and the binary size will be different! (Arduino's atmega328p numbering jumps all over the chip! They shuffled them around to make it "make more sense" Trying to copy that has spawned many horrible pin mappings (over on ATTC we have to support multiple pinouts for I think 6 families, in two cases, there are three pin mapping options - and I personally have had problems that were simply from using the wrong pin mapping there. A vaccine against those bugs was certainly an objective of PIN_Pxn numbering) |
Beta Was this translation helpful? Give feedback.
This is all described under the "How to refer to pins" section of the readme (which it sounds as though you have not read), where I describe the preferred method to refer to pins: PIN_Pxn (where x …