[jaluino] r439 committed - started implementing different rx pipes

8 views
Skip to first unread message

jal...@googlecode.com

unread,
Aug 18, 2013, 9:58:55 AM8/18/13
to jal...@googlegroups.com
Revision: 439
Author: sebastienlelong
Date: Sun Aug 18 13:58:36 2013 UTC
Log: started implementing different rx pipes
http://code.google.com/p/jaluino/source/detail?r=439

Modified:
/trunk/lib/nrf24l01.jal
/trunk/samples/jaluino_bee_nrf24_ping.jal
/trunk/samples/jaluino_bee_nrf24_pong.jal
/trunk/samples/jaluino_bee_nrf24_receive.jal
/trunk/samples/jaluino_bee_nrf24_send.jal

=======================================
--- /trunk/lib/nrf24l01.jal Sat Aug 17 07:19:44 2013 UTC
+++ /trunk/lib/nrf24l01.jal Sun Aug 18 13:58:36 2013 UTC
@@ -15,12 +15,11 @@
-- Sources: http://github.com/aaronds/arduino-nrf24l01/downloads
--
-- Notes: jalv2 port of MiRF lib for arduino. Greatly inspired from MiRF
lib port for arduino, by
--- Aaron Shrimpton and Stefan Engelke
+-- Aaron Shrimpton and Stefan Engelke.
--
-- TODO:
-- * remove delay between csn low/high ?
-- * implement multiple pipeline (probably needs to revise buffers)
--- * rename buffers, confusing (in/out)
-- * implement channel scanner to pick the best available (based on
round-trip time ?)
-- * implement helper such as speed select, power select,...
-- ...
@@ -55,6 +54,8 @@
const byte NRF24_RX_PW_P4 = 0x15
const byte NRF24_RX_PW_P5 = 0x16
const byte NRF24_FIFO_STATUS = 0x17
+const byte NRF24_DYNPD = 0x1C
+const byte NRF24_FEATURE = 0x1D

-- Bit Mnemonics
const byte NRF24_MASK_RX_DR = 6
@@ -98,6 +99,13 @@
const byte NRF24_TX_EMPTY = 4
const byte NRF24_RX_FULL = 1
const byte NRF24_RX_EMPTY = 0
+const byte NRF24_EN_DPL = 2
+const byte NRF24_DPL_P5 = 5
+const byte NRF24_DPL_P4 = 4
+const byte NRF24_DPL_P3 = 3
+const byte NRF24_DPL_P2 = 2
+const byte NRF24_DPL_P1 = 1
+const byte NRF24_DPL_P0 = 0

-- Instruction Mnemonics --
const byte NRF24_R_REGISTER = 0x00
@@ -109,14 +117,15 @@
const byte NRF24_FLUSH_RX_REG = 0xE2
const byte NRF24_REUSE_TX_PL = 0xE3
const byte NRF24_NOP = 0xFF
+const byte NRF24_ACTIVATE = 0x50
+

-- Defaulting
--
-- Nrf24l settings
-const byte NRF24_ADDR_LEN = 5 ; seb: was used to loop over some arrays,
still useful ? (we have count() in jalv2)
-;const byte NRF24_CONFIG = ((1<<NRF24_EN_CRC) | (0<<NRF24_CRCO) )
-const byte NRF24_CONFIG = ((0<<NRF24_EN_CRC) | (0<<NRF24_CRCO) ) -- test
with Pi
-;const byte NRF24_CONFIG = (0<<NRF24_CRCO)
+const byte NRF24_ADDR_LEN = 5
+-- Enable CRC, 1-byte length
+const byte NRF24_CONFIG = ((1<<NRF24_EN_CRC) | (0<<NRF24_CRCO) )

-- Payload width in bytes default 16 max 32
if !defined(NRF24_PAYLOAD_SIZE) then
@@ -151,15 +160,18 @@
-- internal state: in read mode ?
var bit nrf24_ptx

+-- Store the pipe number from which data was received
+var byte nrf24_last_pipe_number = 0xFF -- impossible value as init
+
-- ------
-- API --
-- ------
procedure nrf24_init()
-procedure nrf24_config_register(byte in reg, byte in value)
+procedure nrf24_write_byte_register(byte in reg, byte in value)
procedure nrf24_power_up_rx()
procedure nrf24_flush_rx()
-procedure nrf24_set_raddr()
-procedure nrf24_write_register(byte in reg, byte in len)
+procedure nrf24_set_rx_pipe(byte in pipe, byte in addr[])
+procedure nrf24_write_array_register(byte in reg, byte in data[])
procedure nrf24_transmit_sync(byte in len)
procedure nrf24_read_register(byte in reg, byte in len)
procedure nrf24_transfer_sync(byte in len)
@@ -178,23 +190,21 @@
-- init buffers in/out
var byte i
for count(nrf24_bufwrite) using i loop
+ -- arbitrary value
nrf24_bufwrite[i] = 0x0F
nrf24_bufread[i] = 0x0F
end loop
- -- Set receiving address
- nrf24_set_raddr()
+ -- Set receiving address, on pipe 1 (pipe 0 is used to auto-ACK,
combined with TX address)
+ nrf24_set_rx_pipe(1,NRF24_RECEIVE_ADDR)
-- Set RF channel
- nrf24_config_register(NRF24_RF_CH,NRF24_CHANNEL)
- -- Set length of incoming payload
- nrf24_config_register(NRF24_RX_PW_P0, NRF24_PAYLOAD_SIZE)
- nrf24_config_register(NRF24_RX_PW_P1, NRF24_PAYLOAD_SIZE)
+ nrf24_write_byte_register(NRF24_RF_CH,NRF24_CHANNEL)
-- Start receiver
nrf24_power_up_rx()
nrf24_flush_rx()
end procedure

