Čeština / English
Login

SVN Repository / Prohlížení

Aktuální adresář: FITkit / trunk / mcu / libs / nrf24l01 /

nrf24l01_spi.h

   1  /*******************************************************************************
   2     nrf24l01_spi.h: NRF24L01 low-level functions
   3     Copyright (C) 2010 Brno University of Technology,
   4                        Faculty of Information Technology
   5     Author(s): Zdenek Vasicek <vasicek AT fit.vutbr.cz>
   6  
   7     LICENSE TERMS
   8  
   9     Redistribution and use in source and binary forms, with or without
  10     modification, are permitted provided that the following conditions
  11     are met:
  12     1. Redistributions of source code must retain the above copyright
  13        notice, this list of conditions and the following disclaimer.
  14     2. Redistributions in binary form must reproduce the above copyright
  15        notice, this list of conditions and the following disclaimer in
  16        the documentation and/or other materials provided with the
  17        distribution.
  18     3. All advertising materials mentioning features or use of this software
  19        or firmware must display the following acknowledgement:
  20  
  21          This product includes software developed by the University of
  22          Technology, Faculty of Information Technology, Brno and its
  23          contributors.
  24  
  25     4. Neither the name of the Company nor the names of its contributors
  26        may be used to endorse or promote products derived from this
  27        software without specific prior written permission.
  28  
  29     This software or firmware is provided ``as is'', and any express or implied
  30     warranties, including, but not limited to, the implied warranties of
  31     merchantability and fitness for a particular purpose are disclaimed.
  32     In no event shall the company or contributors be liable for any
  33     direct, indirect, incidental, special, exemplary, or consequential
  34     damages (including, but not limited to, procurement of substitute
  35     goods or services; loss of use, data, or profits; or business
  36     interruption) however caused and on any theory of liability, whether
  37     in contract, strict liability, or tort (including negligence or
  38     otherwise) arising in any way out of the use of this software, even
  39     if advised of the possibility of such damage.
  40  
  41     $Id$
  42  
  43  
  44  *******************************************************************************/
  45  
  46  /**
  47  	\file nrf24l01_spi.h
  48  
  49  */
  50  
  51  #ifndef _NRF24L01_SPI_
  52  #define _NRF24L01_SPI_
  53  
  54  /**
  55   \cond
  56   **/
  57  #define BASE_ADDR_CTRLREG 0xE0
  58  #define control_reg_write(data) FPGA_SPI_RW_A8_D8(SPI_FPGA_ENABLE_WRITE, BASE_ADDR_CTRLREG, (data))
  59  #define control_reg_read() (FPGA_SPI_RW_A8_D8(SPI_FPGA_ENABLE_READ, BASE_ADDR_CTRLREG, 0))
  60  
  61  /**
  62   \endcond
  63   **/
  64  
  65  /**
  66   \brief Inicializace NRF24L01 (modifikuje port P1)
  67  
  68  
  69   **/
  70  char NRF24L01_init();
  71  
  72  /**
  73   \brief RF_CE_clr - nastavi signal CE na hodnotu log. 0
  74   **/
  75  #define RF_CE_clr() control_reg_write(0x01)
  76  
  77  /**
  78   \brief RF_CE_set - nastavi signal CE na hodnotu log. 1
  79   **/
  80  #define RF_CE_set() control_reg_write(0x03)
  81  
  82  #define RF_IRQ BIT7
  83  
  84  #define RF_is_IRQ() ((P1IN & BIT7) == 0)
  85  
  86  //******************************************
  87  //fce cteni/zapis registru
  88  //******************************************
  89  
  90  /**
  91  
  92  
  93  
  94  
  95  
  96   **/
  97  unsigned char RF_cmd_read(unsigned char cmd, unsigned char* buf, unsigned char len);
  98  
  99  
 100  /**
 101  
 102  
 103  
 104  
 105  
 106   **/
 107  unsigned char RF_cmd_write(unsigned char cmd, unsigned char* buf, unsigned char len);
 108  
 109  /**
 110  
 111   \param addr - adresa registru
 112  
 113  
 114   **/
 115  unsigned char RF_reg_read(unsigned char addr, unsigned char* data, unsigned char len);
 116  
 117  
 118  /**
 119  
 120   \param addr - adresa registru
 121  
 122   **/
 123  inline unsigned char RF_reg_write(unsigned char addr, unsigned char data);
 124  
 125  /**
 126  
 127   \param addr - adresa registru
 128  
 129  
 130   **/
 131  inline unsigned char RF_reg_write_bytes(unsigned char addr, unsigned char data, unsigned char len);
 132  
 133  
 134  /**
 135  
 136   \param addr - adresa registru
 137  
 138  
 139   **/
 140  #define RF_reg_write_buf(addr, buf, len) RF_cmd_write(W_REGISTER | (addr), (buf), (len))
 141  
 142  
 143  /**
 144   \cond
 145   **/
 146  
 147  
 148  
 149  //******************************************
 150  //SPI INSTRUKCE
 151  //******************************************
 152  
 153  #define   NRF_NOP         0xFF
 154  #define   R_REGISTER      0x00
 155  #define   W_REGISTER      0x20
 156  #define   R_RX_PAYLOAD    0x61
 157  #define   W_TX_PAYLOAD    0xA0
 158  #define   W_TX_PAYLOAD_NO_ACK    0xB0
 159  #define   FLUSH_TX        0xE1
 160  #define   FLUSH_RX        0xE2
 161  #define   REUSE_TX_PL     0xE3
 162  #define   R_RX_PL_WID     0x60
 163  
 164  
 165  //******************************************
 166  //ADRESY REGISTRU
 167  //******************************************
 168  #define   NRF_CONFIG       0x00
 169  #define   NRF_EN_AA        0x01
 170  #define   NRF_EN_RXADDR    0x02
 171  #define   NRF_SETUP_AW     0x03
 172  #define   NRF_SETUP_RETR   0x04
 173  #define   NRF_RF_CH        0x05
 174  #define   NRF_RF_SETUP     0x06
 175  #define   NRF_STATUS       0x07
 176  #define   NRF_OBSERVE_TX   0x08
 177  #define   NRF_RPD          0x09
 178  #define   NRF_RX_ADDR_P0   0x0A
 179  #define   NRF_RX_ADDR_P1   0x0B
 180  #define   NRF_RX_ADDR_P2   0x0C
 181  #define   NRF_RX_ADDR_P3   0x0D
 182  #define   NRF_RX_ADDR_P4   0x0E
 183  #define   NRF_RX_ADDR_P5   0x0F
 184  #define   NRF_TX_ADDR      0x10
 185  #define   NRF_RX_PW_P0     0x11
 186  #define   NRF_RX_PW_P1     0x12
 187  #define   NRF_RX_PW_P2     0x13
 188  #define   NRF_RX_PW_P3     0x14
 189  #define   NRF_RX_PW_P4     0x15
 190  #define   NRF_RX_PW_P5     0x16
 191  #define   NRF_FIFO_STATUS  0x17
 192  #define   NRF_DYNPD        0x1C
 193  #define   NRF_FEATURE      0x1D
 194  
 195  //***********************************
 196  //BITY REGISTRU
 197  //***********************************
 198  
 199  // status registr
 200  #define   TX_FULL         0x01
 201  #define   MAX_RT          0x10
 202  #define   TX_DS           0x20
 203  #define   RX_DR           0x40
 204  
 205  /**
 206   \endcond
 207   **/
 208  
 209  #endif /*_NRF24L01_SPI_*/
 210  
Zobrazeno: 597148x Naposledy: 27.1.2022 15:32:44