I managed to get two arduino talking to each other using two NRF24L01+ modules (http://imall.iteadstudio.com/im120606002.html) and the ping example from the MIRF library. Sometimes I get a ping (10-12 ms), but sometimes, randomly, the server doesn't receive the client's message and I get the "Timeout on response from server!" error on the client side.
I want to increase the number of auto retransmit to see if things get better.
This is achievable by altering register as explained in NRF24L01+ data sheet, page 58.
I want to set SETUP_RETR > ARC to the maximum of retransmit : 1111 (15 retransmits) instead of default 0011 (3 retransmits)
How am I supposed to do ?
Should I change the 0 for something else in "#define ARC 0" in the nrf24l01.h:75 file ?
Or should I use configRegister() function from the lib, writing something like this "configRegister(SETUP_RETR,11110000,8)" ? (actually, this doesn't work, the parameters of the function must not be the good ones)
NADPH:
I want to increase the number of auto retransmit to see if things get better.
This is achievable by altering register as explained in NRF24L01+ data sheet, page 58.
I want to set SETUP_RETR > ARC to the maximum of retransmit : 1111 (15 retransmits) instead of default 0011 (3 retransmits)
How am I supposed to do ?
On the nRF24L01+, the SETUP_RETR register is addressed as register 4. It is an 8-bit register, with the top four bits holding the ARD value, and the lower four bits holding the the ARC value. When you set the register, you have to set all 8 bits.
So, if you only want to change the ARC bits, and leave the ARD bits unchanged, you would do the following:
uint8_t ard_arc = spi_read(SETUP_RETR); // get current ARD and ARC values
ard_arc |= 0x0F; // set ARC to 15, while preserving ARD
spi_write(SETUP_RETR,ard_arc); // write back the adjusted register value to the nRF24L01+
To generalise the above so it works for any value for ARC between 0-15, you need an extra step:
uint8_t ard_arc = spi_read(SETUP_RETR); // get current ARD and ARC values
ard_arc &= 0xF0; // set ARC to 0, while preserving ARD
ard_arc |= n; // note, n must be between 0 and 15 for this to work!
spi_write(SETUP_RETR,ard_arc); // write back the adjusted register value to the nRF24L01+
Thanks a lot for your help, you got me unstuck. I really need to learn about bitwise operations.
I got it working using mirf functions for register handling
// Let's see what's in there
uint8_t ard_arc;
Mirf.readRegister( SETUP_RETR, &ard_arc, sizeof(ard_arc) ); // get current ARD and ARC values
Serial.print("maxtranmit set to ");
Serial.println(ard_arc, BIN);
// Let's change it
ard_arc &= 0xF0; // set ARC to 0, while preserving ARD
ard_arc |= 0x0F; // set ARC to 15
Mirf.configRegister(SETUP_RETR,ard_arc); // write back the adjusted register value to the nRF24L01+
Serial.println("maxtranmit changed ... ");
// Let's check
ard_arc = 0;
Mirf.readRegister( SETUP_RETR, &ard_arc, sizeof(ard_arc) ); // get current ARD and ARC values
Serial.print("maxtranmit set to ");
Serial.println(ard_arc, BIN);
And I get this in serial terminal
maxtranmit set to 11
maxtranmit changed ...
maxtranmit set to 1111
Cooool !
The code works great, but increasing number of auto retransmit did not solve the problem of timeout I get. I will open a new thread soon requesting your help if I can't solve it myself.