Jump to content
43oh

[Energia Library] Nordic nRF24L01+ library


Recommended Posts

  • 2 weeks later...
  • 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

I still haven't figured out a way to send a struct using this library. Neither write nor print will accept pointer to struct. I know that the RF24 library can do such thing, but it doesn't work with Energia and MSP430. Sorry for asking for it again, but it is a blocker for my project. Any chance you could implement this functionality in some future version or maybe just point me how to do that?

Link to post
Share on other sites

I still haven't figured out a way to send a struct using this library. Neither write nor print will accept pointer to struct. I know that the RF24 library can do such thing, but it doesn't work with Energia and MSP430. Sorry for asking for it again, but it is a blocker for my project. Any chance you could implement this functionality in some future version or maybe just point me how to do that?

Wild guess, but, maybe try casting it to void * (it should take that I think) and be sure to use the .write() variant with the length specified (use sizeof(struct_type) for this)

 

Sent from my Galaxy Note II with Tapatalk 4

 

 

Link to post
Share on other sites

Thank you for the replies.

#include <Enrf24.h>
#include <nRF24L01.h>
#include <SPI.h>

struct color_t {
  byte red;
  byte green;
  byte blue;
};

Enrf24 radio(P2_0, P2_1, P2_2);
const uint8_t txaddr[] = { 0x01, 0x02, 0x03, 0x04, 0x05 };

color_t *data = (color_t *)malloc(sizeof(color_t));

void setup()
{
  SPI.begin();
  SPI.setDataMode(SPI_MODE0);
  SPI.setBitOrder(1);
  
  radio.begin();
  
  radio.setTXaddress((void*)txaddr);
  
  randomSeed(analogRead(1)); //A1
  
  pinMode(RED_LED, OUTPUT);
  pinMode(GREEN_LED, OUTPUT);
  
  if(radio.radioState() != ENRF24_STATE_NOTPRESENT) {
    digitalWrite(GREEN_LED, HIGH);
  } else {
    analogWrite(GREEN_LED, 60);
  }
}

void loop()
{
  digitalWrite(RED_LED, HIGH);
  
  data->red = random(0, 256);
  data->green = random(0, 256);
  data->blue = random(0, 256);
  
  radio.write(data, sizeof(data));
  radio.flush();
  
  delay(20);
  
  digitalWrite(RED_LED, LOW);
  
  delay(2000);
}

This is the code I wrote.

 

I tried:

  1. Pointer returned by malloc, as you can see above
  2. Casting the struct to (void *)
  3. *data and &data
  4. Everything that came to my mind

All of the above using .write() method. None worked for me. The sketch won't even compile as there is "no matching function" or "invalid cast from type 'color_t' to type 'void*'". I ran out of ideas so any help will be appreciated.

Link to post
Share on other sites

Are you even allowed to initialize a global variable like 'data' with a function call? I always thought you had to do the malloc() call inside setup(). Anyway, I recommend using sizeof(struct color_t) for one, and second go ahead and try casting data to void * -- then post your updated code so we know exactly how you're doing it.

 

Sent from my Galaxy Note II with Tapatalk 4

 

 

Link to post
Share on other sites

Malloc was my last try anyway. Here is the code:

#include <Enrf24.h>
#include <nRF24L01.h>
#include <SPI.h>

typedef struct {
  byte red;
  byte green;
  byte blue;
} color_t;

Enrf24 radio(P2_0, P2_1, P2_2);
const uint8_t txaddr[] = { 0x01, 0x02, 0x03, 0x04, 0x05 };

color_t data;

void setup()
{
  SPI.begin();
  SPI.setDataMode(SPI_MODE0);
  SPI.setBitOrder(1);
  
  radio.begin();
  
  radio.setTXaddress((void*)txaddr);
  
  randomSeed(analogRead(1)); //A1
  
  pinMode(RED_LED, OUTPUT);
  pinMode(GREEN_LED, OUTPUT);
  
  if(radio.radioState() != ENRF24_STATE_NOTPRESENT) {
    digitalWrite(GREEN_LED, HIGH);
  } else {
    analogWrite(GREEN_LED, 60);
  }
}

