• Main Page
  • Modules
  • Index
  • File List
  • Globals

projects/nrfgo_sdk/enhanced_shockburst_examples/ptx/main.c

Go to the documentation of this file.
00001 /* Copyright (c) 2009 Nordic Semiconductor. All Rights Reserved.
00002  *
00003  * The information contained herein is property of Nordic Semiconductor ASA.
00004  * Terms and conditions of usage are described in detail in NORDIC
00005  * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
00006  *
00007  * Licensees are granted free, non-transferable use of the information. NO
00008  * WARRENTY of ANY KIND is provided. This heading must NOT be removed from
00009  * the file.
00010  *
00011  * $LastChangedRevision: 2513 $
00012  */
00013 
00036 //lint -e717
00037 //lint -e714
00038 //lint -e640
00039 
00040 #ifdef MCU_NRF24LE1
00041 #include "nrf24le1.h"
00042 #include "hal_clk.h"
00043 #endif
00044 
00045 #ifdef MCU_NRF24LU1P
00046 #include "nrf24lu1p.h"
00047 #endif
00048 
00049 #include <stdint.h>
00050 #include <stdbool.h>
00051 #include "hal_nrf.h"
00052 #ifndef MCU_NRF24LU1P
00053 #include "hal_clk.h" //lint !e322 !e7 "include file not found"
00054 #endif
00055 
00056 // Global variables
00057 static bool volatile radio_busy;
00058 
00059 void main(void)
00060 {
00061   uint8_t payload[3];
00062 
00063   #ifdef MCU_NRF24LE1
00064   while(hal_clk_get_16m_source() != HAL_CLK_XOSC16M)
00065   {
00066     // Wait until 16 MHz crystal oscillator is running
00067   }
00068   #endif
00069 
00070   #ifdef MCU_NRF24LU1P
00071   // Enable radio SPI
00072   RFCTL = 0x10U;
00073   #endif
00074 
00075   // Enable the radio clock
00076   RFCKEN = 1U;
00077 
00078   // Enable RF interrupt
00079   RF = 1U;
00080 
00081   // Enable global interrupt
00082   EA = 1U;
00083 
00084   // Power up radio
00085   hal_nrf_set_power_mode(HAL_NRF_PWR_UP);
00086 
00087   for(;;)
00088   {
00089     // Put P0 contents in payload[0]
00090     payload[0] = ~P0;
00091 
00092     // Write payload to radio TX FIFO
00093     hal_nrf_write_tx_payload(payload, 3U);
00094 
00095     // Toggle radio CE signal to start transmission
00096     CE_PULSE();
00097 
00098     radio_busy = true;
00099     // Wait for radio operation to finish
00100     while (radio_busy)
00101     {
00102     }
00103   }
00104 }
00105 
00106 // Radio interrupt
00107 NRF_ISR()
00108 {
00109   uint8_t irq_flags;
00110 
00111   // Read and clear IRQ flags from radio
00112   irq_flags = hal_nrf_get_clear_irq_flags();
00113 
00114   switch(irq_flags)
00115   {
00116     // Transmission success
00117     case (1 << (uint8_t)HAL_NRF_TX_DS):
00118       radio_busy = false;
00119       // Data has been sent
00120       break;
00121     // Transmission failed (maximum re-transmits)
00122     case (1 << (uint8_t)HAL_NRF_MAX_RT):
00123       // When a MAX_RT interrupt occurs the TX payload will not be removed from the TX FIFO.
00124       // If the packet is to be discarded this must be done manually by flushing the TX FIFO.
00125       // Alternatively, CE_PULSE() can be called re-starting transmission of the payload.
00126       // (Will only be possible after the radio irq flags are cleared)
00127       hal_nrf_flush_tx();
00128       radio_busy = false;
00129       break;
00130     default:
00131       break;
00132   }
00133 }

Generated on Fri Apr 20 2012 14:11:45 for nRFGo SDK by  doxygen 1.7.2