nRF24L01 Software Driver for C51 Microcontrollers nRF24L01 is a single chip RF-transceiver intended for applications in the 2.4 GHz ISM to 2.5 GHz band. Software Driver for C51 Microcontrollers AT89C5131A is a high-performance Flash version of the 80C51 single-chip 8-bit micro controllers with full speed USB functions. Application Note Th is app lica tion no te d escrib es th e nRF24L 01 softwa re drive r ru nning on AT89C5131A micrcontroller. References AT89C5131A data sheet (available on www.atmel.com) nRF24L01 data sheet (available on www.nordicsemi.no) Acronyms USB: Universal Serial Bus ISM: Industrial, Scientific and Medical (radio spectrum) 7651A–USB–05/06 Software Driver Overview The nRF24L01/AT89C5131A driver is composed of 3 parts: 1/ nRF24L01 driver: This part contains the functions to init the nRF24L01 in transmission mode or reception mode. This part contains also the interrupt function. The list of files is: • nRF24L01_lib.c • nRF24L01_lib.h 2/ Nordic driver: T his part contains fi les from Nordic evaluation kit (source code available on www.nordicsemi.no). The list of files is: • Protocol_API.c • Protocol_API.h • nRF_API.c • nRF_API.h 3/ Low level driver: This part contains files with low level functions to control AT89C5131A IOs and SPI commands. The low level driver calls SPI functions from a C51 library. The list of files is: • LL_API_C51.c • LL_API_C51.h 2 nRF24L01 Software Driver 7651A–USB–05/06 nRF24L01 Software Driver Hardware Description This driver is based on the hardware configuration described in Fig 1. Figure 1. AT89C5131A and nRF24L01 nRF24L01 AT89C5131A SPI P1_6/SCK SCK P1_7/MOSI MOSI P1_5/MISO MISO CSN P2_1 P2_2 P3_2/INT0 XTAL1 XTAL2 CE IRQ XC1 16MHz Note: XC2 16MHz Both ICs can share the same crystal if they are placed on the same PCB. The nRF24L01 signals are separated in two parts: • SPI: the read/write operations on nRF24L01 registers come from the AT89C5131A hardware SPI bus (ENABLE, CLOCK, DATA). • IO lines: the control of CE and CSN signals is done by 2 IO lines. The IRQ signal from nRF24L01 is connected to the external interrupt input (INT0) of the AT89C5131A. 3 7651A–USB–05/06 nRF24L01 Software Driver Description A list of functions (based on SPI commands) is proposed to: • send the configuration to nRF24L01 • send/receive data on RF part of nRF24L01. Figure 2. Software Architecture Application nRF24L01 driver nRF24L01_lib.c Nordic driver Protocol_API.c nRF_API.c * provided by Nordic Low level driver LL_API.c * specific for AT89C5131A SPI driver SPI_drv.c nRF24L01 device 4 nRF24L01 Software Driver 7651A–USB–05/06 nRF24L01 Software Driver Application layer The application calls “open”, “putc” and “getc” functions. Table 1. Application functions Application function Description open() Init device putc() Send a data byte on RF part getc() Receive a data byte on RF part nRF24L01 driver The nRF24L01 driver contains functions to send/receive data via RF. The nRF24L01 driver calls Nordic functions from Protocol_API and nRF_API files. Table 2. Application functions Application function nRF24L01 function Description open() nRF24L01_init() UART init and nRF24L01 init putc() nRF24L01_send_byte() Send a data byte on RF part getc() nRF24L01_receive_byte() Receive a data byte on RF part Low Level layer The nRF24L01 driver manages the configuration of nRF24L01 by using the hardware SPI bus of AT89C5131A. Table 3. nRF24L01 low level functions Function name Parameters SPI_Init SPI Mode (hardware) Description Init C5131 hardware SPI C5131_enable_it Enable C5131 IT on INT0 pin nRF24L01_reset Reset/Unreset nRF24L01 nRF24L01_tx_config Configure nRF24L01 in Tx mode nRF24L01_rx_config Configure nRF24L01 in Rx mode SPI_HW Data to send Send a byte via RF CSN_Pin State (0 or 1) Control of CSN pin of nRF24L01 CE_Pin state (O or 1) Control of CE pin of nRF24L01 5 7651A–USB–05/06 Atmel Corporation 2325 Orchard Parkway San Jose, CA 95131, USA Tel: 1(408) 441-0311 Fax: 1(408) 487-2600 Regional Headquarters Europe Atmel Sarl Route des Arsenaux 41 Case Postale 80 CH-1705 Fribourg Switzerland Tel: (41) 26-426-5555 Fax: (41) 26-426-5500 Asia Room 1219 Chinachem Golden Plaza 77 Mody Road Tsimshatsui East Kowloon Hong Kong Tel: (852) 2721-9778 Fax: (852) 2722-1369 Japan 9F, Tonetsu Shinkawa Bldg. 1-24-8 Shinkawa Chuo-ku, Tokyo 104-0033 Japan Tel: (81) 3-3523-3551 Fax: (81) 3-3523-7581 Atmel Operations Memory 2325 Orchard Parkway San Jose, CA 95131, USA Tel: 1(408) 441-0311 Fax: 1(408) 436-4314 Microcontrollers 2325 Orchard Parkway San Jose, CA 95131, USA Tel: 1(408) 441-0311 Fax: 1(408) 436-4314 La Chantrerie BP 70602 44306 Nantes Cedex 3, France Tel: (33) 2-40-18-18-18 Fax: (33) 2-40-18-19-60 ASIC/ASSP/Smart Cards RF/Automotive Theresienstrasse 2 Postfach 3535 74025 Heilbronn, Germany Tel: (49) 71-31-67-0 Fax: (49) 71-31-67-2340 1150 East Cheyenne Mtn. Blvd. Colorado Springs, CO 80906, USA Tel: 1(719) 576-3300 Fax: 1(719) 540-1759 Biometrics/Imaging/Hi-Rel MPU/ High Speed Converters/RF Datacom Avenue de Rochepleine BP 123 38521 Saint-Egreve Cedex, France Tel: (33) 4-76-58-30-00 Fax: (33) 4-76-58-34-80 Zone Industrielle 13106 Rousset Cedex, France Tel: (33) 4-42-53-60-00 Fax: (33) 4-42-53-60-01 1150 East Cheyenne Mtn. Blvd. Colorado Springs, CO 80906, USA Tel: 1(719) 576-3300 Fax: 1(719) 540-1759 Scottish Enterprise Technology Park Maxwell Building East Kilbride G75 0QR, Scotland Tel: (44) 1355-803-000 Fax: (44) 1355-242-743 Literature Requests www.atmel.com/literature Disclaimer: The information in this document is provided in connection with Atmel products. No license, express or implied, by estoppel or otherwise, to any intellectual property right is granted by this document or in connection with the sale of Atmel products. EXCEPT AS SET FORTH IN ATMEL’S TERMS AND CONDITIONS OF SALE LOCATED ON ATMEL’S WEB SITE, ATMEL ASSUMES NO LIABILITY WHATSOEVER AND DISCLAIMS ANY EXPRESS, IMPLIED OR STATUTORY WARRANTY RELATING TO ITS PRODUCTS INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, CONSEQUENTIAL, PUNITIVE, SPECIAL OR INCIDENTAL DAMAGES (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF PROFITS, BUSINESS INTERRUPTION, OR LOSS OF INFORMATION) ARISING OUT OF THE USE OR INABILITY TO USE THIS DOCUMENT, EVEN IF ATMEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. Atmel makes no representations or warranties with respect to the accuracy or completeness of the contents of this document and reserves the right to make changes to specifications and product descriptions at any time without notice. Atmel does not make any commitment to update the information contained herein. Unless specifically providedotherwise, Atmel products are not suitable for, and shall not be used in, automotive applications. Atmel’s products are not intended, authorized, or warranted for use as components in applications intended to support or sustain life. © Atmel Corporation 2006. All rights reserved. Atmel ® , logo and combinations thereof, and Everywhere You Are ® are the trademarks or registered trademarks, of Atmel Corporation or its subsidiaries. Other terms and product names may be trademarks of others. Printed on recycled paper. 7651A–USB–05/06