#define RFM_REN P3REN
#define RFM_DIR P3DIR
#define RFM_IN P3IN
#define RFM_OUT P3OUT
#define RFM_CS_PIN (1<<7)
#define RFM_SCL_PIN (1<<3)
#define RFM_MISO_PIN (1<<2)
#define RFM_MOSI_PIN (1<<1)
#define RFM_NIRQ_PIN (1<<6)
unsigned int spi_shift16(unsigned int data)
{
unsigned int result = 0;
unsigned char width;
RFM_OUT &= ~(RFM_SCL_PIN); //init clock low
RFM_OUT &= ~(RFM_CS_PIN); //begin transmit - cs low
for (width=0; width<16; width++)
{
if (data & 0x8000)
{ //check bit and set data line accordingly
RFM_OUT |= RFM_MOSI_PIN;
}
else
{
RFM_OUT &= ~(RFM_MOSI_PIN);
}
RFM_OUT |= RFM_SCL_PIN; //end bit - clock high
result <<= 1;
if((RFM_IN & RFM_MISO_PIN) == RFM_MISO_PIN)
result |= 0x00001;
RFM_OUT &= ~(RFM_SCL_PIN); //begin bit - clock low
data <<= 1;
}
RFM_OUT |= RFM_CS_PIN; //end transmit
return result;
}