[SOLVED] attiny84 (arduino-tiny-core) port mappings to Arduino Digital Pins

While trying to get the mirf libs working for the attiny84, I notice the differences between attiny85 and attiny84..

All the attiny85 PB0-PB4 maps directly to Arduino digital pins and pinMode(), digitalWrite() will work whereas for the attiny84, the PA4-PA7 maps counter clockwise to the Arduino Digital pins and the SPI was not working (obviously...)

From the Arduino-tiny core, pins_arduino.c have the following pin mappings..

MISO , PA5 , maps to D5 MOSI, PA6, maps to D4 SCK, PA4, maps to D6 SS, PA7, maps to D3

How do I fix this in the header files to get the correct mapping for Arduino ??

Thanks

It's not clear what you mean by "the correct mapping". What would make your mapping more correct than the one provided by the Arduino-tiny core?

If anything, you should be looking at the mirf library, not trying to change "pins_arduino.c".

Yes, I will use the arduino-tiny cores codes as references and make changes to my application..

What I mean was this :-

The SPI85.cpp mapped the MOSI = PA6 and MISO = PA5 but when I Serial.print, PA5 = 5 but PA6 = 6 instead of 4...

SPI85.cpp
#if defined( __AVR_ATtiny84__ )
const static uint8_t SS   = PA7;
const static uint8_t MOSI = PA6; // mapped according to arduino-tiny-core
const static uint8_t MISO = PA5; // mapped according to arduino-tiny-core
const static uint8_t SCK  = PA4;
#endif

I had to hard code the digital pins for the SPI ...

#define SS    3
#define MOSI  4
#define MISO  5
#define SCK   6
#define CE    8 //ATTiny84 pin11
#define CSN   7 //ATTiny84 pin10

Currently, with the above code, the SCK, CSN & CE is working but the MOSI / MISO always shows 0xff and returns 0x00 when I decode it with a logic analyzer...

PA0 to PA7 are just #defines for the numbers 0 to 7 an have nothing to do with Arduino ‘digital pin’ numbers.

Ok.. need to clarify this...

As for as my application/library goes, I just need to point to the function of the pins ( MISO/MOSI/SCK/SS ) instead of the physical pins, is this statement accurate ? ( The mapping was done between the tiny-core codes to the h/w itself )

If the USI-SPI codes works for the tiny85 but not for the tiny84, the most probable reason would be the pins was mapped incorrectly in the library/application during the SPI transfer in the library..

Stanley: Ok.. need to clarify this...

As for as my application/library goes, I just need to point to the function of the pins ( MISO/MOSI/SCK/SS ) instead of the physical pins, is this statement accurate ? ( The mapping was done between the tiny-core codes to the h/w itself )

If the USI-SPI codes works for the tiny85 but not for the tiny84, the most probable reason would be the pins was mapped incorrectly in the library/application during the SPI transfer in the library..

If the library does things like "pinMode(SS,OUTPUT)" then you have to find a working value for "SS".

I managed to solve the issue, somehow the PA4-PA7 did not match correctly to the Arduino Digital pins.. and I have no idea where were those PA4-PA7 defined for the attiny84

I had to hard code them to make the USI-SPI working for the attiny84...

SPI85.cpp
#if defined( __AVR_ATtiny84__ )
const static uint8_t SS   = 3;
const static uint8_t MOSI = 5; 
const static uint8_t MISO = 4; 
const static uint8_t SCK  = 6;
#endif

Thanks to Nick Gammon SPI tutorials that gives me some clue on how to resolve it... http://gammon.com.au/spi

I'm still confused here... hope someone can help to clarify this for me...

I've lookup the iotnx4.h under the Arduino folder... how does it "magically" mapped to the Digital Pin as per the Arduino tiny cores ( https://code.google.com/p/arduino-tiny/ )

I was under the impression that for my programs / libraries or headers, once I defined the correct pin name as below, it would be automatically mapped to the correct pins when Arduino compiles for the attiny84 cores ...

or shd i just ignore the h/w pin names and directly use the Arduino digital pin instead...

#define PORTA   _SFR_IO8(0x1B)
#define PA7     7
#define PA6     6
#define PA5     5
#define PA4     4
#define PA3     3
#define PA2     2
#define PA1     1
#define PA0     0

No those mapping define the bit positions for the Port A register.

The correct digital port mappings are in a different file under ~\hardware\tiny\cores\tiny\pins_arduino.c.