[jaluino] r430 committed - nRF24L01 wireless module, read registers

15 views
Skip to first unread message

jal...@googlecode.com

unread,
Jun 1, 2013, 1:40:55 PM6/1/13
to jal...@googlegroups.com
Revision: 430
Author: sebastienlelong
Date: Sat Jun 1 10:40:34 2013
Log: nRF24L01 wireless module, read registers
http://code.google.com/p/jaluino/source/detail?r=430

Modified:
/trunk/lib/nrf24l01.jal
/trunk/samples/jaluino_bee_nrf24_readreg.jal

=======================================
--- /trunk/lib/nrf24l01.jal Sun May 26 05:54:49 2013
+++ /trunk/lib/nrf24l01.jal Sat Jun 1 10:40:34 2013
@@ -74,8 +74,11 @@
const byte NRF24_AW = 0
const byte NRF24_ARD = 4
const byte NRF24_ARC = 0
+const byte NRF24_CH = 0
+const byte NRF24_CONT_WAVE = 7
+const byte NRF24_RF_DR_LOW = 5
const byte NRF24_PLL_LOCK = 4
-const byte NRF24_RF_DR = 3
+const byte NRF24_RF_DR_HIGH = 3
const byte NRF24_RF_PWR = 1
const byte NRF24_LNA_HCURR = 0
const byte NRF24_RX_DR = 6
@@ -116,7 +119,7 @@

-- Channel 0 - 127 or 0 - 84 in the US.
if !defined(NRF24_CHANNEL) then
- const byte NRF24_CHANNEL = 1
+ const byte NRF24_CHANNEL = 120
end if

-- Fool proof checks
@@ -150,17 +153,24 @@
procedure nrf24_power_up_rx()
procedure nrf24_flush_rx()
procedure nrf24_set_raddr()
-procedure nrf24_write_register(byte in reg, byte in value[])
-procedure nrf24_transmit_sync(byte in datain[])
-procedure nrf24_read_register(byte in reg, byte in value[])
-procedure nrf24_transfer_sync(byte out dataout[]);, byte in datain[])
+procedure nrf24_write_register(byte in reg, byte in len)
+procedure nrf24_transmit_sync(byte in len)
+procedure nrf24_read_register(byte in reg, byte in len)
+procedure nrf24_transfer_sync(byte in len)

+const byte NRF24_BUFFER_LEN = 10
+var volatile byte nrf24_bufout[NRF24_BUFFER_LEN]
+var volatile byte nrf24_bufin[NRF24_BUFFER_LEN]

-- Initializes pins to communicate with the MiRF module
-- Should be called in the early initializing phase at startup.
procedure nrf24_init() is
- ;nrf24_ce_pin = low
- ;nrf24_csn_pin = high
+ -- init buffers in/out
+ var byte i
+ for count(nrf24_bufin) using i loop
+ nrf24_bufin[i] = 0x0F
+ nrf24_bufout[i] = 0x0F
+ end loop
-- Set receiving address
nrf24_set_raddr()
-- Set RF channel
@@ -198,67 +208,67 @@
-- sets the receiving address
procedure nrf24_set_raddr() is
nrf24_ce_pin = low
- nrf24_write_register(NRF24_RX_ADDR_P1,NRF24_RECEIVE_ADDR)
+ var byte c = count(NRF24_RECEIVE_ADDR)
+ var byte i
+ for c using i loop
+ nrf24_bufin[i] = NRF24_RECEIVE_ADDR[i]
+ end loop
+ nrf24_write_register(NRF24_RX_ADDR_P1,c)
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 value[]) is
+procedure nrf24_write_register(byte in reg, byte in len) is
nrf24_csn_pin = low
spi_master_data = (NRF24_W_REGISTER | (NRF24_REGISTER_MASK & reg))
- nrf24_transmit_sync(value)
+ nrf24_transmit_sync(len)
nrf24_csn_pin = high
end procedure

-procedure nrf24_transmit_sync(byte in datain[]) is
+procedure nrf24_transmit_sync(byte in len) is
var byte i
var byte c
- print_string(serial_hw_data,"count datain: ")
- print_byte_dec(serial_hw_data,byte(count(datain)))
- print_crlf(serial_hw_data)
- for count(datain) using i loop
- c = datain[i]
+ for len using i loop
+ c = nrf24_bufin[i]
spi_master_data = c
end loop
end procedure


-var byte xfer_tmp[] = {0x2F}
-- Reads an array of bytes from the given start position in the MiRF
registers.
-procedure nrf24_read_register(byte in reg, byte out value[]) is
+procedure nrf24_read_register(byte in reg, byte in len) is
nrf24_csn_pin = low
spi_master_data = (NRF24_R_REGISTER | (NRF24_REGISTER_MASK & reg))
- var byte dummy[] = {0x00}
-
- print_string(serial_hw_data,"count val in read: ")
- print_byte_dec(serial_hw_data,byte(count(value)))
- print_crlf(serial_hw_data)
-
- nrf24_transfer_sync(value);,value)
+ nrf24_transfer_sync(len)
nrf24_csn_pin = high
+ ;const byte str[] = "bufout[O]:"
+ ;print_string(serial_hw_data,str)
+ ;print_byte_bin(serial_hw_data,nrf24_bufout[0])
+ ;print_crlf(serial_hw_data)
end procedure

