NRF24L01+ mit ACK Payload

    Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

    Aufgrund technischer Veränderungen ist der Mailverkehr innerhalb des Forums (Private Nachrichten) nur noch eingeschränkt möglich. Die Einschränkung ist notwendig, um zusätzliche Betriebskosten für das Forum zu vermeiden. Näheres zu den Hintergründen im Thread "Aktuelles zum Forum".Wir bitten um Verständnis.

    Hinweis kann nach Kenntnisnahme deaktiviert werden!

    • NRF24L01+ mit ACK Payload

      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.

      BASCOM-Quellcode: NRF_TX_Arduino_Nano_web.bas

      1. ' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      2. ' Nordic nRF24L01 data link demo in Enhanced Shockburst mode
      3. ' By Evert Dekker 2007 nRF24L01@Evertdekker dotje com
      4. ' Created with Bascom-Avr: 1.11.8.3
      5. '
      6. ' Expanded with ACK Payload and created with Bascom-AVR 2079 Michael Kinz 12/2016
      7. '------------------------------------------------------------------
      8. $regfile = "M328pdef.dat" 'Arduini Nano V3
      9. $crystal = 16000000
      10. $baud = 9600
      11. $hwstack = 40
      12. $swstack = 20
      13. $framesize = 40
      14. '=== Declare sub routines
      15. Declare Sub R_register(byval Command As Byte , Byval C_bytes As Byte)
      16. Declare Sub W_register(byval C_bytes As Byte)
      17. '=== Constante ===
      18. 'Define nRF24L01 interrupt flag's
      19. Const Idle_int = &H00 'Idle, no interrupt pending
      20. Const Max_rt = &H10 'Max #of Tx Retrans Interrupt
      21. Const Tx_ds = &H20 'Tx Data Sent Interrupt
      22. Const Rx_dr = &H40 'Rx Data Received
      23. 'SPI(nRF24L01) commands
      24. Const Read_reg = &H00 'Define Read Command To Register
      25. Const Write_reg = &H20 'Define Write Command To Register
      26. Const Rd_rx_pload = &H61 'Define Rx Payload Register Address
      27. Const Wr_tx_pload = &HA0 'Define Tx Payload Register Address
      28. Const Flush_tx = &HE1 'Define Flush Tx Register Command
      29. Const Flush_rx = &HE2 'Define Flush Rx Register Command
      30. Const Reuse_tx_pl = &HE3 'Define Reuse Tx Payload Register Command
      31. Const Nop_comm = &HFF 'Define No Operation , Might Be Used To Read Status Register
      32. 'SPI(nRF24L01) registers(addresses)
      33. Const Config_nrf = &H00 'Config' register address
      34. Const En_aa = &H01 'Enable Auto Acknowledgment' register address
      35. Const En_rxaddr = &H02 'Enabled RX addresses' register address
      36. Const Setup_aw = &H03 'Setup address width' register address
      37. Const Setup_retr = &H04 'Setup Auto. Retrans' register address
      38. Const Rf_ch = &H05 'RF channel' register address
      39. Const Rf_setup = &H06 'RF setup' register address
      40. Const Status = &H07 'Status' register address
      41. Const Observe_tx = &H08 'Observe TX' register address
      42. Const Cd = &H09 'Carrier Detect' register address
      43. Const Rx_addr_p0 = &H0A 'RX address pipe0' register address
      44. Const Rx_addr_p1 = &H0B 'RX address pipe1' register address
      45. Const Rx_addr_p2 = &H0C 'RX address pipe2' register address
      46. Const Rx_addr_p3 = &H0D 'RX address pipe3' register address
      47. Const Rx_addr_p4 = &H0E 'RX address pipe4' register address
      48. Const Rx_addr_p5 = &H0F 'RX address pipe5' register address
      49. Const Tx_addr = &H10 'TX address' register address
      50. Const Rx_pw_p0 = &H11 'RX payload width, pipe0' register address
      51. Const Rx_pw_p1 = &H12 'RX payload width, pipe1' register address
      52. Const Rx_pw_p2 = &H13 'RX payload width, pipe2' register address
      53. Const Rx_pw_p3 = &H14 'RX payload width, pipe3' register address
      54. Const Rx_pw_p4 = &H15 'RX payload width, pipe4' register address
      55. Const Rx_pw_p5 = &H16 'RX payload width, pipe5' register address
      56. Const Fifo_status = &H17 'FIFO Status Register' register address
      57. Const Feature = &H1D 'ACK Payload Feature
      58. Const Dyn_pd = &H1C 'Dynamic Payload Register
      59. Const R_rx_pl_wid = &H60 'Payload RX Length
      60. 'Various
      61. Const True = 1
      62. Const False = 0
      63. Config Portb.2 = Output 'SPI Master needed
      64. '=== Config hardware ===
      65. Config Spi = Hard , Interrupt = Off , Data Order = Msb , Master = Yes , Polarity = Low , Phase = 0 , Clockrate = 4 , Noss = 1
      66. 'Software SPI is NOT working with the nRF24L01, use hardware SPI only, but the SS pin must be controlled by our self
      67. Config Pind.2 = Output 'CE pin is output
      68. Config Pind.3 = Output 'SS pin is output
      69. Config Pind.7 = Input 'IRQ pin is input
      70. Nrf_ce Alias Portd.2
      71. Nrf_csn Alias Portd.3
      72. Irq Alias Pind.7
      73. Config Pinb.0 = Output
      74. Led Alias Portb.0 'Debug LED
      75. Config Lcdpin = Pin , Db4 = Portc.2 , Db5 = Portc.3 , Db6 = Portc.4 , Db7 = Portc.5 , E = Portc.1 , Rs = Portc.0
      76. Config Lcd = 16x2
      77. Initlcd
      78. Cursor Off
      79. Cls
      80. Lcd "NRF 24L01+"
      81. Spiinit 'init the spi pins
      82. Set Nrf_ce
      83. Waitms 10 'Wait a moment until all hardware is stable
      84. Reset Nrf_ce 'Set CE pin low
      85. Reset Nrf_csn 'Set SS pin low (CSN pin)
      86. Dim D_bytes(33) As Byte , B_bytes(33) As Byte 'Dim the bytes use for SPI, D_bytes = outgoing B_bytes = Incoming
      87. Dim Temp As Byte , W As Word , Temp2 As Byte
      88. Dim Packet_count As Word 'Payload Sender
      89. Led = 1
      90. Print "TX_device" 'Send to terminal who i'm
      91. D_bytes(1) = Flush_tx 'Flush the TX_fifo buffer
      92. Call W_register(1)
      93. D_bytes(1) = Write_reg + Status 'Reset the IRQ bits
      94. D_bytes(2) = &B00110000
      95. Call W_register(2)
      96. Gosub Setup_tx
      97. Do 'Main loop for TX
      98. Toggle Led
      99. D_bytes(1) = Wr_tx_pload 'Put 5 bytes in the TX pload buffer
      100. D_bytes(2) = &HAA 'Byte 1
      101. D_bytes(3) = &HBB 'Byte 2
      102. D_bytes(4) = &HCC 'Byte 3
      103. D_bytes(5) = High(packet_count) 'Byte 4
      104. D_bytes(6) = Low(packet_count) 'Byte 5 will be increase every loop
      105. Call W_register(6) 'Write 6 bytes to register
      106. Waitms 2
      107. Set Nrf_ce 'Set CE for a short moment to transmit the fifo buffer
      108. Waitms 1 '
      109. Reset Nrf_ce '
      110. Waitms 247 'Some delay to read the output on the terminal, line can be removed for max. speed
      111. W = 0 'Counter for time out
      112. Do
      113. If Irq = 0 Then
      114. Call R_register(status , 1)
      115. Temp = B_bytes(1) And &B01110000 'Mask the IRQ bits out the status byte
      116. 'Print Bin(b_bytes(temp));
      117. Select Case Temp 'Which IRQ occurs
      118. Case Max_rt 'MAX_RT
      119. ' Print "Maximum number of TX retries, Flushing the TX buffer now !"
      120. D_bytes(1) = Flush_tx 'Flush the TX buffer
      121. Call W_register(1)
      122. D_bytes(1) = Write_reg + Status
      123. D_bytes(2) = &B00010000 'Clear the MAX_RT IRQ bit
      124. Call W_register(2)
      125. Exit Do
      126. Case Tx_ds 'TX_DS
      127. Print
      128. Print "P " ; Packet_count ; '" send and ACK received." ;
      129. D_bytes(1) = Write_reg + Status
      130. D_bytes(2) = &B00100000 'Clear the TX_DS IRQ bit
      131. Call W_register(2)
      132. Incr Packet_count
      133. Exit Do
      134. Case Else 'Other IRQ ??
      135. D_bytes(1) = Flush_tx 'Flush the TX buffer
      136. Call W_register(1)
      137. If Temp.6 = 1 Then
      138. Reset Nrf_ce
      139. Do
      140. Call R_register(r_rx_pl_wid , 1) 'Anzahl Bytes im Empfangspuffer lesen
      141. Temp2 = B_bytes(1)
      142. Call R_register(rd_rx_pload , Temp2) 'Lese X bytes RX payload register
      143. 'Print "Pload " ;
      144. Print " ";
      145. Locate 2 , 2
      146. If B_bytes(1) < 10 Then 'Formatierung für Output
      147. Print "0";
      148. Lcd "0"
      149. End If
      150. Print B_bytes(1) ; ":" ;
      151. Lcd B_bytes(1) ; ":"
      152. If B_bytes(2) < 10 Then 'Formatierung für Output
      153. Print "0";
      154. Lcd "0"
      155. End If
      156. Print B_bytes(2) ; ":" ;
      157. Lcd B_bytes(2) ; ":"
      158. If B_bytes(3) < 10 Then 'Formatierung für Output
      159. Print "0";
      160. Lcd "0"
      161. End If
      162. Print B_bytes(3) ;
      163. Lcd B_bytes(3)
      164. Call R_register(fifo_status , 1) 'Read FIFO_STATUS
      165. Loop Until B_bytes(1).0 = True 'Test or RX_EMPTY bit is true, RX FIFO empty
      166. D_bytes(1) = Write_reg + Status 'Reset the RX_DR status bit
      167. D_bytes(2) = &B01000000 'Write 1 to RX_DR bit to reset IRQ
      168. Call W_register(2)
      169. Set Nrf_ce
      170. End If
      171. End Select
      172. End If
      173. Waitms 1 'Time out waiting for IRQ 1ms * 100
      174. Incr W 'Increment W
      175. If W > 100 Then 'Waited for 100ms
      176. Print "No irq response from RF20L01 within 100ms"
      177. Exit Do 'Exit the wait loop
      178. End If
      179. Loop
      180. Loop
      181. End
      182. '=== Sub routines ===
      183. Sub W_register(byval C_bytes As Byte) 'Write register with SPI
      184. Reset Nrf_csn 'Manual control SS pin, set SS low before shifting out the bytes
      185. Spiout D_bytes(1) , C_bytes 'Shiftout the data bytes trough SPI , C_bytes is the amount bytes to be written
      186. Set Nrf_csn 'Set SS high
      187. End Sub
      188. Sub R_register(byval Command As Byte , Byval C_bytes As Byte) As Byte 'C_bytes = Count_bytes, number off bytes to be read
      189. Reset Nrf_csn 'Manual controle SS pin, set low before shifting in/out the bytes
      190. Spiout Command , 1 'First shiftout the register to be read
      191. Spiin B_bytes(1) , C_bytes 'Read back the bytes from SPI sended by nRF20L01
      192. Set Nrf_csn 'Set SS back to high level
      193. End Sub
      194. Setup_tx: 'Setup for TX
      195. D_bytes(1) = Write_reg + Tx_addr 'TX adress
      196. D_bytes(2) = &H34
      197. D_bytes(3) = &H43
      198. D_bytes(4) = &H10
      199. D_bytes(5) = &H10
      200. D_bytes(6) = &H01
      201. Call W_register(6)
      202. D_bytes(1) = Write_reg + Rx_addr_p0 'RX adress for pipe0
      203. D_bytes(2) = &H34
      204. D_bytes(3) = &H43
      205. D_bytes(4) = &H10
      206. D_bytes(5) = &H10
      207. D_bytes(6) = &H01
      208. Call W_register(6)
      209. D_bytes(1) = Write_reg + En_aa 'Enable auto ACK for pipe0
      210. D_bytes(2) = &H01
      211. Call W_register(2)
      212. D_bytes(1) = Write_reg + En_rxaddr 'Enable RX adress for pipe0
      213. D_bytes(2) = &H01
      214. Call W_register(2)
      215. D_bytes(1) = Write_reg + Rf_ch 'Set RF channel
      216. D_bytes(2) = 40
      217. Call W_register(2)
      218. D_bytes(1) = Write_reg + Rf_setup 'Setup RF-> Output power 0dbm, datarate 2Mbps and LNA gain on
      219. D_bytes(2) = &H0F
      220. Call W_register(2)
      221. D_bytes(1) = Write_reg + Config_nrf 'Setup CONFIG-> PRX=0(TX_device), PWR_UP=1, CRC 2bytes, Enable CRC
      222. D_bytes(2) = &H0E
      223. Call W_register(2)
      224. D_bytes(1) = Write_reg + Setup_retr 'Retransmission auf
      225. D_bytes(2) = &H20
      226. Call W_register(2)
      227. D_bytes(1) = Write_reg + Feature 'Feature Register Enables_Dynamic_Payload_Length=1 Enable_ACK_Payload=1 '
      228. D_bytes(2) = &H06
      229. Call W_register(2)
      230. D_bytes(1) = Write_reg + Dyn_pd 'Dynamic Payload Register - Enable dynamic payload length data pipe 0 = 1 '
      231. D_bytes(2) = &H01
      232. Call W_register(2)
      233. Return
      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.

      BASCOM-Quellcode: NRF_RX_ATMega32_web.bas

      1. ' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      2. ' Nordic nRF24L01 data link demo in Enhanced Shockburst mode
      3. ' By Evert Dekker 2007 nRF24L01@Evertdekker dotje com
      4. ' Created with Bascom-Avr: 1.11.8.3
      5. '
      6. ' Expanded with ACK Payload and 1.8" Color Display (hkipnik)
      7. ' Created with Bascom-AVR 2079 Michael Kinz 12/2016
      8. ' ------------------------------------------------------------------
      9. $regfile = "M32def.dat"
      10. $crystal = 16000000
      11. $baud = 9600
      12. $hwstack = 128 'needed for display
      13. $swstack = 128
      14. $framesize = 128
      15. '=== Declare sub routines
      16. Declare Sub R_register(byval Command As Byte , Byval C_bytes As Byte)
      17. Declare Sub W_register(byval C_bytes As Byte)
      18. '=== Constante ===
      19. 'Define nRF24L01 interrupt flag's
      20. Const Idle_int = &H00 'Idle, no interrupt pending
      21. Const Max_rt = &H10 'Max #of Tx Retrans Interrupt
      22. Const Tx_ds = &H20 'Tx Data Sent Interrupt
      23. Const Rx_dr = &H40 'Rx Data Received
      24. 'SPI(nRF24L01) commands
      25. Const Read_reg = &H00 'Define Read Command To Register
      26. Const Write_reg = &H20 'Define Write Command To Register
      27. Const Rd_rx_pload = &H61 'Define Rx Payload Register Address
      28. Const Wr_tx_pload = &HA0 'Define Tx Payload Register Address
      29. Const W_ack_payload = &HA8
      30. Const Flush_tx = &HE1 'Define Flush Tx Register Command
      31. Const Flush_rx = &HE2 'Define Flush Rx Register Command
      32. Const Reuse_tx_pl = &HE3 'Define Reuse Tx Payload Register Command
      33. Const Nop_comm = &HFF 'Define No Operation , Might Be Used To Read Status Register
      34. 'SPI(nRF24L01) registers(addresses)
      35. Const Config_nrf = &H00 'Config' register address
      36. Const En_aa = &H01 'Enable Auto Acknowledgment' register address
      37. Const En_rxaddr = &H02 'Enabled RX addresses' register address
      38. Const Setup_aw = &H03 'Setup address width' register address
      39. Const Setup_retr = &H04 'Setup Auto. Retrans' register address
      40. Const Rf_ch = &H05 'RF channel' register address
      41. Const Rf_setup = &H06 'RF setup' register address
      42. Const Status = &H07 'Status' register address
      43. Const Observe_tx = &H08 'Observe TX' register address
      44. Const Cd = &H09 'Carrier Detect' register address
      45. Const Rx_addr_p0 = &H0A 'RX address pipe0' register address
      46. Const Rx_addr_p1 = &H0B 'RX address pipe1' register address
      47. Const Rx_addr_p2 = &H0C 'RX address pipe2' register address
      48. Const Rx_addr_p3 = &H0D 'RX address pipe3' register address
      49. Const Rx_addr_p4 = &H0E 'RX address pipe4' register address
      50. Const Rx_addr_p5 = &H0F 'RX address pipe5' register address
      51. Const Tx_addr = &H10 'TX address' register address
      52. Const Rx_pw_p0 = &H11 'RX payload width, pipe0' register address
      53. Const Rx_pw_p1 = &H12 'RX payload width, pipe1' register address
      54. Const Rx_pw_p2 = &H13 'RX payload width, pipe2' register address
      55. Const Rx_pw_p3 = &H14 'RX payload width, pipe3' register address
      56. Const Rx_pw_p4 = &H15 'RX payload width, pipe4' register address
      57. Const Rx_pw_p5 = &H16 'RX payload width, pipe5' register address
      58. Const Fifo_status = &H17 'FIFO Status Register' register address
      59. Const Feature = &H1D 'ACK Payload Feature
      60. Const Dyn_pd = &H1C 'Dynamic Payload Register
      61. 'Various
      62. Const True = 1
      63. Const False = 0
      64. Config Pinb.4 = Output 'needed for SPI-Master Function
      65. Portb.4 = 1
      66. Config Portb.3 = Output
      67. Config Portb.2 = Output
      68. Config Portb.1 = Output
      69. Lcd_cs Alias Portb.1
      70. Lcd_dc Alias Portb.3
      71. Lcd_reset Alias Portb.2
      72. Portb.2 = 1
      73. Config Pind.5 = Output 'CE pin is output
      74. Config Pind.7 = Output 'SS pin is output
      75. Config Pind.4 = Input 'IRQ pin is input
      76. Nrf_ce Alias Portd.5
      77. Nrf_csn Alias Portd.7
      78. Irq Alias Pind.4
      79. '###################################################################################
      80. Const Sdcard = 0
      81. Const Modus = 1 '0=Portrait 1=Landscape
      82. Const Driver = 0 '0=ST7735 1=ILI9163
      83. 'only Display ST7735
      84. 'Display typ Red or black Tab have different RGB order
      85. 'color of the display plastic wrap
      86. Const Disp_typ = 0 'RGB order 0=Black Tab 1=Red Tab
      87. $include "18Spi_declarations.inc"
      88. Print "Start NRF24L01+ RX + Display"
      89. Dim Lsyssec As Long
      90. Dim Atemp As String * 16
      91. Dim Halbflag As Bit
      92. Dim Halb As Bit
      93. Config Clock = User 'create clock variables and time functions
      94. Config Timer1 = Timer , Prescale = 256 'user defined clock
      95. On Timer1 T1irq
      96. Start Timer1
      97. Enable Timer1
      98. Enable Interrupts
      99. '###################################################################################
      100. Config Portd.6 = Output
      101. Led Alias Portd.6 'debug led
      102. Gosub Activate_display 'SPI init LCD
      103. '*******************************************************************************
      104. 'Init the Dispaly
      105. Waitms 10
      106. Lcd_cs = 0
      107. Call Lcd_init()
      108. Waitms 10
      109. Call Lcd_clear(gray4)
      110. Waitms 100
      111. Atemp = "NRF24L01+"
      112. Print Atemp
      113. Call Lcd_text(atemp , 5 , 10 , 2 , Blue , Gray4)
      114. Atemp = "Payload "
      115. Call Lcd_text(atemp , 5 , 30 , 2 , Blue , Gray4)
      116. '*******************************************************************************
      117. Waitms 10
      118. Gosub Activate_nrf 'init the spi pins
      119. Print "Los geht's"
      120. Set Nrf_ce
      121. Waitms 10 'Wait a moment until all hardware is stable
      122. Reset Nrf_ce 'Set CE pin low
      123. Reset Nrf_csn 'Set SS pin low (CSN pin)
      124. Dim D_bytes(33) As Byte , B_bytes(33) As Byte 'Dim the bytes use for SPI, D_bytes = outgoing B_bytes = Incoming
      125. Dim Btemp As Byte , W As Word
      126. Dim Packet_count As Byte
      127. '===Main rx==========================================================================================================================
      128. 'Main_rx:
      129. Call R_register(status , 1) 'Read STATUS register
      130. Print "Rx_device" 'Send to terminal who i'm
      131. Reset Nrf_ce 'Set CE low to access the registers
      132. Gosub Setup_rx 'Setup the nRF24L01 for RX
      133. Waitms 2 'Add a delay before going in RX
      134. Set Nrf_ce 'Set nRF20L01 in RX mode
      135. Do 'Main loop for RX
      136. If Irq = 0 Then 'Wait until IRQ occurs, pin becomes low on interrupt
      137. Reset Nrf_ce 'Receiver must be disabled before reading pload
      138. Do 'Loop until all 3 fifo buffers are empty
      139. Call R_register(rd_rx_pload , 5) 'Read 5 bytes RX pload register
      140. 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
      141. Gosub Activate_display
      142. Atemp = Hex(b_bytes(1)) + Hex(b_bytes(2)) + Hex(b_bytes(3)) + Hex(b_bytes(4)) + Hex(b_bytes(5))
      143. Call Lcd_text(atemp , 5 , 50 , 2 , Blue , Gray4)
      144. Gosub Activate_nrf
      145. Call R_register(fifo_status , 1) 'Read FIFO_STATUS
      146. Toggle Led 'debug
      147. Loop Until B_bytes(1).0 = True 'Test or RX_EMPTY bit is true, RX FIFO empty
      148. D_bytes(1) = Write_reg + Status 'Reset the RX_DR status bit
      149. D_bytes(2) = &B01000000 'Write 1 to RX_DR bit to reset IRQ
      150. Call W_register(2)
      151. Set Nrf_ce 'Enable receiver again
      152. Waitms 2
      153. Gosub Activate_nrf
      154. D_bytes(1) = Flush_tx 'Flush the TX_fifo buffer
      155. Call W_register(1)
      156. D_bytes(1) = W_ack_payload 'Put bytes in the TX pload buffer
      157. D_bytes(4) = _sec
      158. D_bytes(3) = _min
      159. D_bytes(2) = _hour
      160. Call W_register(4)
      161. End If
      162. If Halbflag = 1 Then
      163. Halbflag = 0
      164. If Halb = 1 Then
      165. Gosub Activate_display
      166. Call Lcd_text(time$ , 5 , 70 , 2 , Blue , Gray4)
      167. End If
      168. End If
      169. Loop
      170. End
      171. '=== Sub routines ===
      172. Sub W_register(byval C_bytes As Byte) 'Write register with SPI
      173. Reset Nrf_csn 'Manual control SS pin, set SS low before shifting out the bytes
      174. Spiout D_bytes(1) , C_bytes 'Shiftout the data bytes trough SPI , C_bytes is the amount bytes to be written
      175. Set Nrf_csn 'Set SS high
      176. End Sub
      177. Sub R_register(byval Command As Byte , Byval C_bytes As Byte) As Byte 'C_bytes = Count_bytes, number off bytes to be read
      178. Reset Nrf_csn 'Manual controle SS pin, set low before shifting in/out the bytes
      179. Spiout Command , 1 'First shiftout the register to be read
      180. Spiin B_bytes(1) , C_bytes 'Read back the bytes from SPI sended by nRF20L01
      181. Set Nrf_csn 'Set SS back to high level
      182. End Sub
      183. Setup_rx: 'Setup for RX
      184. D_bytes(1) = Write_reg + Rx_addr_p0 'RX adress for pipe0
      185. D_bytes(2) = &H34
      186. D_bytes(3) = &H43
      187. D_bytes(4) = &H10
      188. D_bytes(5) = &H10
      189. D_bytes(6) = &H01
      190. Call W_register(6) 'Send 6 bytes to SPI
      191. D_bytes(1) = Write_reg + En_aa 'Enable auto ACK for pipe0
      192. D_bytes(2) = &H01
      193. Call W_register(2)
      194. D_bytes(1) = Write_reg + En_rxaddr 'Enable RX adress for pipe0
      195. D_bytes(2) = &H01
      196. Call W_register(2)
      197. D_bytes(1) = Write_reg + Rf_ch 'Set RF channel
      198. D_bytes(2) = 40
      199. Call W_register(2)
      200. D_bytes(1) = Write_reg + Rx_pw_p0 'Set RX pload width for pipe0
      201. D_bytes(2) = 5
      202. Call W_register(2)
      203. D_bytes(1) = Write_reg + Rf_setup 'Setup RF-> Output power 0dbm, datarate 2Mbps and LNA gain on
      204. D_bytes(2) = &H0F
      205. Call W_register(2)
      206. D_bytes(1) = Write_reg + Config_nrf 'Setup CONFIG-> PRX=1(RX_device), PWR_UP=1, CRC 2bytes, Enable CRC
      207. D_bytes(2) = &H0F
      208. Call W_register(2)
      209. D_bytes(1) = Write_reg + Feature '
      210. D_bytes(2) = &H06
      211. Call W_register(2)
      212. D_bytes(1) = Write_reg + Dyn_pd '
      213. D_bytes(2) = &H01
      214. Call W_register(2)
      215. Return
      216. Activate_display:
      217. Nrf_csn = 1
      218. Config Spi = Hard , Interrupt = Off , Data Order = Msb , Master = Yes , Polarity = High , Phase = 1 , Clockrate = 4 , Noss = 1
      219. Spsr.0 = 1
      220. Spiinit
      221. Return
      222. Activate_nrf:
      223. Lcd_cs = 1
      224. Config Spi = Hard , Interrupt = Off , Data Order = Msb , Master = Yes , Polarity = Low , Phase = 0 , Clockrate = 4 , Noss = 1
      225. Spsr.0 = 1
      226. Spiinit
      227. Return
      228. T1irq:
      229. Timer1 = 34286 '500ms
      230. Halbflag = 1
      231. Toggle Halb
      232. If Halb = 1 Then Incr Lsyssec
      233. Return
      234. Getdatetime:
      235. Time$ = Time(lsyssec)
      236. Return
      237. Settime:
      238. Return
      239. '*******************************************************************************
      240. $include "ST7735_functions.inc"
      241. $include "Font\Font12x16.font"
      242. $include "Font\Font8x8.font"
      243. $include "Font\font8x12.font"
      244. $include "Font\font6x10.font"
      245. $include "Font\font10x16.font"
      246. '*******************************************************************************
      Alles anzeigen


      NRF24L01.jpg
      Dateien
      • NRF24L01P.zip

        (20,68 kB, 150 mal heruntergeladen, zuletzt: )
    • Martin schrieb:

      Hallo Charly,
      das kann das Problem sein
      ich habe 2.0.7.7
      werde mich mal updaten
      wenn man sich aber die beiden geposteten Quellcodes anschaut, dann wurden diese mit einer noch älteren Bascom-Version erstellt und auch wohl compiliert.

      Kommt es oft vor, dass ältere Codes dann nicht mehr nach Bascom-updates laufen und abgeändert werden müssen?
      Das wäre aber schade, wenn man ältere Codes gespeichert hat und diese jedesmal angepasst werden müssen.
      Vor allem die Fehlersuche, wenn man weiß, das der Code auch mal funktioniert hatte.
    • Hallo Michael,

      ich habe deinen Beitrag mit großem Interesse gelesen. Ich würde allerdings mich auch Hardwareseitig mit diesem Problem beschäftigen wollen. Ich denke das es Hilfreich wäre wenn in der *.zip auch der Stromlaufplan der beiden Module wäre. Ich denke meine Vorredner wären bestimmt auch daran Interessiert.

      Mit freundlichen Grüßen

      daschmann
    • Einen Schaltplan habe ich leider nicht, es war ein Steckbrett Aufbau. Deswegen hatte ich auch die Belegung in das Programm geschrieben.

      Also SCK,MOSI,MISO sind ja klar, die werden direkt verbunden.
      Die Belegung von CSN,CE und IRQ steht im Quelltext, wobei die Bezeichnung CSN am NRF24 Modul für das SPI Chip select steht, also damit wird die SPI Übertragung eingeleitet.
    • hallo Michael,

      ich habe noch einige Fragen zu deinem Projekt: Die nRF24L01+ Module arbeiten mit 3,3V der ATMega32 arbeitet mit 5V, könnte mit 3,3V arbeiten und das TFT- Display möchte aber mit 5V versorgt werden. Der Arduino Nano bekommt 5V über USB oder Pinx. der nRF24L01+ möchte 3,3V haben und das dortige LCD Modul hat welche Spannungsschiene ? Warum werden im Sender und im Empfänger unterschiedliche MCU's eingesetzt, könnte es nicht 2 x Arduino Nano sein ? Natürlich dann mit geändertem Quelltext und neu Kompilierung. Sind etwa Si- Dioden im + Zweig zur Spannungsreduzierung ? Das Bild lässt keine Aussage zu.
      Ich würde mich über eine Antwort freuen.

      Mit freundlichen Grüßen

      daschmann
    • Auf der Rückseite der Schaltpläne ist der Beutel mit den Abblockkondensatoren und den Versorgungspins der Kontroller hingetackert :D
      Raum für Notizen

      -----------------------------------------------------------------------------------------------------

      -----------------------------------------------------------------------------------------------------
    • Hallo Freunde,

      die Schaltungen sind ganz gut und schön aber sie gehen etwas am eigentlichen Thema von Michael vorbei. Von den vielen kleinen Fehlern wie Quarzlast C's und Abblock- C's sind die Schaltungen für andere Quelltexte vorgesehen noch sind die Fragen beantwortet. Wie ich den Quelltexten entnehme sind im Original die nRF's das Grafikdisplay mit dem SPI Bus verbunden. Warum eine ATMega32 MCU und ein Arduino Nano verwendet wurde ist damit auch nicht beantwortet. Oder ob es nicht möglich ist zwei Arduino Nano zu verwenden ist auch nicht für die Allgemeinheit geklärt worden.
      Wenn in dem Forum Fragen auftauchen sollte man sie auch sachgerecht beantworten wenn man kann.

      Mit freundlichen Grüßen

      daschmann
    • daschmann schrieb:

      Der Arduino Nano bekommt 5V über USB oder Pinx. der nRF24L01+ möchte 3,3V haben und das dortige LCD Modul hat welche Spannungsschiene ?
      Das LCD bekommt 5V und wird mit 3,3V vom AVR angesteuert.
      Die 3,3V werden mit LM317 erzeugt.

      daschmann schrieb:

      Warum werden im Sender und im Empfänger unterschiedliche MCU's eingesetzt, könnte es nicht 2 x Arduino Nano sein ?
      Ich hatte gerade keinen Atmega16 und auch keinen Atmega 256 zur Hand. Ansonsten hätten es auch 2 Arduino Nano sein können.
      Attinys benutze ich fast nie, weil sie zu wenig Speicher, keine Mul-Einheit und zu wenige Schnittstellen haben.

      daschmann schrieb:

      Sind etwa Si- Dioden im + Zweig zur Spannungsreduzierung ?
      Nein, Dioden sind in solchen Schaltungen nicht empfehlenswert. Es gibt durch das Senden einen erhöhten Strombedarf, die weiche Kennlinie von Dioden passen dann nicht zum Spannungsbereich des Sendemoduls.

      daschmann schrieb:

      Wenn in dem Forum Fragen auftauchen sollte man sie auch sachgerecht beantworten wenn man kann.
      Natürlich sind Fragen auch möglichst zu beantworten, aber bedenke bitte, dass wir hier nicht bezahlt werden, das hier ist alles freiwillig und kostenlos.
      Wenn man sich mit dem Thema NRF24 beschäftigt, sollte man über Grundlagen, wie Spannungsversorgung und Wahl des AVRs, hinaus sein, sonst gibt es nur Frust.
      Ich selbst habe mich lange mit dem Thema beschäftigt und beim ersten mal hat es auch nicht geklappt.
      Wenn ich hier eine funktionierende Software poste, dann steckt da meist viel Arbeit (Freizeit) mit Versuch und Irrtum drin. Die wichtigen Sachen sind im Quelltext als Kommentar hinterlegt und doch habe ich sie nochmal beantwortet.

      Ich hoffe, du kannst trotzdem von meinen Bemühungen profitieren.

      Es wäre nett, wenn hier in diesem Thread auch nur noch Fragen bezüglich des Themas gestellt werden.
      Allgemeines gehört in das Hauptforum und von dort kann man sich ja auf dieses Thema hier beziehen/verlinken.

      Danke und Gruß, Michael
    • Hallo Michael,

      ich habe von dir nun meine Fragen korrekt beantwortet bekommen und möchte mich ausdrücklich dafür bedanken. Ich hatte schon gedacht das ein Arduino Nano wenn im TX eingesetzt auch im RX gehen sollte. An Hand des Bildes kann man beim besten Willen die Spannungslevel nicht ausmachen nun ist alles soweit klar. Ich weiß das so ein Programm kein Sonntagsspaziergang ist und viel Mühe macht, habe auf anderen Gebieten mit Bascom auch meine Erfahrungen gemacht und auch viel Lehrgeld bezahlt. Es ist aber immer wieder schön wenn jemand mal seine Erfahrungen veröffentlicht und alle Interessenten davon lernen können.
      Ich habe deshalb so *gebohrt' weil ich nicht nur so einfach auf dem Steckbrett was nachbauen will, sondern das soll darin Enden das ein TX- und RX- Modul entsteht welches mal alle Pipelines benutzt Analogwerte und Tastenzustände übertragen kann welche dann auf dem RX- Board dargestellt werden können. Ich bin gerade dabei meine Gedanken in einen Stromlaufplan zu verewigen mit dem Ziel zwei Platinen zu haben. Und wer es wünscht sich mittels GERBER- File einen Satz Platinen anfertigen zu lassen. Zu gegebener Zeit werde ich mich mal wieder melden was da so entstanden ist.

      Also nochmals Danke ich wollte nicht nerven.

      Mit freundlichen Grüßen

      daschmann