Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of NRF2401P by
Diff: NRF2401P.cpp
- Revision:
- 3:afe8d307b5c3
- Parent:
- 2:ca0a3c0bba70
- Child:
- 4:e55807cf840b
--- a/NRF2401P.cpp Thu Jun 11 23:19:52 2015 +0000 +++ b/NRF2401P.cpp Thu Jun 11 23:38:01 2015 +0000 @@ -41,7 +41,7 @@ csn = 1; ce = 0; dynamic = false; - debug=1|false; + debug=false; }; @@ -209,9 +209,12 @@ } /** * Transmits width bytes of data. width <32 +* returns 1 if succeful */ -char NRF2401P::transmitData( char *data, char width ) +bool NRF2401P::transmitData( char *data, char width ) { + if (width>32) return 0; + //clearStatus(); //ce = 1; csn = 0; @@ -223,9 +226,14 @@ spi->write( data[ i ] ); } csn = 1; - if (debug){ - sprintf(logMsg, " Transmit data %d bytes to %02x (%02x) = %10s", width, address, status, *data ); - log(logMsg); + wait(0.001); + checkStatus(); + if ((status>>4)&1) { // Max retries - flush tx + flushTx(); + } + if (debug) { + sprintf(logMsg, " Transmit data %d bytes to %02x (%02x) = %10s", width, address, status, *data ); + log(logMsg); } return status; @@ -242,15 +250,15 @@ char address = W_ACK_PAYLOAD | (pipe&0x07); int i; // set up for writing - csn = 0; + csn = 0; status = spi->write( address ); for ( i = 0; i <width; i++ ) { spi->write( data[ i ] ); } csn = 1; - if (debug){ - sprintf(logMsg, " acknowledge data %d bytes to %02x (%02x) = %c", width, address, status, *data ); - log(logMsg); + if (debug) { + sprintf(logMsg, " acknowledge data %d bytes to %02x (%02x) = %c", width, address, status, *data ); + log(logMsg); } return status; @@ -365,7 +373,7 @@ flushTx(); flushRx(); writeReg( CONFIG, data ); - writeReg( RX_ADDR_P0, txAdd, addressWidth ); // reset p0 + writeReg( RX_ADDR_P0, txAdd, addressWidth ); // reset p0 writeReg(EN_RXADDR,0x01); // enable pipe 0 for reading // check readReg( 0x00, &data ); @@ -599,8 +607,8 @@ data |= ( 0x01 ); writeReg( 0x00, data ); - if (pipe0Add[0]|pipe0Add[1]|pipe0Add[2]|pipe0Add[3]|pipe0Add[4] >0){ - setRxAddress(pipe0Add,0); + if (pipe0Add[0]|pipe0Add[1]|pipe0Add[2]|pipe0Add[3]|pipe0Add[4] >0) { + setRxAddress(pipe0Add,0); } // check readReg( 0x00, &data );