NRF24L01 component problem

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 7.

Moderator: Benj

Post Reply
mnf
Valued Contributor
Valued Contributor
Posts: 1189
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

NRF24L01 component problem

Post by mnf »

Spent several hours trying to get the nrf24l01+ unit working - first with a Arduino nano and then thinking that a power supply issue may be occurring with an FTDI Nero (a clone with a higher spec)

So - with the nano initialise wasn't returning. With the Nero - 0 was always returned.

Taking a peek into the C code generated:

Code: Select all

MX_UINT16 FCD_0e0f1_nRF24L01__Initialise()
{
    //Local variable definitions
    MX_UINT16 FCL_TEMP;
    MX_UINT16 FCR_RETVAL;

    FCP_SET(B, B, 0x1, 0x0, 0);
    FCP_SET(B, B, 0x4, 0x2, 1);
    FCI_DELAYBYTE_US(40);
    FC_CAL_SPI_Master_Init_1();
    FCI_DELAYBYTE_US(40);
    FCD_0e0f1_nRF24L01__WriteRegister(0x24, 0x4F);
    FCD_0e0f1_nRF24L01__WriteRegister(0x26, 0x07);
    FCD_0e0f1_nRF24L01__WriteRegister(0x3C, 0x00);
    FCD_0e0f1_nRF24L01__WriteRegister(0x27, 0x70);
    FCD_0e0f1_nRF24L01__WriteRegister(0x40, 64);
    FCD_0e0f1_nRF24L01__FlushRx();
    FCD_0e0f1_nRF24L01__FlushTx();

    return (FCR_RETVAL);
}
The return value FCR_RETVAL is declared but never actually set - so theoretically any value may be returned but seems to be 0 in practice!

So the 0 return for failure seems to be guaranteed and the success value (non zero) for a correct startup isn't happening....

Anyone else encountered this / has a workaround? (Ignore the 'return' value and assume the nrf24l01 is okay?)

Martin

jgu1
Posts: 1333
Joined: Tue Oct 06, 2009 9:39 am
Has thanked: 1135 times
Been thanked: 299 times
Contact:

Re: NRF24L01 component problem

Post by jgu1 »

Hi Martin!

Sorry I can't help you, but have you seen Johns nice project here: http://www.matrixtsl.com/mmforums/viewt ... 26&t=18044
And one more here from John: http://www.matrixtsl.com/mmforums/viewt ... 26&t=18538

Maybe something you can use. :D

Br Jorgen

mnf
Valued Contributor
Valued Contributor
Posts: 1189
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: NRF24L01 component problem

Post by mnf »

Thanks Jorgen,

I see John just ignores the return value - this may be the way to go although the documentation still needs correcting.

I tried with a very simple setup and CheckRx always seems to return 1 so something still amiss with my setup - using a header board with voltage regulator and capacitors on (which runs correctly under the Arduino IDE).

On the plus side I did get a DFRobot LCD shield working (hurray)



Martin

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: NRF24L01 component problem

Post by Benj »

Hello,

One problem that might be causing you issues is SPI on AVR is a bit fiddly.

There is a hardware SS pin which is part of the SPI peripheral. If you leave this pin as an input (default)and the microcontroller reads the pin as a logic low then it can trigger the SPI into slave mode and cause problems such as blocking code execution and not allowing the SPI to work correctly.

When using SPI on an AVR I would always advise you to use the SS pin as your chip select pin, this way the pin is always configured as an output which stops the problem from occurring.

mnf
Valued Contributor
Valued Contributor
Posts: 1189
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: NRF24L01 component problem

Post by mnf »

Thanks,

Now up and running. I also found I needed to set the prescaler to 4 (or more).

I have attached my simple transmit and receive programs - transmit a block of 32 bytes data, receive prints data to UART
nrfsend.fcfx
(10.56 KiB) Downloaded 421 times
nrfrcv.fcfx
(12.74 KiB) Downloaded 368 times

mnf
Valued Contributor
Valued Contributor
Posts: 1189
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: NRF24L01 component problem

Post by mnf »

I've been playing with a nr24l01+ for a few days. I'd like to get a shock burst example up and running..
One thing I'd like added to the component is a write data (Ben/Leigh please) so something like Write data(addr, data, length).
I actually did this by tweaking the C code in a separate macro and it works well ( there is an unused variable FCL_IDX in the code suggesting this was intended but not implemented? But this approach lacks portability (see separate thread about accessing pin data from a component)
My program generates data in 32 byte packets and it seems inefficient to write it to the radio chip via a second buffer, and it makes such things as setting the pipe address very neat too.

Thanks in advance

Martin

mnf
Valued Contributor
Valued Contributor
Posts: 1189
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: NRF24L01 component problem

Post by mnf »

Ok: to demonstrate what I'm after.

The following two programs demonstrate an enhanced ShockBurst(tm) exchange between two NRF24L01+ chips - connected to an Arduino. I use very little from the actual NRF24L01 library - but have pulled the code into C code blocks and modified.

I've added Write/Read data blocks, tweaked the startup slightly and am just using the default pipe (E7E7E7E7E7) of the NRF chips. I'm also using the interrupt pin to signal data recvd or transmitted (but I busy wait on it changing - bad I know but I wanted to get it working first, ideally the MCU would be doing something else or asleep here)

But: because I'm using C code the pins (CE and CSN) are hard coded (also bad) - see my previous questions about outputting to a components pins... (I suppose rewriting the entire component would fix this)

It works well - the transmitter outputting a variable length data block (I couldn't get the variable length to work using the standard component startup) and the receiver acknowledges with some data (a count of packets received as a string) . Both ends output a fair amount of debug (transmitter - Shows interrupt flags (status reg) and the Ack packet received. Receiver shows the data packet received.)

If anyone would like to try it:

Pin Digital2 is connected to interrupt (IRQ)
D8 (PortB 0) is CE
D10 (PortB 2) is CSN
D11-D13 are Standard MOSI MISO and SCK
I found I needed a Prescaler of Fosc/4

I used NRF24L01+ chips on header boards - which handle the power supply and level issues (and also have labelled pins - a curse on the board manufacturers who don't label the pins on boards)

As an aside - there is a slight mix of local/global variables. I'd far rather Flowcode defaulted to local first when adding a new variable - forcing me to click to add a global variable rather than the current way round.)

I think the current code works at 2Mbs/s - I may experiment with other speeds/powers later :-)

As another aside: It would be good to sell components at a much smaller level.. Many of the packs (Displays for example) - are likely to remain 90% unused. Would it be possible to buy 'just' one component (for say £5). I purchased the debug and a second processor pack in the black Friday sale - but how to access them, no sign in Flowcode or on the website (and yes I did log in and payment was taken)
nrfsend.fcfx
(22.52 KiB) Downloaded 324 times
nrfrcv.fcfx
(19.53 KiB) Downloaded 285 times

Post Reply