Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* ========================================
- *
- * Copyright YOUR COMPANY, THE YEAR
- * All Rights Reserved
- * UNPUBLISHED, LICENSED SOFTWARE.
- *
- * CONFIDENTIAL AND PROPRIETARY INFORMATION
- * WHICH IS THE PROPERTY OF your company.
- *
- * ========================================
- */
- #include <project.h>
- #define R_REGISTER 0x00 // 0000 0000 - logically OR with a register address
- #define W_REGISTER 0x20 // 0010 0000 - as above
- #define R_RX_PAYLOAD 0x61 // 0110 0001
- #define W_TX_PAYLOAD 0xA0 // 1010 0000
- #define NOP 0xFF // to get the STATUS register
- #define CONFIG 0x00
- //#define EN_AA 0x01
- //#define EN_RXADDR 0x02
- #define SETUP_AW 0x03
- //#define RF_CH 0x05
- //#define RF_SETUP 0x06
- #define STATUS 0x07
- //#define RX_ADDR_P0 0x0A
- //#define TX_ADDR 0x10
- #define RX_PW_P0 0x11
- #define FIFO_STATUS 0x17
- #define DUMMYDATA 0x55 // 0101 0101 - just so it doesn't look like anything else
- #define TX_DS 0x20
- #define MAX_RT 0x10 // both for STATUS register
- int main()
- {
- uint8 spiData[2];
- uint8 status;
- CyGlobalIntEnable;
- 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
- }
- }
- }
- }
- /* [] END OF FILE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement