Remap pins for NRF24L01 sketch to ATtiny84

Hello all,

I’m trying to follow the tutorial here: http://iteadstudio.com/application-note/nrf24l01-wireless-module-with-arduino/ but I’m trying to use (2x) ATtiny84’s instead of a full Arduino board. Issue is that I have to remap the default arduino pins over to the ATtiny84’s. The tutorial says to edit the “FRF24L01.h” file (contents below), but I can’t make heads or tails of how… (newbie)…

[size=10pt][size=10pt]#ifndef NRF24L01_h
#define NRF24L01_h

#include "API.h"

//*********************************************
#define SPI_PORT PORTB
#define SPI_DIR  DDRB
#define SPI_IN   PINB
//---------------------------------------------
#define TX_ADR_WIDTH    5   
// 5 unsigned chars TX(RX) address width
#define TX_PLOAD_WIDTH  1  
// 20 unsigned chars TX payload
//---------------------------------------------
#define CE       0x01
// CE_BIT:   Digital Input     Chip Enable Activates RX or TX mode
#define SCK      0x04
// SCK BIT:  Digital Input     SPI Clock

#define MISO     0x10
// MISO BIT: Digital Output    SPI Slave Data Output, with tri-state option
#define CSN      0x02
// CSN BIT:  Digital Input     SPI Chip Select
#define MOSI     0x08
// MOSI BIT: Digital Input     SPI Slave Data Input
#define IRQ      0x20
// IRQ BIT:  Digital Output    Maskable interrupt pin
//*********************************************
#endif[/size][/size]

They appear to be using Direct Port Addressing and software SPI.

Each port has 8 pins. The DDR (Data Direction Register) determines if a pin is INPUT or OUTPUT. The PORT register is how you write to the pins. The PIN register is how you read from the pins AND lets you toggle a pin by writing a 1.

They are using 5 pins that are all controlled by PORTB.

They set up bit masks for the 5 pins:

0x01 == 0b00000001 == PORTB Pin 0 == Chip Enable 0x02 == 0b00000010 == PORTB Pin 1 == SPI Chip Select 0x04 == 0b00000100 == PORTB Pin 2 == SPI Clock 0x08 == 0b00001000 == PORTB Pin 3 == MOSI (Master Out/Slave In) 0x10 == 0b00010000 == PORTB Pin 4 == MISO (Master In/Slave Out)

Looks like the ATtiny84 has PORTA and PORTB. You have to look at the available pins and find 5 on a single PORT that you can use. Since only 4 of the PORTB pins are connected to the outside world you will have to switch to PORTA/DDRA/PINA. Pick any 5 of the 8 you are not using for other things.

PDIP pins: 1 2 PB0 3 PB1 4 PB3 5 PB2 6 PA7 7 PA6

8 PA5 9 PA4 10 PA3 11 PA2 12 PA1 13 PA0 14

Thanks for the tip! So since I need a total of 6 pins (CE, CSN, SCK, MOSI, MISO, IRQ), from what you're saying I either have to use all on PortA or all on PortB--- so if I'd have to switch over to using the APort, what would I need to update? I'm really new to this direct port addressing and SPI's business...

If you just change the defies to:

#define SPI_PORT PORTA
#define SPI_DIR  DDRA
#define SPI_IN   PINA

Your connections will all be on one side of the chip: 14 13 PA0 ---- Chip Enable 12 PA1 ---- SPI Chip Select 11 PA2 ---- SPI Clock 10 PA3 ---- SPI MOSI 9 PA4 ---- SPI MISO 8 PA5 ---- IRQ

Thank you, John!