ATY_LIB V2_102_230218
ATY_LIB for general devices or ALGO
 
Loading...
Searching...
No Matches
nrf24l01.h
Go to the documentation of this file.
1// Copyright 2021 IOsetting <iosetting(at)outlook.com>
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#ifndef __FW_RNF24L01_H__
16#define __FW_RNF24L01_H__
17
18#include "fw_hal.h"
19#include "string.h"
20
21#define NRF_CSN P35
22#define NRF_MOSI P34
23#define NRF_MISO P33
24#define NRF_SCK P32
25#define NRF_IRQ P36
26#define NRF_CE P37
27
28/********** SPI(nRF24L01) commands ***********/
29//
30#define NRF24_CMD_R_REGISTER 0x00 // [000A AAAA] Register read
31#define NRF24_CMD_W_REGISTER 0x20 // [001A AAAA] Register write
32#define NRF24_CMD_R_RX_PAYLOAD 0x61 // Read RX payload
33#define NRF24_CMD_W_TX_PAYLOAD 0xA0 // Write TX payload
34#define NRF24_CMD_FLUSH_TX 0xE1 // Flush TX FIFO
35#define NRF24_CMD_FLUSH_RX 0xE2 // Flush RX FIFO
36#define NRF24_CMD_REUSE_TX_PL 0xE3 // Reuse TX payload
37#define NRF24_CMD_R_RX_PL_WID 0x60 // Read RX-payload width for the top R_RX_PAYLOAD in the RX FIFO.
38#define NRF24_CMD_W_ACK_PAYLOAD 0xA8 // [1010 1PPP] Write ACK Payload to be with ACK packet on PIPE PPP
39#define NRF24_CMD_W_TX_PAYLOAD_NOACK 0xB0 //Write TX payload and disable AUTOACK
40#define NRF24_CMD_NOP 0xFF // No operation (used for reading status register)
41
42#define NRF24_CMD_ACTIVATE 0x50 // (De)Activates R_RX_PL_WID, W_ACK_PAYLOAD, W_TX_PAYLOAD_NOACK features
43#define NRF24_CMD_LOCK_UNLOCK 0x50 // Lock/unlock exclusive features
44
45// SPI(nRF24L01) register address definitions
46#define NRF24_REG_CONFIG 0x00 // Configuration register
47#define NRF24_REG_EN_AA 0x01 // Enable "Auto acknowledgment"
48#define NRF24_REG_EN_RXADDR 0x02 // Enable RX addresses
49#define NRF24_REG_SETUP_AW 0x03 // Setup of address widths
50#define NRF24_REG_SETUP_RETR 0x04 // Setup of automatic re-transmit
51#define NRF24_REG_RF_CH 0x05 // RF channel
52#define NRF24_REG_RF_SETUP 0x06 // RF setup
53#define NRF24_REG_STATUS 0x07 // Status register
54#define NRF24_REG_OBSERVE_TX 0x08 // Transmit observe register
55#define NRF24_REG_RPD 0x09 // Received power detector
56#define NRF24_REG_RX_ADDR_P0 0x0A // Receive address data pipe 0
57#define NRF24_REG_RX_ADDR_P1 0x0B // Receive address data pipe 1
58#define NRF24_REG_RX_ADDR_P2 0x0C // Receive address data pipe 2
59#define NRF24_REG_RX_ADDR_P3 0x0D // Receive address data pipe 3
60#define NRF24_REG_RX_ADDR_P4 0x0E // Receive address data pipe 4
61#define NRF24_REG_RX_ADDR_P5 0x0F // Receive address data pipe 5
62#define NRF24_REG_TX_ADDR 0x10 // Transmit address
63#define NRF24_REG_RX_PW_P0 0x11 // Number of bytes in RX payload in data pipe 0
64#define NRF24_REG_RX_PW_P1 0x12 // Number of bytes in RX payload in data pipe 1
65#define NRF24_REG_RX_PW_P2 0x13 // Number of bytes in RX payload in data pipe 2
66#define NRF24_REG_RX_PW_P3 0x14 // Number of bytes in RX payload in data pipe 3
67#define NRF24_REG_RX_PW_P4 0x15 // Number of bytes in RX payload in data pipe 4
68#define NRF24_REG_RX_PW_P5 0x16 // Number of bytes in RX payload in data pipe 5
69#define NRF24_REG_FIFO_STATUS 0x17 // FIFO status register
70#define NRF24_REG_DYNPD 0x1C // Enable dynamic payload length
71#define NRF24_REG_FEATURE 0x1D // Feature register
72
73// Register bits definitions
74#define NRF24_CONFIG_PRIM_RX 0x01 // PRIM_RX bit in CONFIG register
75#define NRF24_CONFIG_PWR_UP 0x02 // PWR_UP bit in CONFIG register
76#define NRF24_FEATURE_EN_DYN_ACK 0x01 // EN_DYN_ACK bit in FEATURE register
77#define NRF24_FEATURE_EN_ACK_PAY 0x02 // EN_ACK_PAY bit in FEATURE register
78#define NRF24_FEATURE_EN_DPL 0x04 // EN_DPL bit in FEATURE register
79#define NRF24_FLAG_RX_DREADY 0x40 // RX_DR bit (data ready RX FIFO interrupt)
80#define NRF24_FLAG_TX_DSENT 0x20 // TX_DS bit (data sent TX FIFO interrupt)
81#define NRF24_FLAG_MAX_RT 0x10 // MAX_RT bit (maximum number of TX re-transmits interrupt)
82#define NRF24_FLAG_TX_FULL 0x01 // 1:TX FIFO full
83
84// Register masks definitions
85#define NRF24_MASK_REG_MAP 0x1F // Mask bits[4:0] for CMD_RREG and CMD_WREG commands
86#define NRF24_MASK_CRC 0x0C // Mask for CRC bits [3:2] in CONFIG register
87#define NRF24_MASK_STATUS_IRQ 0x70 // Mask for all IRQ bits in STATUS register
88#define NRF24_MASK_RF_PWR 0x06 // Mask RF_PWR[2:1] bits in RF_SETUP register
89#define NRF24_MASK_RX_P_NO 0x0E // Mask RX_P_NO[3:1] bits in STATUS register
90#define NRF24_MASK_DATARATE 0x28 // Mask RD_DR_[5,3] bits in RF_SETUP register
91#define NRF24_MASK_EN_RX 0x3F // Mask ERX_P[5:0] bits in EN_RXADDR register
92#define NRF24_MASK_RX_PW 0x3F // Mask [5:0] bits in RX_PW_Px register
93#define NRF24_MASK_RETR_ARD 0xF0 // Mask for ARD[7:4] bits in SETUP_RETR register
94#define NRF24_MASK_RETR_ARC 0x0F // Mask for ARC[3:0] bits in SETUP_RETR register
95#define NRF24_MASK_RXFIFO 0x03 // Mask for RX FIFO status bits [1:0] in FIFO_STATUS register
96#define NRF24_MASK_TXFIFO 0x30 // Mask for TX FIFO status bits [5:4] in FIFO_STATUS register
97#define NRF24_MASK_PLOS_CNT 0xF0 // Mask for PLOS_CNT[7:4] bits in OBSERVE_TX register
98#define NRF24_MASK_ARC_CNT 0x0F // Mask for ARC_CNT[3:0] bits in OBSERVE_TX register
99
100#define NRF24_ADDR_WIDTH 5 // RX/TX address width
101#define NRF24_PLOAD_WIDTH 32 // Payload width
102#define NRF24_TEST_ADDR "nRF24"
103
104typedef enum
105{
107 NRF24_MODE_TX = 0x01
109
110typedef enum
111{
116
117
119
121
122void NRF24L01_ReadToBuf(uint8_t reg, uint8_t len);
123
124void NRF24L01_WriteFromBuf(uint8_t reg, const uint8_t *pBuf, uint8_t len);
125
126void NRF24L01_PrintBuf(void);
127
131void NRF24L01_FlushRX(void);
132
136void NRF24L01_FlushTX(void);
137
138void NRF24L01_CheckFlag(uint8_t *tx_ds, uint8_t *max_rt, uint8_t *rx_dr);
140
141void NRF24L01_HandelIrqFlag(void);
142void NRF24L01_Tx(uint8_t *pBuf);
143void NRF24L01_StartFastWrite(const void* pBuf);
144uint8_t NRF24L01_WriteFast(const void* pBuf);
145void NRF24L01_ResetTX(void);
147void NRF24L01_Init(NRF24_MODE mode);
148
149
150#endif
value
Definition: DS18B20_ATY.c:216
unsigned char uint8_t
Definition: fw_types.h:18
void NRF24L01_WriteReg(uint8_t reg, uint8_t value)
Definition: nrf24l01.c:24
uint8_t NRF24L01_WriteFast(const void *pBuf)
Definition: nrf24l01.c:149
NRF24_SCEN
Definition: nrf24l01.h:111
@ NRF24_SCEN_HALF_DUPLEX
Definition: nrf24l01.h:114
@ NRF24_SCEN_TX
Definition: nrf24l01.h:113
@ NRF24_SCEN_RX
Definition: nrf24l01.h:112
uint8_t NRF24L01_ReadReg(uint8_t reg)
Definition: nrf24l01.c:33
void NRF24L01_Init(NRF24_MODE mode)
Definition: nrf24l01.c:181
void NRF24L01_ResetTX(void)
Definition: nrf24l01.c:161
void NRF24L01_PrintBuf(void)
Definition: nrf24l01.c:61
uint8_t NRF24L01_Check(void)
Definition: nrf24l01.c:168
NRF24_MODE
Definition: nrf24l01.h:105
@ NRF24_MODE_TX
Definition: nrf24l01.h:107
@ NRF24_MODE_RX
Definition: nrf24l01.h:106
void NRF24L01_FlushRX(void)
Definition: nrf24l01.c:74
void NRF24L01_WriteFromBuf(uint8_t reg, const uint8_t *pBuf, uint8_t len)
Definition: nrf24l01.c:52
void NRF24L01_Tx(uint8_t *pBuf)
Definition: nrf24l01.c:131
void NRF24L01_HandelIrqFlag(void)
Definition: nrf24l01.c:111
void NRF24L01_FlushTX(void)
Definition: nrf24l01.c:82
uint8_t NRF24L01_RxAvailable(uint8_t *pipe_num)
Definition: nrf24l01.c:97
void NRF24L01_ReadToBuf(uint8_t reg, uint8_t len)
Definition: nrf24l01.c:43
void NRF24L01_StartFastWrite(const void *pBuf)
Definition: nrf24l01.c:143
void NRF24L01_CheckFlag(void)
Definition: nrf24l01.c:87