Quantcast
Channel: MEL PICBASIC Forum
Viewing all articles
Browse latest Browse all 4787

need help coding NRF24L01. What am I missing?

$
0
0
OK first off I know my code is horrible and I have no intention of becoming a professional coder so I'm not going to change that. But to the point, I'm trying to send the number 1, wait a second, the number 2, wait a second, the number 3 then repeat, and have an LED light up based on the # received. I haven't gotten a response from the receiving end no matter what I try. What am I missing here? FYI the most complex thing I've interfaced before these is a 1kbit i2c eeprom so this is a bit over my head. The LED for the number 2 does light up dimly whenever power is connected. Power supply is 3.3 volts. Do these need pull up/down resistors? Did I miss a register? How do I select the data pipe to use, or the addres to send to? I couldn't find any answers in the datasheet or the diyembedded tutorial, and the code examples I have found have all used hardware level SPI and been beyond my understanding.

The address for pipe 1 is "aaaaa" and I've tried to disable every advanced feature on the chip to simplify things. By the way, when I copied and pasted the code, it cut off the first part of my commands. (101010 turns into 101010) WTF??


TX code:
Code:

define osc 4


 a var byte
 csn var portc.1
transmit var portc.3
so var portc.5
si var portc.2
sck var portc.4
high csn
pause 100
low transmit

low csn
shiftout si, sck, 0, [10000, 000000]
high csn
pause 5
low csn
shiftout si, sck, 0, [101010, "a", "a", "a", "a", "a"]
high csn
pause 5
low csn
shiftout si, sck, 0, [110001, 000001]
high csn



  do
 low csn
shiftout si, sck, 0, [100000,  "a", "a", "a", "a", "a", 000001]
high csn
high transmit
pause 10
low transmit
pause 1000

 low csn
shiftout si, sck, 0, [100000,  "a", "a", "a", "a", "a", 000010]
high csn
high transmit
pause 10
low transmit
pause 1000

 low csn
shiftout si, sck, 0, [100000, "a", "a", "a", "a", "a", 000011]
high csn
high transmit
pause 10
low transmit
pause 1000
 
 
 
 
 
  loop


RX code:
Code:

define osc 4
 #config
 __config H'3F46'
#endconfig

 a var byte
 csn var porta.2
receive var portb.0
so var portb.3
si var portb.2
sck var portb.1

high csn
pause 100

low csn
shiftout si, sck, 0, [10000, 000000]
high csn
pause 5
low csn
shiftout si, sck, 0, [101010, "a", "a", "a", "a", "a"]
high csn
pause 5
low csn
shiftout si, sck, 0, [110001, 000001]
high csn
 

  do
 low receive
  low csn
shiftout si, sck, 0, [100000,  "a", "a", "a", "a", "a", 010101]
shiftin so, sck, 0, [a]
high csn
high receive



pause 10
 
 
 
  if a = 1 then
  high portb.4
  low portb.5
  low portb.6
  elseif a = 2 then
  high portb.5
  low portb.4
  low portb.5
  elseif a = 3 then
  high portb.6
  low portb.4
  low portb.5
  else
  high portb.4
  high portb.5
  high portb.6
  endif
 
  pause 20
 
 
 
  loop


Viewing all articles
Browse latest Browse all 4787

Trending Articles