Vorgestellt wird eine Funkstrecke zwischen 2 NRF24L01 frei nach der AN#151 von MCS
Erweitert wurde das Programm um die ACK-Payload Funktion, das heißt, der Sender erhält mit der Sendebestätigung noch ein paar Bytes Nutzdaten vom Empfänger.
Hier im Beispiel wird die aktuelle Uhrzeit des Empfämgers in 3 Bytes zurück zum Sender übertragen.
Der Empfänger enthält zusätzlich noch die SPI-Displayfunktionen für 1.8" Display von hkipnik.
Display und NRF24L01+ und Programmierstecker teilen sich die SPI-Schnittstelle.
Das Display braucht aber eine andere SPI-Konfiguration als das Funkmodul. Entsprechend wird immer neu initialisiert.
Entgegen der allgemeinen Befürchtung, dass SPI-Geräte und Programmierstecker zusammen nicht arbeiten, funktioniert es hier einwandfrei. Die entsprechenden Chip-Select Leitungen brauchen nur einen Pullup von je 10k nach Vcc, um während der AVR-Programmierung im Tristate zu sein.
Die Sendeleistung und Datenrate sind auf Maximum und die Verbindung ist stabil bis ca 6m (2 Decken und 2 Wände)
Eine Verinerung der Datenrate bringt hier sicher noch eine größere Entfernung.
Im Anhang befinden sich Sende-und Empfangsprogramm und die benötigten Displayroutinen.
Das Datenblatt vom NRF24L01P Funkmodul gibt es bei NordicSemiconductor
Sender:
Alle 1/4s wird ein 5-Byte Telegramm gesendet mit fortlaufendem Zähler
Wenn ein Payload-ACK Paket kommt, wird daraus die Uhrzeit des Empfängers extrahiert.
Alles anzeigen
Empfänger:
Beim Empfang eines Telegramms wird der Inhalt auf dem Grafikdisplay dargestellt und die Daten (altuelle Uhrzeit) für die ACK-Payload für die nächste Übertragung neu in den Buffer geschrieben.
Alles anzeigen
NRF24L01.jpg
Erweitert wurde das Programm um die ACK-Payload Funktion, das heißt, der Sender erhält mit der Sendebestätigung noch ein paar Bytes Nutzdaten vom Empfänger.
Hier im Beispiel wird die aktuelle Uhrzeit des Empfämgers in 3 Bytes zurück zum Sender übertragen.
Der Empfänger enthält zusätzlich noch die SPI-Displayfunktionen für 1.8" Display von hkipnik.
Display und NRF24L01+ und Programmierstecker teilen sich die SPI-Schnittstelle.
Das Display braucht aber eine andere SPI-Konfiguration als das Funkmodul. Entsprechend wird immer neu initialisiert.
Entgegen der allgemeinen Befürchtung, dass SPI-Geräte und Programmierstecker zusammen nicht arbeiten, funktioniert es hier einwandfrei. Die entsprechenden Chip-Select Leitungen brauchen nur einen Pullup von je 10k nach Vcc, um während der AVR-Programmierung im Tristate zu sein.
Die Sendeleistung und Datenrate sind auf Maximum und die Verbindung ist stabil bis ca 6m (2 Decken und 2 Wände)
Eine Verinerung der Datenrate bringt hier sicher noch eine größere Entfernung.
Im Anhang befinden sich Sende-und Empfangsprogramm und die benötigten Displayroutinen.
Das Datenblatt vom NRF24L01P Funkmodul gibt es bei NordicSemiconductor
Sender:
Alle 1/4s wird ein 5-Byte Telegramm gesendet mit fortlaufendem Zähler
Wenn ein Payload-ACK Paket kommt, wird daraus die Uhrzeit des Empfängers extrahiert.
BASCOM-Quellcode: NRF_TX_Arduino_Nano_web.bas
- ' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- ' Nordic nRF24L01 data link demo in Enhanced Shockburst mode
- ' By Evert Dekker 2007 nRF24L01@Evertdekker dotje com
- ' Created with Bascom-Avr: 1.11.8.3
- '
- ' Expanded with ACK Payload and created with Bascom-AVR 2079 Michael Kinz 12/2016
- '------------------------------------------------------------------
- $regfile = "M328pdef.dat" 'Arduini Nano V3
- $crystal = 16000000
- $baud = 9600
- $hwstack = 40
- $swstack = 20
- $framesize = 40
- '=== Declare sub routines
- Declare Sub R_register(byval Command As Byte , Byval C_bytes As Byte)
- Declare Sub W_register(byval C_bytes As Byte)
- '=== Constante ===
- 'Define nRF24L01 interrupt flag's
- Const Idle_int = &H00 'Idle, no interrupt pending
- Const Max_rt = &H10 'Max #of Tx Retrans Interrupt
- Const Tx_ds = &H20 'Tx Data Sent Interrupt
- Const Rx_dr = &H40 'Rx Data Received
- 'SPI(nRF24L01) commands
- Const Read_reg = &H00 'Define Read Command To Register
- Const Write_reg = &H20 'Define Write Command To Register
- Const Rd_rx_pload = &H61 'Define Rx Payload Register Address
- Const Wr_tx_pload = &HA0 'Define Tx Payload Register Address
- Const Flush_tx = &HE1 'Define Flush Tx Register Command
- Const Flush_rx = &HE2 'Define Flush Rx Register Command
- Const Reuse_tx_pl = &HE3 'Define Reuse Tx Payload Register Command
- Const Nop_comm = &HFF 'Define No Operation , Might Be Used To Read Status Register
- 'SPI(nRF24L01) registers(addresses)
- Const Config_nrf = &H00 'Config' register address
- Const En_aa = &H01 'Enable Auto Acknowledgment' register address
- Const En_rxaddr = &H02 'Enabled RX addresses' register address
- Const Setup_aw = &H03 'Setup address width' register address
- Const Setup_retr = &H04 'Setup Auto. Retrans' register address
- Const Rf_ch = &H05 'RF channel' register address
- Const Rf_setup = &H06 'RF setup' register address
- Const Status = &H07 'Status' register address
- Const Observe_tx = &H08 'Observe TX' register address
- Const Cd = &H09 'Carrier Detect' register address
- Const Rx_addr_p0 = &H0A 'RX address pipe0' register address
- Const Rx_addr_p1 = &H0B 'RX address pipe1' register address
- Const Rx_addr_p2 = &H0C 'RX address pipe2' register address
- Const Rx_addr_p3 = &H0D 'RX address pipe3' register address
- Const Rx_addr_p4 = &H0E 'RX address pipe4' register address
- Const Rx_addr_p5 = &H0F 'RX address pipe5' register address
- Const Tx_addr = &H10 'TX address' register address
- Const Rx_pw_p0 = &H11 'RX payload width, pipe0' register address
- Const Rx_pw_p1 = &H12 'RX payload width, pipe1' register address
- Const Rx_pw_p2 = &H13 'RX payload width, pipe2' register address
- Const Rx_pw_p3 = &H14 'RX payload width, pipe3' register address
- Const Rx_pw_p4 = &H15 'RX payload width, pipe4' register address
- Const Rx_pw_p5 = &H16 'RX payload width, pipe5' register address
- Const Fifo_status = &H17 'FIFO Status Register' register address
- Const Feature = &H1D 'ACK Payload Feature
- Const Dyn_pd = &H1C 'Dynamic Payload Register
- Const R_rx_pl_wid = &H60 'Payload RX Length
- 'Various
- Const True = 1
- Const False = 0
- Config Portb.2 = Output 'SPI Master needed
- '=== Config hardware ===
- Config Spi = Hard , Interrupt = Off , Data Order = Msb , Master = Yes , Polarity = Low , Phase = 0 , Clockrate = 4 , Noss = 1
- 'Software SPI is NOT working with the nRF24L01, use hardware SPI only, but the SS pin must be controlled by our self
- Config Pind.2 = Output 'CE pin is output
- Config Pind.3 = Output 'SS pin is output
- Config Pind.7 = Input 'IRQ pin is input
- Nrf_ce Alias Portd.2
- Nrf_csn Alias Portd.3
- Irq Alias Pind.7
- Config Pinb.0 = Output
- Led Alias Portb.0 'Debug LED
- Config Lcdpin = Pin , Db4 = Portc.2 , Db5 = Portc.3 , Db6 = Portc.4 , Db7 = Portc.5 , E = Portc.1 , Rs = Portc.0
- Config Lcd = 16x2
- Initlcd
- Cursor Off
- Cls
- Lcd "NRF 24L01+"
- Spiinit 'init the spi pins
- Set Nrf_ce
- Waitms 10 'Wait a moment until all hardware is stable
- Reset Nrf_ce 'Set CE pin low
- Reset Nrf_csn 'Set SS pin low (CSN pin)
- Dim D_bytes(33) As Byte , B_bytes(33) As Byte 'Dim the bytes use for SPI, D_bytes = outgoing B_bytes = Incoming
- Dim Temp As Byte , W As Word , Temp2 As Byte
- Dim Packet_count As Word 'Payload Sender
- Led = 1
- Print "TX_device" 'Send to terminal who i'm
- D_bytes(1) = Flush_tx 'Flush the TX_fifo buffer
- Call W_register(1)
- D_bytes(1) = Write_reg + Status 'Reset the IRQ bits
- D_bytes(2) = &B00110000
- Call W_register(2)
- Gosub Setup_tx
- Do 'Main loop for TX
- Toggle Led
- D_bytes(1) = Wr_tx_pload 'Put 5 bytes in the TX pload buffer
- D_bytes(2) = &HAA 'Byte 1
- D_bytes(3) = &HBB 'Byte 2
- D_bytes(4) = &HCC 'Byte 3
- D_bytes(5) = High(packet_count) 'Byte 4
- D_bytes(6) = Low(packet_count) 'Byte 5 will be increase every loop
- Call W_register(6) 'Write 6 bytes to register
- Waitms 2
- Set Nrf_ce 'Set CE for a short moment to transmit the fifo buffer
- Waitms 1 '
- Reset Nrf_ce '
- Waitms 247 'Some delay to read the output on the terminal, line can be removed for max. speed
- W = 0 'Counter for time out
- Do
- If Irq = 0 Then
- Call R_register(status , 1)
- Temp = B_bytes(1) And &B01110000 'Mask the IRQ bits out the status byte
- 'Print Bin(b_bytes(temp));
- Select Case Temp 'Which IRQ occurs
- Case Max_rt 'MAX_RT
- ' Print "Maximum number of TX retries, Flushing the TX buffer now !"
- D_bytes(1) = Flush_tx 'Flush the TX buffer
- Call W_register(1)
- D_bytes(1) = Write_reg + Status
- D_bytes(2) = &B00010000 'Clear the MAX_RT IRQ bit
- Call W_register(2)
- Exit Do
- Case Tx_ds 'TX_DS
- Print "P " ; Packet_count ; '" send and ACK received." ;
- D_bytes(1) = Write_reg + Status
- D_bytes(2) = &B00100000 'Clear the TX_DS IRQ bit
- Call W_register(2)
- Incr Packet_count
- Exit Do
- Case Else 'Other IRQ ??
- D_bytes(1) = Flush_tx 'Flush the TX buffer
- Call W_register(1)
- If Temp.6 = 1 Then
- Reset Nrf_ce
- Do
- Call R_register(r_rx_pl_wid , 1) 'Anzahl Bytes im Empfangspuffer lesen
- Temp2 = B_bytes(1)
- Call R_register(rd_rx_pload , Temp2) 'Lese X bytes RX payload register
- 'Print "Pload " ;
- Print " ";
- Locate 2 , 2
- If B_bytes(1) < 10 Then 'Formatierung für Output
- Print "0";
- Lcd "0"
- End If
- Print B_bytes(1) ; ":" ;
- Lcd B_bytes(1) ; ":"
- If B_bytes(2) < 10 Then 'Formatierung für Output
- Print "0";
- Lcd "0"
- End If
- Print B_bytes(2) ; ":" ;
- Lcd B_bytes(2) ; ":"
- If B_bytes(3) < 10 Then 'Formatierung für Output
- Print "0";
- Lcd "0"
- End If
- Print B_bytes(3) ;
- Lcd B_bytes(3)
- Call R_register(fifo_status , 1) 'Read FIFO_STATUS
- Loop Until B_bytes(1).0 = True 'Test or RX_EMPTY bit is true, RX FIFO empty
- D_bytes(1) = Write_reg + Status 'Reset the RX_DR status bit
- D_bytes(2) = &B01000000 'Write 1 to RX_DR bit to reset IRQ
- Call W_register(2)
- Set Nrf_ce
- End If
- End Select
- End If
- Waitms 1 'Time out waiting for IRQ 1ms * 100
- Incr W 'Increment W
- If W > 100 Then 'Waited for 100ms
- Print "No irq response from RF20L01 within 100ms"
- Exit Do 'Exit the wait loop
- End If
- Loop
- Loop
- End
- '=== Sub routines ===
- Sub W_register(byval C_bytes As Byte) 'Write register with SPI
- Reset Nrf_csn 'Manual control SS pin, set SS low before shifting out the bytes
- Spiout D_bytes(1) , C_bytes 'Shiftout the data bytes trough SPI , C_bytes is the amount bytes to be written
- Set Nrf_csn 'Set SS high
- End Sub
- Sub R_register(byval Command As Byte , Byval C_bytes As Byte) As Byte 'C_bytes = Count_bytes, number off bytes to be read
- Reset Nrf_csn 'Manual controle SS pin, set low before shifting in/out the bytes
- Spiout Command , 1 'First shiftout the register to be read
- Spiin B_bytes(1) , C_bytes 'Read back the bytes from SPI sended by nRF20L01
- Set Nrf_csn 'Set SS back to high level
- End Sub
- Setup_tx: 'Setup for TX
- D_bytes(1) = Write_reg + Tx_addr 'TX adress
- D_bytes(2) = &H34
- D_bytes(3) = &H43
- D_bytes(4) = &H10
- D_bytes(5) = &H10
- D_bytes(6) = &H01
- Call W_register(6)
- D_bytes(1) = Write_reg + Rx_addr_p0 'RX adress for pipe0
- D_bytes(2) = &H34
- D_bytes(3) = &H43
- D_bytes(4) = &H10
- D_bytes(5) = &H10
- D_bytes(6) = &H01
- Call W_register(6)
- D_bytes(1) = Write_reg + En_aa 'Enable auto ACK for pipe0
- D_bytes(2) = &H01
- Call W_register(2)
- D_bytes(1) = Write_reg + En_rxaddr 'Enable RX adress for pipe0
- D_bytes(2) = &H01
- Call W_register(2)
- D_bytes(1) = Write_reg + Rf_ch 'Set RF channel
- D_bytes(2) = 40
- Call W_register(2)
- D_bytes(1) = Write_reg + Rf_setup 'Setup RF-> Output power 0dbm, datarate 2Mbps and LNA gain on
- D_bytes(2) = &H0F
- Call W_register(2)
- D_bytes(1) = Write_reg + Config_nrf 'Setup CONFIG-> PRX=0(TX_device), PWR_UP=1, CRC 2bytes, Enable CRC
- D_bytes(2) = &H0E
- Call W_register(2)
- D_bytes(1) = Write_reg + Setup_retr 'Retransmission auf
- D_bytes(2) = &H20
- Call W_register(2)
- D_bytes(1) = Write_reg + Feature 'Feature Register Enables_Dynamic_Payload_Length=1 Enable_ACK_Payload=1 '
- D_bytes(2) = &H06
- Call W_register(2)
- D_bytes(1) = Write_reg + Dyn_pd 'Dynamic Payload Register - Enable dynamic payload length data pipe 0 = 1 '
- D_bytes(2) = &H01
- Call W_register(2)
- Return
Empfänger:
Beim Empfang eines Telegramms wird der Inhalt auf dem Grafikdisplay dargestellt und die Daten (altuelle Uhrzeit) für die ACK-Payload für die nächste Übertragung neu in den Buffer geschrieben.
BASCOM-Quellcode: NRF_RX_ATMega32_web.bas
- ' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- ' Nordic nRF24L01 data link demo in Enhanced Shockburst mode
- ' By Evert Dekker 2007 nRF24L01@Evertdekker dotje com
- ' Created with Bascom-Avr: 1.11.8.3
- '
- ' Expanded with ACK Payload and 1.8" Color Display (hkipnik)
- ' Created with Bascom-AVR 2079 Michael Kinz 12/2016
- ' ------------------------------------------------------------------
- $regfile = "M32def.dat"
- $crystal = 16000000
- $baud = 9600
- $hwstack = 128 'needed for display
- $swstack = 128
- $framesize = 128
- '=== Declare sub routines
- Declare Sub R_register(byval Command As Byte , Byval C_bytes As Byte)
- Declare Sub W_register(byval C_bytes As Byte)
- '=== Constante ===
- 'Define nRF24L01 interrupt flag's
- Const Idle_int = &H00 'Idle, no interrupt pending
- Const Max_rt = &H10 'Max #of Tx Retrans Interrupt
- Const Tx_ds = &H20 'Tx Data Sent Interrupt
- Const Rx_dr = &H40 'Rx Data Received
- 'SPI(nRF24L01) commands
- Const Read_reg = &H00 'Define Read Command To Register
- Const Write_reg = &H20 'Define Write Command To Register
- Const Rd_rx_pload = &H61 'Define Rx Payload Register Address
- Const Wr_tx_pload = &HA0 'Define Tx Payload Register Address
- Const W_ack_payload = &HA8
- Const Flush_tx = &HE1 'Define Flush Tx Register Command
- Const Flush_rx = &HE2 'Define Flush Rx Register Command
- Const Reuse_tx_pl = &HE3 'Define Reuse Tx Payload Register Command
- Const Nop_comm = &HFF 'Define No Operation , Might Be Used To Read Status Register
- 'SPI(nRF24L01) registers(addresses)
- Const Config_nrf = &H00 'Config' register address
- Const En_aa = &H01 'Enable Auto Acknowledgment' register address
- Const En_rxaddr = &H02 'Enabled RX addresses' register address
- Const Setup_aw = &H03 'Setup address width' register address
- Const Setup_retr = &H04 'Setup Auto. Retrans' register address
- Const Rf_ch = &H05 'RF channel' register address
- Const Rf_setup = &H06 'RF setup' register address
- Const Status = &H07 'Status' register address
- Const Observe_tx = &H08 'Observe TX' register address
- Const Cd = &H09 'Carrier Detect' register address
- Const Rx_addr_p0 = &H0A 'RX address pipe0' register address
- Const Rx_addr_p1 = &H0B 'RX address pipe1' register address
- Const Rx_addr_p2 = &H0C 'RX address pipe2' register address
- Const Rx_addr_p3 = &H0D 'RX address pipe3' register address
- Const Rx_addr_p4 = &H0E 'RX address pipe4' register address
- Const Rx_addr_p5 = &H0F 'RX address pipe5' register address
- Const Tx_addr = &H10 'TX address' register address
- Const Rx_pw_p0 = &H11 'RX payload width, pipe0' register address
- Const Rx_pw_p1 = &H12 'RX payload width, pipe1' register address
- Const Rx_pw_p2 = &H13 'RX payload width, pipe2' register address
- Const Rx_pw_p3 = &H14 'RX payload width, pipe3' register address
- Const Rx_pw_p4 = &H15 'RX payload width, pipe4' register address
- Const Rx_pw_p5 = &H16 'RX payload width, pipe5' register address
- Const Fifo_status = &H17 'FIFO Status Register' register address
- Const Feature = &H1D 'ACK Payload Feature
- Const Dyn_pd = &H1C 'Dynamic Payload Register
- 'Various
- Const True = 1
- Const False = 0
- Config Pinb.4 = Output 'needed for SPI-Master Function
- Portb.4 = 1
- Config Portb.3 = Output
- Config Portb.2 = Output
- Config Portb.1 = Output
- Lcd_cs Alias Portb.1
- Lcd_dc Alias Portb.3
- Lcd_reset Alias Portb.2
- Portb.2 = 1
- Config Pind.5 = Output 'CE pin is output
- Config Pind.7 = Output 'SS pin is output
- Config Pind.4 = Input 'IRQ pin is input
- Nrf_ce Alias Portd.5
- Nrf_csn Alias Portd.7
- Irq Alias Pind.4
- '###################################################################################
- Const Sdcard = 0
- Const Modus = 1 '0=Portrait 1=Landscape
- Const Driver = 0 '0=ST7735 1=ILI9163
- 'only Display ST7735
- 'Display typ Red or black Tab have different RGB order
- 'color of the display plastic wrap
- Const Disp_typ = 0 'RGB order 0=Black Tab 1=Red Tab
- $include "18Spi_declarations.inc"
- Print "Start NRF24L01+ RX + Display"
- Dim Lsyssec As Long
- Dim Atemp As String * 16
- Dim Halbflag As Bit
- Dim Halb As Bit
- Config Clock = User 'create clock variables and time functions
- Config Timer1 = Timer , Prescale = 256 'user defined clock
- On Timer1 T1irq
- Start Timer1
- Enable Timer1
- Enable Interrupts
- '###################################################################################
- Config Portd.6 = Output
- Led Alias Portd.6 'debug led
- Gosub Activate_display 'SPI init LCD
- '*******************************************************************************
- 'Init the Dispaly
- Waitms 10
- Lcd_cs = 0
- Call Lcd_init()
- Waitms 10
- Call Lcd_clear(gray4)
- Waitms 100
- Atemp = "NRF24L01+"
- Print Atemp
- Call Lcd_text(atemp , 5 , 10 , 2 , Blue , Gray4)
- Atemp = "Payload "
- Call Lcd_text(atemp , 5 , 30 , 2 , Blue , Gray4)
- '*******************************************************************************
- Waitms 10
- Gosub Activate_nrf 'init the spi pins
- Print "Los geht's"
- Set Nrf_ce
- Waitms 10 'Wait a moment until all hardware is stable
- Reset Nrf_ce 'Set CE pin low
- Reset Nrf_csn 'Set SS pin low (CSN pin)
- Dim D_bytes(33) As Byte , B_bytes(33) As Byte 'Dim the bytes use for SPI, D_bytes = outgoing B_bytes = Incoming
- Dim Btemp As Byte , W As Word
- Dim Packet_count As Byte
- '===Main rx==========================================================================================================================
- 'Main_rx:
- Call R_register(status , 1) 'Read STATUS register
- Print "Rx_device" 'Send to terminal who i'm
- Reset Nrf_ce 'Set CE low to access the registers
- Gosub Setup_rx 'Setup the nRF24L01 for RX
- Waitms 2 'Add a delay before going in RX
- Set Nrf_ce 'Set nRF20L01 in RX mode
- Do 'Main loop for RX
- If Irq = 0 Then 'Wait until IRQ occurs, pin becomes low on interrupt
- Reset Nrf_ce 'Receiver must be disabled before reading pload
- Do 'Loop until all 3 fifo buffers are empty
- Call R_register(rd_rx_pload , 5) 'Read 5 bytes RX pload register
- Print "Pload : " ; Hex(b_bytes(1)) ; Hex(b_bytes(2)) ; Hex(b_bytes(3)) ; Hex(b_bytes(4)) ; Hex(b_bytes(5)) 'Print the pload
- Gosub Activate_display
- Atemp = Hex(b_bytes(1)) + Hex(b_bytes(2)) + Hex(b_bytes(3)) + Hex(b_bytes(4)) + Hex(b_bytes(5))
- Call Lcd_text(atemp , 5 , 50 , 2 , Blue , Gray4)
- Gosub Activate_nrf
- Call R_register(fifo_status , 1) 'Read FIFO_STATUS
- Toggle Led 'debug
- Loop Until B_bytes(1).0 = True 'Test or RX_EMPTY bit is true, RX FIFO empty
- D_bytes(1) = Write_reg + Status 'Reset the RX_DR status bit
- D_bytes(2) = &B01000000 'Write 1 to RX_DR bit to reset IRQ
- Call W_register(2)
- Set Nrf_ce 'Enable receiver again
- Waitms 2
- Gosub Activate_nrf
- D_bytes(1) = Flush_tx 'Flush the TX_fifo buffer
- Call W_register(1)
- D_bytes(1) = W_ack_payload 'Put bytes in the TX pload buffer
- D_bytes(4) = _sec
- D_bytes(3) = _min
- D_bytes(2) = _hour
- Call W_register(4)
- End If
- If Halbflag = 1 Then
- Halbflag = 0
- If Halb = 1 Then
- Gosub Activate_display
- Call Lcd_text(time$ , 5 , 70 , 2 , Blue , Gray4)
- End If
- End If
- Loop
- End
- '=== Sub routines ===
- Sub W_register(byval C_bytes As Byte) 'Write register with SPI
- Reset Nrf_csn 'Manual control SS pin, set SS low before shifting out the bytes
- Spiout D_bytes(1) , C_bytes 'Shiftout the data bytes trough SPI , C_bytes is the amount bytes to be written
- Set Nrf_csn 'Set SS high
- End Sub
- Sub R_register(byval Command As Byte , Byval C_bytes As Byte) As Byte 'C_bytes = Count_bytes, number off bytes to be read
- Reset Nrf_csn 'Manual controle SS pin, set low before shifting in/out the bytes
- Spiout Command , 1 'First shiftout the register to be read
- Spiin B_bytes(1) , C_bytes 'Read back the bytes from SPI sended by nRF20L01
- Set Nrf_csn 'Set SS back to high level
- End Sub
- Setup_rx: 'Setup for RX
- D_bytes(1) = Write_reg + Rx_addr_p0 'RX adress for pipe0
- D_bytes(2) = &H34
- D_bytes(3) = &H43
- D_bytes(4) = &H10
- D_bytes(5) = &H10
- D_bytes(6) = &H01
- Call W_register(6) 'Send 6 bytes to SPI
- D_bytes(1) = Write_reg + En_aa 'Enable auto ACK for pipe0
- D_bytes(2) = &H01
- Call W_register(2)
- D_bytes(1) = Write_reg + En_rxaddr 'Enable RX adress for pipe0
- D_bytes(2) = &H01
- Call W_register(2)
- D_bytes(1) = Write_reg + Rf_ch 'Set RF channel
- D_bytes(2) = 40
- Call W_register(2)
- D_bytes(1) = Write_reg + Rx_pw_p0 'Set RX pload width for pipe0
- D_bytes(2) = 5
- Call W_register(2)
- D_bytes(1) = Write_reg + Rf_setup 'Setup RF-> Output power 0dbm, datarate 2Mbps and LNA gain on
- D_bytes(2) = &H0F
- Call W_register(2)
- D_bytes(1) = Write_reg + Config_nrf 'Setup CONFIG-> PRX=1(RX_device), PWR_UP=1, CRC 2bytes, Enable CRC
- D_bytes(2) = &H0F
- Call W_register(2)
- D_bytes(1) = Write_reg + Feature '
- D_bytes(2) = &H06
- Call W_register(2)
- D_bytes(1) = Write_reg + Dyn_pd '
- D_bytes(2) = &H01
- Call W_register(2)
- Return
- Activate_display:
- Nrf_csn = 1
- Config Spi = Hard , Interrupt = Off , Data Order = Msb , Master = Yes , Polarity = High , Phase = 1 , Clockrate = 4 , Noss = 1
- Spsr.0 = 1
- Spiinit
- Return
- Activate_nrf:
- Lcd_cs = 1
- Config Spi = Hard , Interrupt = Off , Data Order = Msb , Master = Yes , Polarity = Low , Phase = 0 , Clockrate = 4 , Noss = 1
- Spsr.0 = 1
- Spiinit
- Return
- T1irq:
- Timer1 = 34286 '500ms
- Halbflag = 1
- Toggle Halb
- If Halb = 1 Then Incr Lsyssec
- Return
- Getdatetime:
- Time$ = Time(lsyssec)
- Return
- Settime:
- Return
- '*******************************************************************************
- $include "ST7735_functions.inc"
- $include "Font\Font12x16.font"
- $include "Font\Font8x8.font"
- $include "Font\font8x12.font"
- $include "Font\font6x10.font"
- $include "Font\font10x16.font"
- '*******************************************************************************
NRF24L01.jpg