-procedure nrf24_transfer_sync(byte out dataout[]) is ;, byte in datain[])
is
- var byte i
- var byte c
+procedure nrf24_transfer_sync(byte in len) is
+ var byte i = 0
-- assuming dataout/datein have same size
- print_string(serial_hw_data,"count val in xfer: ")
- print_byte_dec(serial_hw_data,byte(count(dataout)))
- print_crlf(serial_hw_data)
- ;for count(dataout) using i loop
- for 1 using i loop
- ;spi_master_data = 0x00
- c = spi_master_data
- xfer_tmp[0] = c
- print_crlf(serial_hw_data)
- print_string(serial_hw_data,"temp i: Ã ")
- print_byte_dec(serial_hw_data,i)
- serial_hw_data = ">"
- print_byte_bin(serial_hw_data,c)
- serial_hw_data = " "
- print_byte_bin(serial_hw_data,xfer_tmp[0])
- print_crlf(serial_hw_data)
+ ;serial_hw_data = "i"
+ ;serial_hw_data = i + "0"
+
+ nrf24_bufout[0] = 0x00
+
+ for len loop
+ ;serial_hw_data = i + "0"
+ ;serial_hw_data = " "
+ nrf24_bufout[i] = spi_master_hw2_exchange(nrf24_bufin[i])
+ ;const byte str[] = "xfer bufout[i]:"
+ ;print_string(serial_hw_data,str)
+ ;print_byte_bin(serial_hw_data,nrf24_bufout[i])
+ ;print_crlf(serial_hw_data)
+ i = i + 1
end loop
+ ;const byte str[] = "xfer bufout[0]:"
+ ;print_string(serial_hw_data,str)
+ ;print_byte_bin(serial_hw_data,nrf24_bufout[0])
+ ;print_crlf(serial_hw_data)
end procedure

;void send(uint8_t *value);
@@ -281,4 +291,4 @@
;void powerDown();
;
;void flushRx();
-;
+
=======================================
--- /trunk/samples/jaluino_bee_nrf24_readreg.jal Sun May 26 05:54:49 2013
+++ /trunk/samples/jaluino_bee_nrf24_readreg.jal Sat Jun 1 10:40:34 2013
@@ -31,6 +31,7 @@
include serial_hardware
serial_hw_init()

+
-- Configure Remappable Pins on MSSP2
-- PPS module writes are protected, we need to first unlock it
pps_control_lock(false)
@@ -71,32 +72,206 @@

nrf24_init()

-
-print_string(serial_hw_data,"Reading registers...")
+const byte str[] = "Reading registers..."
+print_string(serial_hw_data,str)
print_crlf(serial_hw_data)

+
+
forever loop
-var byte rf_setup[] = {0x00}
-print_string(serial_hw_data,"count rf_setup: ")
-print_byte_dec(serial_hw_data,count(rf_setup))
-print_crlf(serial_hw_data)
-nrf24_read_register(NRF24_RF_SETUP,rf_setup)
-print_string(serial_hw_data,"RF_SETUP: ")
-print_byte_bin(serial_hw_data,xfer_tmp[0])
-print_crlf(serial_hw_data)
+ nrf24_read_register(NRF24_CONFIG_REG,1)
+ var byte config = nrf24_bufout[0]
+ const byte str00[] = "CONFIG: "
+ print_string(serial_hw_data,str00)
+ print_byte_bin(serial_hw_data,config)
+ serial_hw_data = ","
+ print_byte_bin(serial_hw_data,nrf24_bufout[0])
+ 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)

-nrf24_read_register(NRF24_CONFIG_REG,rf_setup)
-print_string(serial_hw_data,"CONFIG: ")
-print_byte_bin(serial_hw_data,xfer_tmp[0])
-print_crlf(serial_hw_data)

-nrf24_read_register(NRF24_RX_ADDR_P1,rf_setup)
-print_string(serial_hw_data,"NRF24_RX_ADDR_P1: ")
-print_byte_bin(serial_hw_data,xfer_tmp[0])
-print_crlf(serial_hw_data)
+ nrf24_read_register(NRF24_EN_AA,1)
+ var byte en_aa = nrf24_bufout[0]
+ const byte str9[] = "EN_AA: "
+ print_string(serial_hw_data,str9)
+ print_byte_bin(serial_hw_data,en_aa)
+ 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)

-delay_1s(2)
+ nrf24_read_register(NRF24_EN_RXADDR,1)
+ var byte en_rxaddr = nrf24_bufout[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)

-end loop
+ nrf24_read_register(NRF24_SETUP_AW,1)
+ var byte setup_aw = nrf24_bufout[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)

+ nrf24_read_register(NRF24_SETUP_RETR,1)
+ var byte setup_retr = nrf24_bufout[0]
+ const byte str25[] = "SETUP_RETR: "
+ print_string(serial_hw_data,str25)
+ print_byte_bin(serial_hw_data,setup_retr)
+ 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)
+ 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_bufout[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_bufout[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_bufout[i]
+ ;print_byte_hex(serial_hw_data,c)
+ serial_hw_data = c + "0"
+ serial_hw_data = ","
+ i = i + 1
+ end loop
+ print_crlf(serial_hw_data)
+
+
+ print_crlf(serial_hw_data)
+ const byte str37[] = "..."
+ print_string(serial_hw_data,str37)
+ print_crlf(serial_hw_data)
+ print_crlf(serial_hw_data)
+ delay_1s(10)
+
+
+end loop
+;
+;
Reply all
Reply to author
Forward
0 new messages