SHARE
TWEET

Receiver

meffcio Mar 16th, 2015 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* ========================================
  2.  *
  3.  * Copyright YOUR COMPANY, THE YEAR
  4.  * All Rights Reserved
  5.  * UNPUBLISHED, LICENSED SOFTWARE.
  6.  *
  7.  * CONFIDENTIAL AND PROPRIETARY INFORMATION
  8.  * WHICH IS THE PROPERTY OF your company.
  9.  *
  10.  * ========================================
  11. */
  12. #include <project.h>
  13.  
  14. #define R_REGISTER                  0x00 // 0000 0000 - logically OR with a register address
  15. #define W_REGISTER                  0x20 // 0010 0000 - logically OR with a register address
  16. #define R_RX_PAYLOAD            0x61 // 0110 0001
  17. #define W_TX_PAYLOAD            0xA0 // 1010 0000
  18.  
  19. #define CONFIG                      0x00
  20. //#define EN_AA                     0x01
  21. //#define EN_RXADDR                 0x02
  22. #define SETUP_AW                    0x03
  23. //#define RF_CH                     0x05
  24. //#define RF_SETUP                  0x06
  25. #define STATUS                      0x07
  26. //#define RX_ADDR_P0            0x0A
  27. //#define TX_ADDR                   0x10
  28. #define RX_PW_P0                    0x11
  29. #define FIFO_STATUS             0x17
  30. #define DUMMYDATA           0x55 // 0101 0101 - just so it doesn't look like anything else
  31.  
  32. #define RX_DR                       0x40 // from STATUS register
  33. #define RX_EMPTY                0x01 // from FIFO_STATUS register
  34.  
  35. int main()
  36. {
  37.     uint8 spiData[2];            // array for SPI commands
  38.     uint8 data[3];               // up to 3 payloads in RX FIFO
  39.     int dataSize;                // actual size of data
  40.     uint8 fifoStatus;
  41.     int i;
  42.    
  43.     CyGlobalIntEnable;
  44.     SPI_Start();
  45.    
  46.     spiData[0] = W_REGISTER | CONFIG;
  47.     spiData[1] = 0x3F;
  48.     SPI_SpiUartPutArray(spiData,  2);       // reflect RX_DR interrupt as IRQ pin active low, enable 2-byte CRC, power-up, RX mode
  49.    
  50.     spiData[0] = W_REGISTER | SETUP_AW;
  51.     spiData[1] = 0x03;
  52.     SPI_SpiUartPutArray(spiData,  2);       // 5 byte address
  53.    
  54.     spiData[0] = W_REGISTER | RX_PW_P0;
  55.     spiData[1] = 0x01;
  56.     SPI_SpiUartPutArray(spiData,  2);       // 1 byte of payload
  57.    
  58.    
  59.     CE_Write(1);                            // enable chip = start listening
  60.    
  61.     for(;;){
  62.         if (IRQ_Read() == 0) {                                      // if there's an RX_DR interrupt, meaning data is received
  63.             CE_Write(0);                                            // stop listening
  64.             dataSize=0;                                            
  65.             do {
  66.                 spiData[0] = R_RX_PAYLOAD;
  67.                 spiData[1] = DUMMYDATA;
  68.                 SPI_SpiUartPutArray(spiData, 2);                    // read payload
  69.                 data[dataSize]=SPI_SpiUartReadRxData();             // throw payload into array
  70.                 dataSize++;
  71.                 spiData[0] = R_REGISTER | FIFO_STATUS;
  72.                 spiData[1] = DUMMYDATA;
  73.                 SPI_SpiUartPutArray(spiData, 2);
  74.                 fifoStatus = SPI_SpiUartReadRxData();
  75.             } while ((fifoStatus & RX_EMPTY) == 0);                // do until RX FIFO empty
  76.             spiData[0] = STATUS;
  77.             spiData[1] = RX_DR;
  78.             SPI_SpiUartPutArray(spiData,  2);                       // clear interrupt
  79.             for (i=0; i<dataSize; i++) {                        // process received data
  80.                 LED_Write(data[i]);
  81.             }
  82.             CE_Write(1);                                            // start listening again
  83.         }
  84.     }
  85. }
  86.  
  87. /* [] END OF FILE */
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top