Issues with SPI write on nRF24L01, byte order incorrect/repeated

How do I write the correct node address into the SPI radio in the correct order ??

I need to send :-
0xE3 0xF0 0xF0 0xF0 0xF0
but when I read back from the nRF24L01 register, it shows
0xE3 0xE3 0xE3 0xE3 0xF0

I confirm the SPI write and read to the register is working ok … I need to send in Least Significant Byte first according to the nRF24L01 datasheet…

Thanks

Server log output :-
4/19/2013 12:12:49 PM: SPI Speed :7500
4/19/2013 12:12:49 PM: RF_CH :0x4C
4/19/2013 12:12:49 PM: RF_SETUP :0x06
4/19/2013 12:12:49 PM: Setting RX addr :�����
4/19/2013 12:12:49 PM: writeRegister input:0xE1
4/19/2013 12:12:49 PM: writeRegister input:0xF0
4/19/2013 12:12:49 PM: writeRegister input:0xF0
4/19/2013 12:12:49 PM: writeRegister input:0xF0
4/19/2013 12:12:49 PM: writeRegister input:0xF0

4/19/2013 12:12:49 PM: Setting TX addr :�����
4/19/2013 12:12:49 PM: writeRegister input:0xE2
4/19/2013 12:12:49 PM: writeRegister input:0xF0
4/19/2013 12:12:49 PM: writeRegister input:0xF0
4/19/2013 12:12:49 PM: writeRegister input:0xF0
4/19/2013 12:12:49 PM: writeRegister input:0xF0
4/19/2013 12:12:49 PM: ReadAddrRegister :10
4/19/2013 12:12:49 PM: ReadAddrRegister return0 :0xE1
4/19/2013 12:12:49 PM: ReadAddrRegister return1 :0xE1
4/19/2013 12:12:49 PM: ReadAddrRegister return2 :0xE1
4/19/2013 12:12:49 PM: ReadAddrRegister return3 :0xE1
4/19/2013 12:12:49 PM: ReadAddrRegister return4 :0xF0

4/19/2013 12:12:49 PM: RX_ADDR_P0 return :�����
4/19/2013 12:12:49 PM: ReadAddrRegister :16
4/19/2013 12:12:49 PM: ReadAddrRegister return0 :0xE2
4/19/2013 12:12:49 PM: ReadAddrRegister return1 :0xE2
4/19/2013 12:12:49 PM: ReadAddrRegister return2 :0xE2
4/19/2013 12:12:49 PM: ReadAddrRegister return3 :0xE2
4/19/2013 12:12:49 PM: ReadAddrRegister return4 :0xF0
4/19/2013 12:12:49 PM: TX_ADDR addr return :�����
4/19/2013 12:12:49 PM: Enable Dynamic Payload

`
// Pipe Addresses for RX & TX
const pipes0 = “\xE3\xF0\xF0\xF0\xF0”;
const pipes1 = “\xE2\xF0\xF0\xF0\xF0”;

function writeRegister(regAddr, data, len) {               

    local i = 0;
    local address = ( W_REGISTER | ( REGISTER_MASK & regAddr ) );                  
    SelectChip();                                           // Chip select
    myspi.write(format("%c",address));            // Write the address
    local status = myspi.read(1);                 // Read status after write

server.log(“writeRegister input:” + format("0x%02X"data[0]));
server.log(“writeRegister input:” + format("0x%02X"data[1]));
server.log(“writeRegister input:” + format("0x%02X"data[2]));
server.log(“writeRegister input:” + format("0x%02X"data[3]));
server.log(“writeRegister input:” + format("0x%02X"data[4]));

    myspi.write(format("%c",data[0]) );    
    myspi.write(format("%c",data[1]) );  
    myspi.write(format("%c",data[2]) );  
    myspi.write(format("%c",data[3]) );  
    myspi.write(format("%c",data[4]) );  
    
    DeselectChip();                                         // Chip deselect 
    return status[0];

}
`

Did you include LSB_FIRST in your first argument to spi.configure?

See http://devwiki.electricimp.com/doku.php?id=electricimpapi:spi:configure

Thanks, I tried LSB_FIRST and nothing was returned, the radio is using MSB_FIRST in the SPI setting…

Found the issue when I hook up to a Logic Analyzer…

This line, writeread() solved it :-

` nodeAddr = myspi.writeread("\xFF\xFF\xFF\xFF\xFF");

Look forward to your results! Keep trying!

hardware.pin8.write(0); // spi latch low

hardware.spi257.write(format("%c", byte)); // how do you write one byte?

hardware.pin8.write(1); // spi latch high

the problem is that pin 8 never goes high, or is sensitive to the loading on the pins when I connect the logic analyzer it works, otherwise pin 8 never goes high again

How is pin 8 being configured? It needs to be configured as DIGITAL_OUT.

it is but what happens is it tristates, i put a temporary fix on it with a 2.2K pullup

// Configure pin 8 as an open drain output with internal pull up
hardware.pin8.configure(DIGITAL_OUT_OD);

Oops that must be it

yes it works now, thaks a lot…it was in front of me all the time and I missed it

You should not be using DIGITAL_OUT_OD or using a pullup if it’s driving a /CS line - you should be using DIGITAL_OUT, which drives high and drives low. No need for a resistor and it will take less power! (because when driven low, there’s no leakage path through a pullup).

I’m writing it this way, is this the optimize way to control the pins ?

`
ce = hardware.pin2; // CE, active when HIGH
cs = hardware.pin5; // CSN, active when LOW
myspi = hardware.spi189; // Use SPI pin 1 - SCK, 8 - MOSI, 9 - MISO

ce.configure(DIGITAL_OUT);          // CE Output pin 
cs.configure(DIGITAL_OUT);          // CS Output pin

function SelectChip()   { cs.write(0); }     
function DeselectChip() { cs.write(1); }  

function ChipEnable()   { ce.write(1); } 
function ChipDisable()  { ce.write(0); } 

`

Got the radio.sent() working… pls help me test if possible…

Now, I’m figuring out on how to get planner’s inputPort to send an array/blob to the buffer…

http://forums.electricimp.com/discussion/999/nordic-nrf24l01-for-the-electric-imp#Item_3

You’d be wise to hold off on that. The Agent in Beta will be so much better and easier to code! When is it coming?