Trying to get pipe address but couldn't

136 views
Skip to first unread message

Dario Salvi

unread,
Jan 28, 2014, 4:25:21 AM1/28/14
to nrf24-...@googlegroups.com
Hi,

I am making some extensions to the library (very good work BTW!).
I am now stuck with this problem: I am trying to read some RX_ADDR with this function:

uint8_t* NRF24::getPipeAddress(uint8_t pipe){
    uint8_t len = getAddressSize();
    if((pipe == 0) || (pipe == 1)){
        uint8_t addr[len];
        spiBurstReadRegister(NRF24_REG_0A_RX_ADDR_P0 + pipe, addr, len);
        return addr;
    }
    else if((pipe ==2) || (pipe == 3) || (pipe == 4) || (pipe == 5)){
        uint8_t* addr = getPipeAddress(0);//Get base address
        uint8_t lastbyte[1];
        spiBurstReadRegister(NRF24_REG_0A_RX_ADDR_P0 + pipe, lastbyte, 1);
        addr[len-1] = lastbyte[0];
        return addr;
    }
    else return NULL;
}

but the result is pretty unpredictable, besides, it seems to change depending on time :s

(the getAddress() function reads the SETUP_AW register, and it works)


Any idea?

thanks...

Mike McCauley

unread,
Jan 28, 2014, 4:38:23 AM1/28/14
to nrf24-...@googlegroups.com
Hi,

I think the main problem (or at least one major problem is that your variable
'addr' is on the stack as a temporary variable, but you return its address.
That wont work.

'addr' will need to be declared static or else be at file or global scope.


Cheers.
--
Mike McCauley VK4AMM mi...@airspayce.com
Airspayce Pty Ltd 9 Bulbul Place Currumbin Waters QLD 4223 Australia
http://www.airspayce.com
Phone +61 7 5598-7474 Fax +61 7 5598-7070

Colin Cooper

unread,
Jan 28, 2014, 4:41:19 AM1/28/14
to nrf24-...@googlegroups.com
Also, don't pipes 2-5 share the 4 most significant bytes of pipe 1?  
Is this perhaps composing them using pipe 0's address?: getPipeAddress(0);//Get base address

  Regards,
  Colin Cooper



--
You received this message because you are subscribed to the Google Groups "NRF24-Arduino" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nrf24-arduin...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Dario Salvi

unread,
Jan 28, 2014, 6:39:46 AM1/28/14
to nrf24-...@googlegroups.com
Thank you guys !

You were both right. It seems I am losing my C-programming skills lately :)

The correct function is:

boolean NRF24::getPipeAddress(uint8_t pipe, uint8_t * address){
uint8_t len = getAddressSize();
if((pipe == 0) || (pipe == 1)){
spiBurstReadRegister(NRF24_REG_0A_RX_ADDR_P0 + pipe, address, len);
return true;
}
else if((pipe ==2) || (pipe == 3) || (pipe == 4) || (pipe == 5)){
if(!getPipeAddress(1, address)) //Get base address
return false;
uint8_t lastbyte[1];
spiBurstReadRegister(NRF24_REG_0A_RX_ADDR_P0 + pipe, lastbyte, 1);
address[len-1] = lastbyte[0];
return true;
}
else return false;
}


2014-01-28 Colin Cooper <cdcoo...@googlemail.com>:
Reply all
Reply to author
Forward
0 new messages