3 Replies Latest reply on Jan 17, 2018 3:52 AM by anks

    SPI receive data from slave trouble


      I'm new to SPI and have run into a snag. I have a a PCB with a PSoC 3 trying to communicate to an nRF24L01+. With PsoC Creator, I have added an SPI mater to the project and have a simple loop where, after I do a "SPIM_Start()" I try to do some simple register write/read on the slave. I have a logic analyzer showing me the SPI data that is being transfered. It appears as though my write to say register 0 is working .. I basically do a "SPIM_WrtieTxData(<addr>+32)"  ( register write requires bit 6 to be a "1" to indicate a register write, so register "0" if the value == 32), then I do another SPIM_WrtieTxData(<value>) to write the data to that register. So far so good, and the analyzer shows the xfer. But, when I try to read the register; I send "SPIM_WrtieTxData(<addr>)" (bit 6 is clear for a read, so just the reg addr is needed) then another write ("SPIM_WrtieTxData(0xFF)") with bugus data, which gives the slave the clock cycles it needs to shift the return value out  (verified with analyzer), I then do a "temp = SPIM_ReadRxData()" to read what I would think would be the slave return data but the value returned is NOT what is expected (nor what the analyzer shows). So, I must be missing some simple step before I should read the slave data.

      Here is a simple example of my code.. and a snapshot of the analyzer output (attached)

      My guess is I'm missing some Tx and/or Rx status checks but I'm not sure what and why?

      Any suggestions?


      main() {

        uint8 addr, val;



        for (;;) {

           addr = 32;     // Set bit 6 to write to a register (i.e.  001a aaaa ..  "aaaaa" is the register address). So reg "0" here.

            SPIM_WriteTxData(addr);   // Tx addr to slave device

            SPIM_WriteTxData(0x1E);  // Write 0x1E (to register 0 .. just an xfer test, not tryiing to set anything, yet).

            CyDelayUs(10u);   // Give small delay for the xfer


           addr = 0;                    // Now read regsiter 0. A read operation is just the address (i.e. 000a aaaa)

           SPIM_WriteTxData(addr);     // Tx addr to slave

           SPIM_WriteTxData(0xFF);    // Tx bogus data to give slave the clock cycles it needs to shift out register 0 contents

           CyDelayUs(10u);   // Give small delay for the xfer

           val = SPIM_ReadRxData();     // We should see 0x1E, but we val == 0x00 (analyzer shows 0x1E).