00001 /*This file has been prepared for Doxygen automatic documentation generation.*/ 00015 00016 /* Copyright (c) 2007, Atmel Corporation All rights reserved. 00017 * 00018 * Redistribution and use in source and binary forms, with or without 00019 * modification, are permitted provided that the following conditions are met: 00020 * 00021 * 1. Redistributions of source code must retain the above copyright notice, 00022 * this list of conditions and the following disclaimer. 00023 * 00024 * 2. Redistributions in binary form must reproduce the above copyright notice, 00025 * this list of conditions and the following disclaimer in the documentation 00026 * and/or other materials provided with the distribution. 00027 * 00028 * 3. The name of ATMEL may not be used to endorse or promote products derived 00029 * from this software without specific prior written permission. 00030 * 00031 * THIS SOFTWARE IS PROVIDED BY ATMEL ``AS IS'' AND ANY EXPRESS OR IMPLIED 00032 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00033 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY AND 00034 * SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, 00035 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00036 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00037 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00038 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00039 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 00040 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00041 */ 00042 00043 #include "config.h" 00044 #include "nRF_API.h" 00045 #include "lib_mcu/spi/spi_lib.h" 00046 00047 00057 U8 NRF_Read(U8 reg) 00058 { 00059 U8 reg_val; 00060 00061 NRF_select(); 00062 spi_rw(reg); // Select register to read from.. 00063 reg_val = spi_rw(0); // ..then read registervalue 00064 NRF_unselect(); // CSN high, terminate SPI communication 00065 return(reg_val); // return register value 00066 } 00067 00068 00078 U8 NRF_RW_Reg(U8 reg, U8 value) 00079 { 00080 U8 status; 00081 00082 NRF_select(); // CSN low, init SPI transaction 00083 status = spi_rw(reg); // select register 00084 spi_rw(value); // ..and write value to it.. 00085 NRF_unselect(); // CSN high again 00086 return(status); // return nRF24L01 status byte 00087 } 00088 00089 00101 U8 NRF_write_buf(U8 reg,U8 *pBuf, U8 bytes) 00102 { 00103 U8 status,byte_ctr; 00104 volatile U32 tempo; 00105 00106 NRF_select(); // Set CSN low, init SPI tranaction 00107 status = spi_rw(reg); // Select register to write to and read status byte 00108 for(byte_ctr=0; byte_ctr<bytes; byte_ctr++) // then write all byte in buffer(*pBuf) 00109 spi_rw(*pBuf++); 00110 NRF_unselect(); // Set CSN high again 00111 NRF_enable(); 00112 for(tempo=0;tempo<FOSC/100;tempo++); 00113 NRF_disable(); 00114 return(status); // return nRF24L01 status byte 00115 } 00116 00128 U8 NRF_read_buf(U8 reg, U8 *pBuf, U8 bytes) 00129 { 00130 U8 status,byte_ctr; 00131 00132 NRF_select(); // Set CSN low, init SPI tranaction 00133 status = spi_rw(reg); // Select register to write to and read status byte 00134 00135 for(byte_ctr=0;byte_ctr<bytes;byte_ctr++) 00136 pBuf[byte_ctr] = spi_rw(0); // Perform SPI_RW to read byte from nRF24L01 00137 00138 NRF_unselect(); // Set CSN high again 00139 00140 return(status); // return nRF24L01 status byte 00141 }