Interfacing an Arduino with a Microchip MRF89XA radio.

Constants:

// MRF89XA REGISTERS MEMORY MAP
const byte GCONREG=0x00, DMODREG=0x01, FDEVREG=0x02, BRSREG=0x03;
const byte FLTHREG=0x04, FIFOCREG=0x05, R1CREG=0x06, P1CREG=0x07;
const byte S1CREG=0x08, R2CREG=0x09, P2CREG=0x0A, S2CREG=0x0B;
const byte PACREG=0x0C, FTXRXIREG=0x0D, FTPRIREG=0x0E, RSTHIREG=0x0F;
const byte FILCREG=0x10, PFCREG=0x11, SYNCREG=0x12, RSTSREG=0x13;
const byte RSVREG=0x14, OOKCREG=0x15, SYNCV31REG=0x16, SYNCV23REG=0x17;
const byte SYNCV15REG=0x18, SYNCV07REG=0x19, TXCONREG=0x1A, CLKOREG=0x1B;
const byte PLOADREG=0x1C, NADDSREG=0x1D, PKTCREG=0x1E, FCRCREG=0x1F;

const byte READMASK=0x40;
const int CSCON = 2;
const int CSDAT = 3;

Setup:

pinMode(CSCON, OUTPUT);
pinMode(CSDAT, OUTPUT);
digitalWrite(CSCON, HIGH);
digitalWrite(CSDAT, HIGH);

SPI.begin();
SPI.setDataMode(SPI_MODE0); // MRF89XA is SPI0,0
SPI.setBitOrder(MSBFIRST); // MRF89XA is MSB first (page 23)
SPI.setClockDivider(SPI_CLOCK_DIV32); // Max SPI freq is 1MHz for DATA


Read/write CONFIG routines:

byte readConfig(byte addr)
{
  byte ADDRESS = ( addr << 1 ) | READMASK;
  byte VALUE;

  digitalWrite(CSCON, LOW);
  SPI.transfer(ADDRESS);
  VALUE=SPI.transfer(0xFF);
  digitalWrite(CSCON, HIGH);

  return VALUE;
}

byte writeConfig(byte addr, byte val)
{
  byte ADDRESS = ( addr << 1 ); // write mask is 0x00
  byte OLDVALUE;

  digitalWrite(CSCON, LOW);
  SPI.transfer(ADDRESS);
  OLDVALUE=SPI.transfer(val);
  digitalWrite(CSCON, HIGH);

  return OLDVALUE;
}

Share