Jump to content
43oh

[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.

Link to post
Share on other sites
  • Replies 352
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Popular Posts

Hi folks... So I'm a little new to Energia, but since I wrote a library for the nRF24L01+ digital transceivers for native C-based apps I figured it'd be a great idea to port this to Energia.   I'm r

Ok, so I ported the Enrf library over so that it works with both MSP430 and Stellaris.  Seems to work great.  I am watching the tx rx demo between msp430g2553 (on the RX side), and the StellarPad doin

Okie doke - https://github.com/spirilis/Enrf24   The examples are the same as the ones I posted... I'll write up the API in a wiki page soon.  Alternately, I put documentation in the Enrf24.h file f

Posted Images

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.

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.

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.

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.

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.

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.

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).

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...