00001 /* Copyright (c) 2009 Nordic Semiconductor. All Rights Reserved. 00002 * 00003 * The information contained herein is confidential property of Nordic 00004 * Semiconductor ASA.Terms and conditions of usage are described in detail 00005 * in NORDIC 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: 2211 $ 00012 */ 00013 00036 //lint -e717 00037 //lint -e534 00038 //lint -e714 00039 //lint -e783 00040 00041 #ifdef MCU_NRF24LE1 00042 #include "nrf24le1.h" 00043 #include "hal_clk.h" 00044 #endif 00045 00046 #ifdef MCU_NRF24LU1P 00047 #include "nrf24lu1p.h" 00048 #endif 00049 00050 #include <stdint.h> 00051 #include "hal_nrf.h" 00052 00053 // Global variables 00054 uint8_t payload[3]; 00055 00056 void main() 00057 { 00058 #ifdef MCU_NRF24LE1 00059 while(hal_clk_get_16m_source() != HAL_CLK_XOSC16M) 00060 { 00061 // Wait until 16 MHz crystal oscillator is running 00062 } 00063 #endif 00064 00065 #ifdef MCU_NRF24LU1P 00066 // Enable radio SPI 00067 RFCTL = 0x10; 00068 #endif 00069 00070 // Set P0 as output 00071 P0DIR = 0; 00072 00073 // Enable the radio clock 00074 RFCKEN = 1; 00075 00076 // Enable RF interrupt 00077 RF = 1; 00078 // Enable global interrupt 00079 EA = 1; 00080 00081 // Configure radio as primary receiver (PTX) 00082 hal_nrf_set_operation_mode(HAL_NRF_PRX); 00083 00084 // Set payload width to 3 bytes 00085 hal_nrf_set_rx_payload_width((int)HAL_NRF_PIPE0, 3); 00086 00087 // Power up radio 00088 hal_nrf_set_power_mode(HAL_NRF_PWR_UP); 00089 00090 // Enable receiver 00091 CE_HIGH(); 00092 00093 for(;;){} 00094 } 00095 00096 // Radio interrupt 00097 NRF_ISR() 00098 { 00099 uint8_t irq_flags; 00100 00101 // Read and clear IRQ flags from radio 00102 irq_flags = hal_nrf_get_clear_irq_flags(); 00103 00104 // If data received 00105 if((irq_flags & (1<<(uint8_t)HAL_NRF_RX_DR)) > 0) 00106 { 00107 // Read payload 00108 while(!hal_nrf_rx_fifo_empty()) 00109 { 00110 hal_nrf_read_rx_payload(payload); 00111 } 00112 00113 // Write received payload[0] to port 0 00114 P0 = payload[0]; 00115 } 00116 }