This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Has anyone gotten the nRF24L01 to work with PSoC 3/4/5?

Im currently working on a project and long story short im stuck on getting the nRF24l01 to communicate. I believe I have the Tx side of things working, however as I do not have a serial monitor and am relying on an Agilent Scope to measure my SPI transmissions which fluctuates based off what buttons I press.

Here is the code from my Tx side

SPI_Start();

spiData[0] = W_REGISTER | CONFIG;
spiData[1] = 0x4E;
SPI_SpiUartPutArray(spiData,  2);       // reflect TX_DS and MAX_RT interrupts as IRQ active low, enable 2-byte CRC, power-up, TX mode

spiData[0] = W_REGISTER | SETUP_AW;
spiData[1] = 0x03;
SPI_SpiUartPutArray(spiData,  2);       // 5 byte address

spiData[0] = W_REGISTER | RX_PW_P0;
spiData[1] = 0x01;
SPI_SpiUartPutArray(spiData,  2);       // 1 byte of payload

CE_Write(0);                            // stand-by

for(;;)
{
    spiData[0] = W_TX_PAYLOAD;
    spiData[1] = SW1_Read();
    SPI_SpiUartPutArray(spiData,  2);                   // send state of the switch to the TX FIFO
    CE_Write(1);                                        // enable chip - start sending data
    CyDelayUs(10);                                      // wait 10 microseconds
    if ( IRQ_Read() == 0 ){                             // check if there's an interrupt
        SPI_SpiUartWriteTxData(NOP);                    // send no-operation to receive STATUS register and check kind of the interrupt
        status = SPI_SpiUartReadRxData();               // read status register into a variable
        if ((status & TX_DS) == 1){                     // if data sent (or received when using enhanced shockburst mode) we're ok, so:
            CE_Write(0);                                // stop sending
            LED_Write(!LED_Read());                     // toggle LED state
            spiData[0]=STATUS;
            spiData[1]=TX_DS;
            SPI_SpiUartPutArray(spiData,  2);           // clear interrupt
        } else if ((status & MAX_RT) == 1) {            // if max retries achieved, we basically forget that packet
            CE_Write(0);                                // stop sending
            spiData[0]=STATUS;
            spiData[1]=MAX_RT;
            SPI_SpiUartPutArray(spiData,  2);           // clear interrupt
        }
    }
    
}

}

Again i think all the above works as intended per the data sheet. Here is the reciver side which I got from a dated CyPress forum post.

CyGlobalIntEnable;
SPI_Start();

spiData[0] = W_REGISTER | CONFIG;
spiData[1] = 0x3F;
SPI_SpiUartPutArray(spiData,  2);       // reflect RX_DR interrupt as IRQ pin active low, enable 2-byte CRC, power-up, RX mode

spiData[0] = W_REGISTER | SETUP_AW;
spiData[1] = 0x03;
SPI_SpiUartPutArray(spiData,  2);       // 5 byte address

spiData[0] = W_REGISTER | RX_PW_P0;
spiData[1] = 0x01;
SPI_SpiUartPutArray(spiData,  2);       // 1 byte of payload

CE_Write(1);                            // enable chip = start listening

for(;;){
    if (IRQ_Read()==1)
    {LED_Write(1);
    }else{
        LED_Write(0);}
    if (IRQ_Read() == 0) {                                      // if there's an RX_DR interrupt, meaning data is received
        CE_Write(0);                                            // stop listening
        dataSize=0;                                             
        do {
            spiData[0] = R_RX_PAYLOAD;
            spiData[1] = DUMMYDATA;
            SPI_SpiUartPutArray(spiData, 2);                    // read payload
            data[dataSize]=SPI_SpiUartReadRxData();             // throw payload into array
            dataSize++;
            spiData[0] = R_REGISTER | FIFO_STATUS;
            spiData[1] = DUMMYDATA;
            SPI_SpiUartPutArray(spiData, 2);
            fifoStatus = SPI_SpiUartReadRxData();
        } while ((fifoStatus & RX_EMPTY) == 0 && (dataSize < 3));                // do until RX FIFO empty
        spiData[0] = STATUS;
        spiData[1] = RX_DR;
        SPI_SpiUartPutArray(spiData,  2);                       // clear interrupt
        for (i=0; i<dataSize; i++) {                        // process received data
            LED_Write(data[i]);
        }
        CE_Write(1);                                            // start listening again
    }
}

}

On the oscilloscope when im reading the MISO and MOSI on the tx i notice what appears to be a transmission however on the RX only the MOSI as a high wave and no lows. I have very basic coding skills and do not understand much about buffers and array sizes and the like. I did have to manuallly convert some PSoC 1 syntax to PSoC 3/4/5 and it appears to work however Im stuck. Any advice would be greatly apreciated and if anyone has done this and gotten it to work could you either post your solution or walk me thorugh my error?

Thanks to anyone who can help or point me in the right dirrection thanks.

Related