Shop OBEX P1 Docs P2 Docs Learn Events
nRF905 — Parallax Forums

nRF905

Glenn_WebberGlenn_Webber Posts: 11
edited 2009-05-31 16:26 in General Discussion
Hi,

I am trying to get a SX28 to talk to a nRF905 single-chip radio transceiver, I have some C code can any one have a look at the code and tell me how to convert it to the SX.


void
InitPort(void){

// Port I/O configuration: 0=output, 1=input

TX_EN_TRIS = 0; //TX_EN

ADPCFGbits.PCFG6 = 1;

TRX_CE_TRIS = 0; //TRX_CE

ADPCFGbits.PCFG7 = 1;

PWR_UP_TRIS = 0; //PWR_UP

ADPCFGbits.PCFG8 = 1;

CD_TRIS = 1; //CD

ADPCFGbits.PCFG9 = 1;

AM_TRIS = 1; //AM

ADPCFGbits.PCFG5 = 1;

DR_TRIS = 1; //DR

ADPCFGbits.PCFG4 = 1;

CSN_TRIS = 0; //CSN

// nRF initial modes

TX_EN = 0; // Rx mode

TRX_CE = 0; // Standby mode

PWR_UP = 0; // Power down

CSN = 0; // Chip Select Not = enabled

}

void InitSPI(void)

{

OpenSPI1(FRAME_ENABLE_OFF&ENABLE_SDO_PIN&SPI_MODE16_OFF&

SPI_SMP_OFF&SPI_CKE_ON&SLAVE_ENABLE_OFF&CLK_POL_ACTIVE_HIGH&

MASTER_ENABLE_ON&SEC_PRESCAL_1_1&PRI_PRESCAL_1_1,

SPI_ENABLE&SPI_IDLE_CON&SPI_RX_OVFLOW_CLR);

DisableIntSPI1;

}

unsigned char Spi1WriteRead(unsigned char in)

{

unsigned char out;

SPI1STATbits.SPIROV = 0;

SPI1BUF = in;

while(!SPI1STATbits.SPIRBF);

out = SPI1BUF;

return out;

}

void InitNRF(void){

int i;

nRFConfig[noparse][[/noparse]0] = CH_NO_BYTE; //Sets center frequency together with HFREQ_PLL

nRFConfig[noparse][[/noparse]1] = PA_PWR_10dBm|HFREQ_PLL_433MHz|CH_NO_BIT8; //Output power, Band 433 or 868/915 MHz

nRFConfig[noparse][[/noparse]2] = TX_AFW_4BYTE|RX_AFW_4BYTE; //Tx and Rx Address width

nRFConfig[noparse][[/noparse]3] = RX_PW_32BYTE; //RX payload width

nRFConfig[noparse][[/noparse]4] = TX_PW_32BYTE; //Tx payload width

nRFConfig[noparse][[/noparse]5] = nRFAddress[noparse][[/noparse]0];

nRFConfig[noparse][[/noparse]6] = nRFAddress[noparse][[/noparse]1];

nRFConfig[noparse][[/noparse]7] = nRFAddress[noparse][[/noparse]2];

nRFConfig[noparse][[/noparse]8] = nRFAddress[noparse][[/noparse]3];

nRFConfig[noparse][[/noparse]9] = CRC16_EN|XOF_16MHz; //CRC check. Crystal oscillator frequency.

PWR_UP = 1;

CSN = 1;

CSN = 0;

Spi1WriteRead(WC); //Write nRF configuration

for(i=0;i<10;i++)

Spi1WriteRead(nRFConfig[noparse][[/noparse]i]);

CSN = 1;

CSN = 0;

Spi1WriteRead(WTA); //Write TX Address

for(i=0;i<4;i++)

Spi1WriteRead(nRFAddress[noparse][[/noparse]i]);

CSN = 1;

TRX_CE = 1;

}

void TXPacket(char *packet){

TRX_CE = 0;

TX_EN = 1;

int i;

CSN = 0;

Spi1WriteRead(WTP); //Write TX Payload

for(i=0;i<32;i++)

Spi1WriteRead(packet[noparse][[/noparse]i]);

CSN = 1;

TRX_CE = 1; // Start transmitting

while(!DR); // Wait for transmission to finish

TX_EN = 0;

}

void RXPacket(void){

int i;

char SpiRxBuf[noparse][[/noparse]32];

TRX_CE = 0;

CSN = 0;

Spi1WriteRead(RRP); //Read RX Payload

for (i=0;i<32;i++)

SpiRxBuf[noparse][[/noparse]i] = Spi1WriteRead(0);

CSN = 1;

TRX_CE = 1;

if(SpiRxBuf[noparse][[/noparse]0] == 'o' && SpiRxBuf[noparse][[/noparse]1] == 'n'){

green_led = 1;

}

else if(SpiRxBuf[noparse][[/noparse]0] == 'o' && SpiRxBuf[noparse][[/noparse]1] == 'f' && SpiRxBuf[noparse][[/noparse]2] == 'f'){

green_led = 0;

}

else USBsend(SpiRxBuf);

}



I have tryed the Shiftout and Shiftin but have had no luck, I need a SPI.

Thanks

Glenn

Comments

  • ZootZoot Posts: 2,227
    edited 2009-05-28 20:45
    SHIFTIN and SHIFTOUT are designed to be used with SPI, so most likely you aren't configuring the commands properly for the slave device and/or you are not handling the \OE or \CS or latch (or whatever) pin on the slave. The C commands from your library probably handle this internally.

    Best bet might be to post:

    - your SX/B or ASM code that failed
    - the data sheet for the slave device

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST

    1uffakind.com/robots/povBitMapBuilder.php
    1uffakind.com/robots/resistorLadder.php
  • Glenn_WebberGlenn_Webber Posts: 11
    edited 2009-05-30 13:36
    HI,

    I have added all the files and code I have, I am trying to use the nRF905-C868. I hope this will help some one find out how to use the SX28 and the nRF905.

    Thanks
  • LeonLeon Posts: 7,620
    edited 2009-05-30 13:42
    Just convert the C code into assembler, it won't be difficult. I've done that for some PIC example code for the nRF24L01.

    Leon

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Amateur radio callsign: G1HSM
    Suzuki SV1000S motorcycle
  • Glenn_WebberGlenn_Webber Posts: 11
    edited 2009-05-30 14:16
    Thanks Leon, I have lots of stuff for PIC, But I'm trying to move to the SX, But not a lot of stuff on the net yet, maybe the chip is still to new.

    Glenn
  • LeonLeon Posts: 7,620
    edited 2009-05-31 05:39
    I still don't see why you can't convert the C code into SX assembler.

    Leon

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Amateur radio callsign: G1HSM
    Suzuki SV1000S motorcycle
  • Glenn_WebberGlenn_Webber Posts: 11
    edited 2009-05-31 14:12
    I don't know assembler.
  • LeonLeon Posts: 7,620
    edited 2009-05-31 16:26
    Convert it into SX/B, or use a PIC.

    Leon

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Amateur radio callsign: G1HSM
    Suzuki SV1000S motorcycle
Sign In or Register to comment.