bluehash 1,581 Posted November 25, 2013 Share Posted November 25, 2013 Before I forget, I quickly documented the entire process on my blog http://arduino-for-beginners.blogspot.com/2013/11/stellaris-launchpad-with-nrf24l01.html Thank you! Quote Link to post Share on other sites
maxik 1 Posted December 7, 2013 Share Posted December 7, 2013 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? Quote Link to post Share on other sites
energia 485 Posted December 7, 2013 Share Posted December 7, 2013 Can you post an example Sketch that shows what you are trying to do? Robert Quote Link to post Share on other sites
energia 485 Posted December 7, 2013 Share Posted December 7, 2013 Can you post an example Sketch that shows what you are trying to do? Robert Quote Link to post Share on other sites
spirilis 1,265 Posted December 7, 2013 Author Share Posted December 7, 2013 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 Quote Link to post Share on other sites
maxik 1 Posted December 7, 2013 Share Posted December 7, 2013 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: Pointer returned by malloc, as you can see above Casting the struct to (void *) *data and &data 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. Quote Link to post Share on other sites
spirilis 1,265 Posted December 8, 2013 Author Share Posted December 8, 2013 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 Quote Link to post Share on other sites
maxik 1 Posted December 8, 2013 Share Posted December 8, 2013 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. Quote Link to post Share on other sites
spirilis 1,265 Posted December 8, 2013 Author Share Posted December 8, 2013 Ah ok yep, because color_t is a typedef'd struct. Now the problem is, 'data' refers to an actual allocated unit of memory rather than a modifiable pointer. So maybe radio.write((void *)&data, sizeof(color_t)); would work? Sent from my Galaxy Note II with Tapatalk 4 Quote Link to post Share on other sites
maxik 1 Posted December 8, 2013 Share Posted December 8, 2013 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] Quote Link to post Share on other sites
spirilis 1,265 Posted December 8, 2013 Author Share Posted December 8, 2013 Oh well if that's what it's expecting, try casting to uint8_t * instead. Sent from my Galaxy Note II with Tapatalk 4 maxik 1 Quote Link to post Share on other sites
maxik 1 Posted December 8, 2013 Share Posted December 8, 2013 It works! Hangs after few minutes, but I doubt it's caused by the library. Thank you, spirilis! Quote Link to post Share on other sites
rad3d 1 Posted January 15, 2014 Share Posted January 15, 2014 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! 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... Quote Link to post Share on other sites
spirilis 1,265 Posted January 15, 2014 Author Share Posted January 15, 2014 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? Quote Link to post Share on other sites
rad3d 1 Posted January 15, 2014 Share Posted January 15, 2014 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: Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.