void loop()
{
  digitalWrite(RED_LED, HIGH);
  
  data.red = random(0, 256);
  data.green = random(0, 256);
  data.blue = random(0, 256);
  
  radio.write((void*)data, sizeof(color_t));
  radio.flush();
  
  delay(20);
  
  digitalWrite(RED_LED, LOW);
  
  delay(2000);
}

I changed C++ like struct define to C like typedef. sizeof(struct color_t) will generate another error as compiler is trying to declare color_t again.

Link to post
Share on other sites

Unfortunately it won't :( :

error: invalid conversion from 'void*' to 'const uint8_t* {aka const unsigned char*}' [-fpermissive]
E:\ener10\hardware\msp430\cores\msp430/Print.h:57:20: error:   initializing argument 1 of 'virtual size_t Print::write(const uint8_t*, size_t)' [-fpermissive]
Link to post
Share on other sites
  • 1 month later...

I've got the same problem. Used the Enrf24_RXdemo from the examples. It has the SPI.BEGIN.

It says NO TRANSCEIVER PRESENT.

The same transceiver was tested and works. Checked cabling 3 times. Exchanged MISO/MOSI but that didn't work either.

 

Checked the usci_isr_handler.c and it says:

__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();

}

 

So that's fine as far as I know.

I'm stuck.

Got pins connected to NRF24L01 as follows

P1.5 - SCK

P1.6 - MISO

P1.7 - MOSI

P2.0 - CE

P2.1 - CSN

P2.2 - IRQ

Using MSP-EXP430G2 rev1.5 board.

I don't know what to do from here. Except say  HELP!  :sad: 

Oh for what it's worth. ASteITXdemo is not compiling. Complains about class SPIClass has no member named setModule.

The examples that shipped with the library should work.  Be sure things are hooked up properly.  "NO TRANSCEIVER PRESENT" literally means that the library tried to talk to the module, tried to read what its current "address width" is configured to, and didn't find a valid value.  (this is a convenient register to use b/c it can never be 0x00 or 0xFF, typical values you find in an error condition).

 

At the very least, either the CSN port or the SPI ports aren't set up properly, or the module doesn't have power.  Be sure SPI.begin() was run before the library was initialized...

Link to post
Share on other sites

The AStelTXdemo wasn't written by me, and I think it was written with the Stellaris in mind so you can probably yank the setModule() part from that one.

 

Otherwise, I can't help you with what you've provided here.  Where did you buy your modules?  What are the markings on them?  What have you tested it with--what other hardware, what other libraries.  You do have Vcc and GND hooked up (correctly) right?  Any pictures of your setup?

Link to post
Share on other sites

The AStelTXdemo wasn't written by me, and I think it was written with the Stellaris in mind so you can probably yank the setModule() part from that one.

 

Otherwise, I can't help you with what you've provided here.  Where did you buy your modules?  What are the markings on them?  What have you tested it with--what other hardware, what other libraries.  You do have Vcc and GND hooked up (correctly) right?  Any pictures of your setup?

Ebay: http://www.ebay.com/itm/2PCS-New-NRF24L01-2-4GHz-Antenna-Wireless-Transceiver-Module-Arduino-/360826829171?pt=LH_DefaultDomain_0&hash=item5402f47973

They don't have any specific markings.

Tested with a custom build setup from a friend that had different modules and different pin-layout but when correctly wired it worked.

Tried on arduino Uno with the RF24 and Mirf libraries. They responded with content of registers (channels, power mode etc.)

Had the vcc and gnd hooked up to the pins next to the reset button on the bottom right. Later connected them to the vcc/gns on the top pins. I couldn't attach a photo. This is the same setup: dsc04723.jpg

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