Jump to content
spirilis

[Energia Library] Nordic nRF24L01+ library

Recommended Posts

it can be set like this :

in sensor send, get ack, go sleep 100ms, after that go receive for 20-40ms. on RX side you set sending mode(probably using other nrf module if you have more then one sensors, set retransmit to minimum, start transmit.that way nrf will do transmition when remote sensor go online for receive.

Share this post


Link to post
Share on other sites

gotcha... Just be aware, 250Kbps speed doesn't work with the auto-ack retransmit stuff, I found that out by experimentation and analysis with a logic analyzer months ago.  So keep that sort of scheme running at 1 or 2Mbps (with comparably reduced range).

Share this post


Link to post
Share on other sites

bug:

code without

 

  radio.begin();
  radio.setTXaddress((void*)txaddr);

 

 

not work after 

 

 radio.deepsleep();

so it not work like you say(auto-wakeup on flush)

Share this post


Link to post
Share on other sites

Wow ok, I think we have another problem here.  I just set up a set of those demos on a pair of launchpads with Serial output enabled at 9600bps that periodically kicks out the transceiver state, and on the TX side, what I see is anytime I do serial output, the radio.flush() function hangs indefinitely...

 

Sniffing all the I/O with my logic analyzer, it seems like there's a conflict between Energia's handling of the Serial output (which seems to happen in the background BTW) and the SPI I/O going over the USCI_B port.  Periodically when UART characters go out, a mysterious set of 8 clock ticks kick out over the SCLK line (even though the nRF24 CSN line is high).

 

Edit:

Found the bug.

Energia's USCI ISR handler, used for I2C and for Serial I/O, runs the I2C RX/TX handler when SPI is in use.  It should only run this when I2C is in use.

 

Offending section in /Applications/Energia.app/Contents/Resources/Java/hardware/msp430/cores/msp430/usci_isr_handler.c:

__attribute__((interrupt(USCIAB0TX_VECTOR)))
void USCIAB0TX_ISR(void)
{
        /* USCI_A0 UART interrupt? */
        if (UC0IFG & UCA0TXIFG)
                uart_tx_isr();

        /* USCI_B0 I2C TX RX interrupt. */
        if ((UC0IFG & (UCB0TXIFG | UCB0RXIFG)) != 0)
                i2c_txrx_isr();

}

My modified version:

__attribute__((interrupt(USCIAB0TX_VECTOR)))
void USCIAB0TX_ISR(void)
{
        /* USCI_A0 UART interrupt? */
        if (UC0IFG & UCA0TXIFG)
                uart_tx_isr();

        /* USCI_B0 I2C TX RX interrupt. */
        if ((UCB0CTL0 & UCMODE_3) == UCMODE_3 && (UC0IFG & (UCB0TXIFG | UCB0RXIFG)) != 0)
                i2c_txrx_isr();

}

*** NOTE *** No changes necessary to the USCIAB0RX_ISR handler, and that function should be kept in place as is.  This is only a change to the USCIAB0TX_ISR function.

 

This way the i2c_txrx_isr() crap is only considered if I2C mode is actually enabled, i.e. UCB0CTL UCMODE = 0b11 (3, I2C).

This should be pushed up/reported to the Energia devs...  There might be other considerations for the EUSCI chips, I didn't look at that code.

Share this post


Link to post
Share on other sites

Anyway after modifying the Energia core's usci_isr_handler.c for that, my TX demo works correctly, spitting out serial output while simultaneously forcing the LED on my other launchpad to blink (it's running the RXdemo).

 

Also, my latest GIT commit to the project includes my serial-output-ified version of the examples.

Share this post


Link to post
Share on other sites

no. that is nto bug i reported. i removes serial.

 

okay. here is code:

 

void setup() {
  //Serial.begin(9600);
  //Serial.println('1');
  SPI.begin();
  SPI.setDataMode(SPI_MODE0);
  SPI.setBitOrder(1); // MSB-first
  //Serial.println('2');

  radio.begin();  // Defaults 1Mbps, channel 0, max TX power
  Serial.println(radio.radioState());
  radio.setSpeed(1000000);
  radio.setTXaddress((void*)txaddr);

}



void loop() {
   radio.begin();
  radio.setTXaddress((void*)txaddr);
  radio.print(str_on);
  radio.flush();  // Force transmit (don't wait for any more data)
  radio.deepsleep();
  delay(1000);
  radio.begin();
  radio.setTXaddress((void*)txaddr);
  radio.print(str_off);
  radio.flush();  //
  radio.deepsleep();
  delay(1000);
}

 

 

this one is working.

this one is NOT working

 

 

 

void setup() {
  //Serial.begin(9600);
  //Serial.println('1');
  SPI.begin();
  SPI.setDataMode(SPI_MODE0);
  SPI.setBitOrder(1); // MSB-first
  //Serial.println('2');

  radio.begin();  // Defaults 1Mbps, channel 0, max TX power
  Serial.println(radio.radioState());
  radio.setSpeed(1000000);
  radio.setTXaddress((void*)txaddr);

}


void loop() {
  radio.print(str_on);
  radio.flush();  // Force transmit (don't wait for any more data)
  radio.deepsleep();
  delay(1000);
  radio.print(str_off);
  radio.flush();  //
  radio.deepsleep();
  delay(1000);
}

 

also if i switch to lpm3, after that nrf never start at all.

Share this post


Link to post
Share on other sites

ignore that. it still compile it with serial becuase there is one call to serial not commented. without serial it work ok(but still not work after power saver mode)

Share this post


Link to post
Share on other sites

Ok, so I tried using deepsleep() after flush() and it works for me, including serial output (I have patched my Energia core manually), doing a deepsleep() after flush() I still get my LED blinking once a second on the RX launchpad.

 

To patch it, find the Energia install, look for the "hardware/msp430/cores/msp430" directory...

Find "usci_isr_handler.c"

 

Find the section in my post above (http://forum.43oh.com/topic/3237-energia-library-nordic-nrf24l01-library/page-2#entry28498) and add in the "(UCB0CTL0 & UCMODE_3) == UCMODE_3 &&" to the beginning of that if() statement so the i2c_rxtx_isr() only runs if UCMODE = 3.

Share this post


Link to post
Share on other sites

As for LPM3, I'm not sure that'll work right with Energia, because what's waking it up periodically is the WDT ... and that runs off SMCLK, which is disabled in LPM3 mode.

 

You'd have to manually configure Timer_A to run off ACLK, set up the VLOCLK or XT1CLK (for 32.768KHz crystal) yourself, and have a Timer_A ISR that wakes up your chip.

Share this post


Link to post
Share on other sites

thanks,will try patch it.

yes, i am triing figuring out how to change timer in energia to VLO and after that return it back :smile:

without power saving  it get near 0.9mA,that is too much.

 

ps got 0.50mA by patching wiring.c to start at 8mhz. unfortanly at 2mhz nrf just not work.

Share this post


Link to post
Share on other sites

Couple git commits-

 

flush() had a bug where if you ran it while in RX mode, it wouldn't work.  Now flush() has been reworked so it detects a present RX mode, backs out of it (remembering whether or not it was in RX mode when flush() was called), then after all the TX business has completed and IRQs fired, it will run enableRX() to re-enter RX mode.

 

Also flush() now checks if the txbuf is zero-length and return immediately (nothing to send).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×