--- Clocks only one byte into the given MiRF register
-procedure nrf24_config_register(byte in reg, byte in value) is
+-- Write an array of data into a register
+procedure nrf24_write_byte_register(byte in reg, byte in value) is
nrf24_csn_pin = low
var byte _trash = spi_master_exchange(NRF24_W_REGISTER |
(NRF24_REGISTER_MASK & reg))
_trash = spi_master_exchange(value)
@@ -204,9 +214,9 @@
procedure nrf24_power_up_rx() is
nrf24_ptx = 0
nrf24_ce_pin = low
- nrf24_config_register(NRF24_CONFIG_REG, NRF24_CONFIG | (
(1<<NRF24_PWR_UP) | (1<<NRF24_PRIM_RX) ) )
+ nrf24_write_byte_register(NRF24_CONFIG_REG, NRF24_CONFIG | (
(1<<NRF24_PWR_UP) | (1<<NRF24_PRIM_RX) ) )
nrf24_ce_pin = high
- nrf24_config_register(NRF24_STATUS,(1 << NRF24_TX_DS) | (1 <<
NRF24_MAX_RT));
+ nrf24_write_byte_register(NRF24_STATUS,(1 << NRF24_TX_DS) | (1 <<
NRF24_MAX_RT));
end procedure

procedure nrf24_flush_rx() is
@@ -215,21 +225,57 @@
nrf24_csn_pin = high
end procedure

--- sets the receiving address
-procedure nrf24_set_raddr() is
+-- sets the receiving address for a pipe number,
+-- and set payload width as well
+procedure nrf24_set_rx_pipe(byte in pipe, byte in addr[]) is
nrf24_ce_pin = low
- var byte c = count(NRF24_RECEIVE_ADDR)
- var byte i
- for c using i loop
- nrf24_bufwrite[i] = NRF24_RECEIVE_ADDR[i]
- end loop
- nrf24_write_register(NRF24_RX_ADDR_P1,c)
+ -- Pipe 0 and 1 can be 5-bytes long, but others are derived from pipe 1,
+ -- only the latest byte is considered
+ var byte last = addr[count(addr)-1]
+ print_byte_hex(serial_hw_data,last)
+ print_crlf(serial_hw_data)
+ case pipe of
+ 0: block
+ nrf24_write_array_register(NRF24_RX_ADDR_P0,addr)
+ nrf24_write_byte_register(NRF24_RX_PW_P0, NRF24_PAYLOAD_SIZE)
+ end block
+ 1: block
+ nrf24_write_array_register(NRF24_RX_ADDR_P1,addr)
+ nrf24_write_byte_register(NRF24_RX_PW_P1, NRF24_PAYLOAD_SIZE)
+ end block
+ 2: block
+ nrf24_write_byte_register(NRF24_RX_ADDR_P2,last)
+ nrf24_write_byte_register(NRF24_RX_PW_P2, NRF24_PAYLOAD_SIZE)
+ end block
+ 3: block
+ nrf24_write_byte_register(NRF24_RX_ADDR_P3,last)
+ nrf24_write_byte_register(NRF24_RX_PW_P3, NRF24_PAYLOAD_SIZE)
+ end block
+ 4: block
+ nrf24_write_byte_register(NRF24_RX_ADDR_P4,last)
+ nrf24_write_byte_register(NRF24_RX_PW_P4, NRF24_PAYLOAD_SIZE)
+ end block
+ 5: block
+ nrf24_write_byte_register(NRF24_RX_ADDR_P5,last)
+ nrf24_write_byte_register(NRF24_RX_PW_P5, NRF24_PAYLOAD_SIZE)
+ end block
+ end case
+ -- Enable data pipe (note, P0 and P1 are set to 1 by default, not an
issue though if
+ -- we set them here)
+ nrf24_read_register(NRF24_EN_RXADDR,1)
+ nrf24_write_byte_register(NRF24_EN_RXADDR,(nrf24_bufread[0] |
(1<<pipe)))
+
nrf24_ce_pin = high
end procedure

--- Writes an array of bytes into inte the MiRF registers.
-procedure nrf24_write_register(byte in reg, byte in len) is
+-- Write an array of data into a register
+procedure nrf24_write_array_register(byte in reg, byte in data[]) is
nrf24_csn_pin = low
+ var byte len = byte(count(data))
+ var byte i
+ for len using i loop
+ nrf24_bufwrite[i] = data[i]
+ end loop
var byte _trash = spi_master_exchange(NRF24_W_REGISTER |
(NRF24_REGISTER_MASK & reg))
nrf24_transmit_sync(len)
nrf24_csn_pin = high
@@ -303,12 +349,12 @@

procedure nrf24_power_up_tx() is
nrf24_ptx = 1
- nrf24_config_register(NRF24_CONFIG_REG, NRF24_CONFIG | (
(1<<NRF24_PWR_UP) | (0<<NRF24_PRIM_RX) ) )
+ nrf24_write_byte_register(NRF24_CONFIG_REG, NRF24_CONFIG | (
(1<<NRF24_PWR_UP) | (0<<NRF24_PRIM_RX) ) )
end procedure

procedure nrf24_power_down() is
nrf24_ce_pin = low
- nrf24_config_register(NRF24_CONFIG_REG, NRF24_CONFIG)
+ nrf24_write_byte_register(NRF24_CONFIG_REG, NRF24_CONFIG)
end procedure

-- Test if chip is still sending.
@@ -352,13 +398,18 @@
end function

-- Reads payload bytes into data array
--- If reads from the 3-levels FIFO. All RX channels (pipes)
--- shere the FIFO, so you get data from any data pipes
+-- It reads from the 3-levels FIFO. All RX channels (pipes)
+-- share the FIFO, so you get data from any data pipes
procedure nrf24_get_data() is
+ -- store current data pipe number from which we received data
+ var byte st = nrf24_get_status()
+ nrf24_last_pipe_number = (st>>NRF24_RX_P_NO) & 0b111
+
nrf24_csn_pin = low -- Pull down chip select
var byte _trash = spi_master_exchange(NRF24_R_RX_PAYLOAD)
nrf24_transfer_sync(NRF24_PAYLOAD_SIZE)
nrf24_csn_pin = high -- Pull up chip select
+
-- NVI: per product spec, p 67, note c:
-- "The RX_DR IRQ is asserted by a new packet arrival event. The
procedure
-- for handling this interrupt should be: 1) read payload through SPI,
@@ -367,21 +418,14 @@
-- repeat from step 1)."
-- So if we're going to clear RX_DR here, we need to check the RX FIFO
-- in the dataReady() function
- nrf24_config_register(NRF24_STATUS,(1<<NRF24_RX_DR)) -- Reset status
register
+ nrf24_write_byte_register(NRF24_STATUS,(1<<NRF24_RX_DR)) -- Reset
status register
end procedure

-- Sets the transmitting address
procedure nrf24_set_taddr(byte in adr[]) is
- -- load input buffer (to send to NRF24)
- -- /!\ assuming adr is adr[NRF24_ADDR_LEN]
- var byte i = 0
- for NRF24_ADDR_LEN loop
- nrf24_bufwrite[i] = adr[i]
- i = i + 1
- end loop
+ nrf24_write_array_register(NRF24_TX_ADDR,adr)
-- RX_ADDR_P0 must be set to the sending addr for auto ack to work.
- nrf24_write_register(NRF24_RX_ADDR_P0,NRF24_ADDR_LEN)
- nrf24_write_register(NRF24_TX_ADDR,NRF24_ADDR_LEN)
+ nrf24_write_array_register(NRF24_RX_ADDR_P0,adr)
end procedure

-- Payload can be more than 1 byte long, so we need to
@@ -411,6 +455,7 @@

end function

+
var byte _nrf24_send_next_buffer_index = 0
-- pseudo-var to send a byte, blocking call
-- (will block until sent)
@@ -433,189 +478,223 @@

end procedure

-procedure nrf24_print_registers() is
+procedure nrf24_toggle_features() is
+ nrf24_csn_pin = low
+ nrf24_transfer_sync(NRF24_ACTIVATE)
+ nrf24_transfer_sync(0x73)
+ nrf24_csn_pin = high
+end procedure
+
+-- !!! untested
+procedure nrf24_enable_dynamic_payloads() is
+ -- Enable dynamic payload throughout the system
+ nrf24_read_register(NRF24_FEATURE,1)
+ var byte tmp[1]
+ tmp[0] = (nrf24_bufread[0] | (1<<NRF24_EN_DPL))
+ nrf24_write_array_register(NRF24_TX_ADDR,tmp)
+ -- If it didn't work, the features are not enabled
+ nrf24_read_register(NRF24_FEATURE,1)
+ var byte ok = nrf24_bufread[0]
+ if ok == 0 then
+ -- So enable them and try again
+ nrf24_toggle_features()
+ nrf24_write_array_register(NRF24_FEATURE,tmp)
+ end if
+
+ -- Enable dynamic payload on all pipes
+ --
+ -- Not sure the use case of only having dynamic payload on certain
+ -- pipes, so the library does not support it.
+ nrf24_read_register(NRF24_DYNPD,1)
+ tmp[0] = (nrf24_bufread[0] | (1<<NRF24_DPL_P5) | (1<<NRF24_DPL_P4) |
(1<<NRF24_DPL_P3) | (1<<NRF24_DPL_P2) | (1<<NRF24_DPL_P1) |
(1<<NRF24_DPL_P0) )
+ nrf24_write_array_register(NRF24_DYNPD,tmp)
+
+ ;dynamic_payloads_enabled = true;
+end procedure
+
+
+-- ---------------------- --
+-- Print/Debug procedures --
+-- ---------------------- --
+
+procedure nrf24_print_status() is
+ var byte st = nrf24_get_status()
+ const byte st00[] = "STATUS\t\t = "
+ print_string(serial_hw_data,st00)
+ print_byte_bin(serial_hw_data,st)
+ const byte st01[] = " RX_DR="
+ print_string(serial_hw_data,st01)
+ print_byte_dec(serial_hw_data,((st>>NRF24_RX_DR) & 1))
+ const byte st02[] = " TX_DS="
+ print_string(serial_hw_data,st02)
+ print_byte_dec(serial_hw_data,((st>>NRF24_TX_DS) & 1))
+ const byte st03[] = " MAX_RT="
+ print_string(serial_hw_data,st03)
+ print_byte_dec(serial_hw_data,((st>>NRF24_MAX_RT) & 1))
+ const byte st04[] = " RX_P_NO="
+ print_string(serial_hw_data,st04)
+ print_byte_dec(serial_hw_data,((st>>NRF24_RX_P_NO) & 0b111))
+ const byte st05[] = " TX_FULL="
+ print_string(serial_hw_data,st05)
+ print_byte_dec(serial_hw_data,((st>>NRF24_TX_FULL) & 1))
+ print_crlf(serial_hw_data)
+end procedure
+
+procedure nrf24_print_rf_setup() is
+ nrf24_read_register(NRF24_RF_SETUP,1)
+ var byte rf_setup = nrf24_bufread[0]
+ const byte rf30[] = "RF_SETUP\t = "
+ print_string(serial_hw_data,rf30)
+ print_byte_bin(serial_hw_data,rf_setup)
+ const byte rf31[] = " CONT_WAVE="
+ print_string(serial_hw_data,rf31)
+ print_byte_dec(serial_hw_data,(rf_setup >> NRF24_CONT_WAVE) & 1)
+ const byte rf32[] = " RF_DR_LOW="
+ print_string(serial_hw_data,rf32)
+ print_byte_dec(serial_hw_data,(rf_setup >> NRF24_RF_DR_LOW) & 1)
+ const byte rf33[] = " PLL_LOCK="
+ print_string(serial_hw_data,rf33)
+ print_byte_dec(serial_hw_data,(rf_setup >> NRF24_PLL_LOCK) & 1)
+ const byte rf34[] = " RF_DR_HIGH="
+ print_string(serial_hw_data,rf34)
+ print_byte_dec(serial_hw_data,(rf_setup >> NRF24_RF_DR_HIGH) & 1)
+ const byte rf35[] = " RF_PWR="
+ print_string(serial_hw_data,rf35)
+ print_byte_dec(serial_hw_data,(rf_setup >> NRF24_RF_PWR) & 0b11)
+ print_crlf(serial_hw_data)
+end procedure
+
+procedure nrf24_print_config() is
nrf24_read_register(NRF24_CONFIG_REG,1)
var byte config = nrf24_bufread[0]
- const byte str00[] = "CONFIG: "
- print_string(serial_hw_data,str00)
+ const byte cf00[] = "CONFIG\t = "
+ print_string(serial_hw_data,cf00)
print_byte_bin(serial_hw_data,config)
- serial_hw_data = ","
- print_byte_bin(serial_hw_data,nrf24_bufread[0])
+ const byte cf2[] = " MASK_RX_DR="
+ print_string(serial_hw_data,cf2)
+ print_byte_dec(serial_hw_data,(config >> NRF24_MASK_RX_DR) & 1)
+ const byte cf3[] = " MASK_TX_DS="
+ print_string(serial_hw_data,cf3)
+ print_byte_dec(serial_hw_data,(config >> NRF24_MASK_TX_DS) & 1)
+ const byte cf4[] = " MASK_MAX_RT="
+ print_string(serial_hw_data,cf4)
+ print_byte_dec(serial_hw_data,(config >> NRF24_MASK_MAX_RT) & 1)
+ const byte cf5[] = " EN_CRC="
+ print_string(serial_hw_data,cf5)
+ print_byte_dec(serial_hw_data,(config >> NRF24_EN_CRC) & 1)
+ const byte cf6[] = " CRCO="
+ print_string(serial_hw_data,cf6)
+ print_byte_dec(serial_hw_data,(config >> NRF24_CRCO) & 1)
+ const byte cf7[] = " PWR_UP="
+ print_string(serial_hw_data,cf7)
+ print_byte_dec(serial_hw_data,(config >> NRF24_PWR_UP) & 1)
+ const byte cf8[] = " PRIM_RX="
+ print_string(serial_hw_data,cf8)
+ print_byte_dec(serial_hw_data,(config >> NRF24_PWR_UP) & 1)
print_crlf(serial_hw_data)
- const byte str2[] = " MASK_RX_DR[6] : "
- print_string(serial_hw_data,str2)
- print_byte_bin(serial_hw_data,(config >> NRF24_MASK_RX_DR) & 1)
- print_crlf(serial_hw_data)
- const byte str3[] = " MASK_TX_DS[5] : "
- print_string(serial_hw_data,str3)
- print_byte_bin(serial_hw_data,(config >> NRF24_MASK_TX_DS) & 1)
- print_crlf(serial_hw_data)
- const byte str4[] = " MASK_MAX_RT[4]: "
- print_string(serial_hw_data,str4)
- print_byte_bin(serial_hw_data,(config >> NRF24_MASK_MAX_RT) & 1)
- print_crlf(serial_hw_data)
- const byte str5[] = " EN_CRC[3] : "
- print_string(serial_hw_data,str5)
- print_byte_bin(serial_hw_data,(config >> NRF24_EN_CRC) & 1)
- print_crlf(serial_hw_data)
- const byte str6[] = " CRCO[2] : "
- print_string(serial_hw_data,str6)
- print_byte_bin(serial_hw_data,(config >> NRF24_CRCO) & 1)
- print_crlf(serial_hw_data)
- const byte str7[] = " PWR_UP[1] : "
- print_string(serial_hw_data,str7)
- print_byte_bin(serial_hw_data,(config >> NRF24_PWR_UP) & 1)
- print_crlf(serial_hw_data)
- const byte str8[] = " PRIM_RX[0] : "
- print_string(serial_hw_data,str8)
- print_byte_bin(serial_hw_data,(config >> NRF24_PWR_UP) & 1)
- print_crlf(serial_hw_data)
- print_crlf(serial_hw_data)
-
-
+end procedure
+
+procedure nrf24_print_en_aa() is
nrf24_read_register(NRF24_EN_AA,1)
var byte en_aa = nrf24_bufread[0]
- const byte str9[] = "EN_AA: "
- print_string(serial_hw_data,str9)
+ const byte en9[] = "EN_AA\t = "
+ print_string(serial_hw_data,en9)
print_byte_bin(serial_hw_data,en_aa)
+ const byte en10[] = " ENAA_P5="
+ print_string(serial_hw_data,en10)
+ print_byte_dec(serial_hw_data,(en_aa >> NRF24_ENAA_P5) & 1)
+ const byte en11[] = " ENAA_P4="
+ print_string(serial_hw_data,en11)
+ print_byte_dec(serial_hw_data,(en_aa >> NRF24_ENAA_P4) & 1)
+ const byte en12[] = " ENAA_P3="
+ print_string(serial_hw_data,en12)
+ print_byte_dec(serial_hw_data,(en_aa >> NRF24_ENAA_P3) & 1)
+ const byte en13[] = " ENAA_P2="
+ print_string(serial_hw_data,en13)
+ print_byte_dec(serial_hw_data,(en_aa >> NRF24_ENAA_P2) & 1)
+ const byte en14[] = " ENAA_P1="
+ print_string(serial_hw_data,en14)
+ print_byte_dec(serial_hw_data,(en_aa >> NRF24_ENAA_P1) & 1)
+ const byte en15[] = " ENAA_P0="
+ print_string(serial_hw_data,en15)
+ print_byte_dec(serial_hw_data,(en_aa >> NRF24_ENAA_P0) & 1)
print_crlf(serial_hw_data)
- const byte str10[] = " ENAA_P5[5] : "
- print_string(serial_hw_data,str10)
- print_byte_bin(serial_hw_data,(en_aa >> NRF24_ENAA_P5) & 1)
- print_crlf(serial_hw_data)
- const byte str11[] = " ENAA_P4[4] : "
- print_string(serial_hw_data,str11)
- print_byte_bin(serial_hw_data,(en_aa >> NRF24_ENAA_P4) & 1)
- print_crlf(serial_hw_data)
- const byte str12[] = " ENAA_P3[3] : "
- print_string(serial_hw_data,str12)
- print_byte_bin(serial_hw_data,(en_aa >> NRF24_ENAA_P3) & 1)
- print_crlf(serial_hw_data)
- const byte str13[] = " ENAA_P2[2] : "
- print_string(serial_hw_data,str13)
- print_byte_bin(serial_hw_data,(en_aa >> NRF24_ENAA_P2) & 1)
- print_crlf(serial_hw_data)
- const byte str14[] = " ENAA_P1[1] : "
- print_string(serial_hw_data,str14)
- print_byte_bin(serial_hw_data,(en_aa >> NRF24_ENAA_P1) & 1)
- print_crlf(serial_hw_data)
- const byte str15[] = " ENAA_P0[0] : "
- print_string(serial_hw_data,str15)
- print_byte_bin(serial_hw_data,(en_aa >> NRF24_ENAA_P0) & 1)
- print_crlf(serial_hw_data)
- print_crlf(serial_hw_data)
-
- nrf24_read_register(NRF24_EN_RXADDR,1)
- var byte en_rxaddr = nrf24_bufread[0]
- const byte str16[] = "EN_RXADDR: "
- print_string(serial_hw_data,str16)
- print_byte_bin(serial_hw_data,en_rxaddr)
- print_crlf(serial_hw_data)
- const byte str17[] = " ERX_P5[5] : "
- print_string(serial_hw_data,str17)
- print_byte_bin(serial_hw_data,(en_rxaddr >> NRF24_ERX_P5) & 1)
- print_crlf(serial_hw_data)
- const byte str18[] = " ERX_P4[4] : "
- print_string(serial_hw_data,str18)
- print_byte_bin(serial_hw_data,(en_rxaddr >> NRF24_ERX_P4) & 1)
- print_crlf(serial_hw_data)
- const byte str19[] = " ERX_P3[3] : "
- print_string(serial_hw_data,str19)
- print_byte_bin(serial_hw_data,(en_rxaddr >> NRF24_ERX_P3) & 1)
- print_crlf(serial_hw_data)
- const byte str20[] = " ERX_P2[2] : "
- print_string(serial_hw_data,str20)
- print_byte_bin(serial_hw_data,(en_rxaddr >> NRF24_ERX_P2) & 1)
- print_crlf(serial_hw_data)
- const byte str21[] = " ERX_P1[1] : "
- print_string(serial_hw_data,str21)
- print_byte_bin(serial_hw_data,(en_rxaddr >> NRF24_ERX_P1) & 1)
- print_crlf(serial_hw_data)
- const byte str22[] = " ERX_P0[0] : "
- print_string(serial_hw_data,str22)
- print_byte_bin(serial_hw_data,(en_rxaddr >> NRF24_ERX_P0) & 1)
- print_crlf(serial_hw_data)
- print_crlf(serial_hw_data)
-
- nrf24_read_register(NRF24_SETUP_AW,1)
- var byte setup_aw = nrf24_bufread[0]
- const byte str23[] = "SETUP_AW: "
- print_string(serial_hw_data,str23)
- print_byte_bin(serial_hw_data,setup_aw)
- print_crlf(serial_hw_data)
- const byte str24[] = " AW[0-1] : "
- print_string(serial_hw_data,str24)
- print_byte_bin(serial_hw_data,(setup_aw >> NRF24_AW) & 1)
- print_crlf(serial_hw_data)
- print_crlf(serial_hw_data)
-
+end procedure
+
+procedure nrf24_print_setup_retr() is
nrf24_read_register(NRF24_SETUP_RETR,1)
var byte setup_retr = nrf24_bufread[0]
- const byte str25[] = "SETUP_RETR: "
- print_string(serial_hw_data,str25)
+ const byte ret25[] = "SETUP_RETR\t = "
+ print_string(serial_hw_data,ret25)
print_byte_bin(serial_hw_data,setup_retr)
+ const byte ret26[] = " ARD="
+ print_string(serial_hw_data,ret26)
+ print_byte_dec(serial_hw_data,(setup_retr >> NRF24_ARD) & 0b1111)
+ const byte ret27[] = " ARC="
+ print_string(serial_hw_data,ret27)
+ print_byte_dec(serial_hw_data,(setup_retr >> NRF24_ARC) & 0b1111)
print_crlf(serial_hw_data)
- const byte str26[] = " ARD[4-7] : "
- print_string(serial_hw_data,str26)
- print_byte_bin(serial_hw_data,(setup_retr >> NRF24_ARD) & 1)
+end procedure
+
+procedure nrf24_print_address_register(byte in str[], byte in reg, byte in
qty) is
+ print_string(serial_hw_data,str)
+ while qty != 0 loop
+ nrf24_read_register(reg,count(NRF24_RECEIVE_ADDR))
+ var byte i
+ for count(NRF24_RECEIVE_ADDR) using i loop
+ print_byte_hex(serial_hw_data,nrf24_bufread[i])
+ end loop
+ serial_hw_data = " "
+ qty = qty - 1
+ reg = reg + 1 -- moving to next adjacent register
+ end loop
print_crlf(serial_hw_data)
- const byte str27[] = " ARC[0-3] : "
- print_string(serial_hw_data,str27)
- print_byte_bin(serial_hw_data,(setup_retr >> NRF24_ARC) & 1)
- print_crlf(serial_hw_data)
- print_crlf(serial_hw_data)
-
- nrf24_read_register(NRF24_RF_CH,1)
- var byte rf_ch = nrf24_bufread[0]
- const byte str28[] = "RF_CH: "
- print_string(serial_hw_data,str28)
- print_byte_bin(serial_hw_data,rf_ch)
- print_crlf(serial_hw_data)
- const byte str29[] = " RF_CH[0-6] : "
- print_string(serial_hw_data,str29)
- print_byte_bin(serial_hw_data,rf_ch)
- print_crlf(serial_hw_data)
- print_crlf(serial_hw_data)
-
- nrf24_read_register(NRF24_RF_SETUP,1)
- var byte rf_setup = nrf24_bufread[0]
- const byte str30[] = "RF_SETUP: "
- print_string(serial_hw_data,str30)
- print_byte_bin(serial_hw_data,rf_setup)
- print_crlf(serial_hw_data)
- const byte str31[] = " CONT_WAVE[7] : "
- print_string(serial_hw_data,str31)
- print_byte_bin(serial_hw_data,(rf_setup >> NRF24_CONT_WAVE) & 1)
- print_crlf(serial_hw_data)
- const byte str32[] = " RF_DR_LOW[5] : "
- print_string(serial_hw_data,str32)
- print_byte_bin(serial_hw_data,(rf_setup >> NRF24_RF_DR_LOW) & 1)
- print_crlf(serial_hw_data)
- const byte str33[] = " PLL_LOCK[4] : "
- print_string(serial_hw_data,str33)
- print_byte_bin(serial_hw_data,(rf_setup >> NRF24_PLL_LOCK) & 1)
- print_crlf(serial_hw_data)
- const byte str34[] = " RF_DR_HIGH[3] : "
- print_string(serial_hw_data,str34)
- print_byte_bin(serial_hw_data,(rf_setup >> NRF24_RF_DR_HIGH) & 1)
- print_crlf(serial_hw_data)
- const byte str35[] = " RF_PWR[1-2] : "
- print_string(serial_hw_data,str35)
- print_byte_bin(serial_hw_data,(rf_setup >> NRF24_RF_PWR) & 0b11)
- print_crlf(serial_hw_data)
- print_crlf(serial_hw_data)
-
- nrf24_read_register(NRF24_RX_ADDR_P1,count(NRF24_RECEIVE_ADDR))
- const byte str36[] = "NRF24_RX_ADDR_P1: "
- print_string(serial_hw_data,str36)
- var byte i = 0
- for count(NRF24_RECEIVE_ADDR) loop
- var byte c = nrf24_bufread[i]
- print_byte_hex(serial_hw_data,c)
- serial_hw_data = c + "0"
- serial_hw_data = ","
- i = i + 1
+end procedure
+
+procedure nrf24_print_byte_register(byte in str[],byte in reg, byte in
qty) is
+ print_string(serial_hw_data,str)
+ while qty != 0 loop
+ nrf24_read_register(reg,1)
+ print_byte_hex(serial_hw_data,nrf24_bufread[0])
+ qty = qty - 1
+ reg = reg + 1 -- moving to next adjacent register
end loop
print_crlf(serial_hw_data)
-
end procedure
+
+procedure nrf24_print_details() is
+
+ nrf24_print_config()
+ nrf24_print_en_aa()
+
+ const byte pd00[] = "RX_ADDR_P0-1 "
+ nrf24_print_address_register(pd00,NRF24_RX_ADDR_P0,2)
+ const byte pd01[] = "RX_ADDR_P2-5 "
+ nrf24_print_byte_register(pd01,NRF24_RX_ADDR_P2,4)
+ const byte pd02[] = "TX_ADDR "
+ nrf24_print_address_register(pd02,NRF24_TX_ADDR,1)
+ const byte pd03[] = "RX_PW_P0-6 "
+ nrf24_print_byte_register(pd03,NRF24_RX_PW_P0,6)
+ const byte pd04[] = "EN_AA "
+ nrf24_print_byte_register(pd04,NRF24_EN_AA,1)
+ const byte pd05[] = "EN_RXADDR "
+ nrf24_print_byte_register(pd05,NRF24_EN_RXADDR,1)
+ const byte pd11[] = "SETUP_AW "
+ nrf24_print_byte_register(pd11,NRF24_SETUP_AW,1)
+ const byte pd06[] = "RF_CH "
+ nrf24_print_byte_register(pd06,NRF24_RF_CH,1)
+ const byte pd07[] = "RF_SETUP "
+ nrf24_print_byte_register(pd07,NRF24_RF_SETUP,1)
+ const byte pd08[] = "CONFIG "
+ nrf24_print_byte_register(pd08,NRF24_CONFIG,1)
+ const byte pd09[] = "DYNPD/FEATURE "
+ nrf24_print_byte_register(pd09,NRF24_DYNPD,2)
+ const byte pd10[] = "FEATURE "
+ nrf24_print_byte_register(pd10,NRF24_FEATURE,1)
+
+ nrf24_setup_retr()
+ nrf24_print_rf_setup()
+ nrf24_print_status()
+
+end procedure
+
=======================================
--- /trunk/samples/jaluino_bee_nrf24_ping.jal Sat Jun 22 15:33:58 2013 UTC
+++ /trunk/samples/jaluino_bee_nrf24_ping.jal Sun Aug 18 13:58:36 2013 UTC
@@ -65,6 +65,7 @@
alias nrf24_csn_pin is pin_A3
-- Receving adress, size must be NRF24_ADDR_LEN
const byte NRF24_RECEIVE_ADDR[] = {0x05,0x06,0x07,0x08,0x09}
+;const byte NRF24_RECEIVE_ADDR[] = {0x73,0x65,0x72,0x76,0x31}
-- will send dword values
const byte NRF24_PAYLOAD_SIZE = 4
include nrf24l01
@@ -80,19 +81,20 @@
print_string(serial_hw_data,str)
print_crlf(serial_hw_data)

-nrf24_print_registers()
+nrf24_print_details()

const byte str2[] = "Sending: "

-- set destination address
var byte taddr[] = {0x00,0x01,0x02,0x03,0x04} -- see receive sample addr
+;var byte taddr[] = {0xF0,0xF0,0xF0,0xF0,0xE3}
nrf24_set_taddr(taddr)

var dword counter = 1
var byte n0 at counter
-var byte n1 at counter + 1
-var byte n2 at counter + 2
-var byte n3 at counter + 3
+var byte n1 at counter : 1
+var byte n2 at counter : 2
+var byte n3 at counter : 3

forever loop

=======================================
--- /trunk/samples/jaluino_bee_nrf24_pong.jal Sun Jun 23 08:12:49 2013 UTC
+++ /trunk/samples/jaluino_bee_nrf24_pong.jal Sun Aug 18 13:58:36 2013 UTC
@@ -72,21 +72,31 @@

nrf24_init()

+var byte pipe2[] = {0x00,0x01,0x02,0x03,0xDD}
+nrf24_set_rx_pipe(2,pipe2)
+
+
+
const byte str[] = "Alive..."
print_string(serial_hw_data,str)
print_crlf(serial_hw_data)

-nrf24_print_registers()
+nrf24_print_details()

var dword counter = 0
-var byte n0 at counter
-var byte n1 at counter + 1
-var byte n2 at counter + 2
-var byte n3 at counter + 3
+var byte n0 at counter : 0
+var byte n1 at counter : 1
+var byte n2 at counter : 2
+var byte n3 at counter : 3

var dword expected = 0
var dword errors = 0

+const byte STR_RECEIVED[] = "Received: "
+const byte STR_FROM[] = "from pipe #"
+const byte STR_EXPECTED[] = "Expected: "
+const byte STR_ERRORS[] = "Errors: "
+
forever loop

onboard_led = high
@@ -103,10 +113,13 @@
expected = counter
end if

- print_string(serial_hw_data,"Received: ")
+ print_string(serial_hw_data,STR_RECEIVED)
print_dword_dec(serial_hw_data,counter)
serial_hw_data = " "
- print_string(serial_hw_data,"Expected: ")
+ print_string(serial_hw_data,STR_FROM)
+ print_byte_dec(serial_hw_data,nrf24_last_pipe_number)
+ serial_hw_data = " "
+ print_string(serial_hw_data,STR_EXPECTED)
print_dword_dec(serial_hw_data,expected)
serial_hw_data = " "

@@ -119,7 +132,7 @@
expected = counter + 1 -- reinit for next value
end if

- print_string(serial_hw_data,"Errors: ")
+ print_string(serial_hw_data,STR_ERRORS)
print_dword_dec(serial_hw_data,errors)
for 20 loop
serial_hw_data = " "
=======================================
--- /trunk/samples/jaluino_bee_nrf24_receive.jal Sun Jun 23 08:12:49 2013
UTC
+++ /trunk/samples/jaluino_bee_nrf24_receive.jal Sun Aug 18 13:58:36 2013
UTC
@@ -76,7 +76,7 @@
print_string(serial_hw_data,str)
print_crlf(serial_hw_data)

-nrf24_print_registers()
+nrf24_print_details()

const byte str2[] = "Received: "
const byte str3[] = "Sleeping..."
=======================================
--- /trunk/samples/jaluino_bee_nrf24_send.jal Sun Jun 23 08:12:49 2013 UTC
+++ /trunk/samples/jaluino_bee_nrf24_send.jal Sun Aug 18 13:58:36 2013 UTC
@@ -81,7 +81,7 @@
print_string(serial_hw_data,str)
print_crlf(serial_hw_data)

-nrf24_print_registers()
+nrf24_print_details()

const byte str2[] = "Sending: "

Reply all
Reply to author
Forward
0 new messages