Jump to content
43oh

hawwwran

Members
  • Content Count

    29
  • Joined

  • Last visited

Reputation Activity

  1. Like
    hawwwran got a reaction from gssmahadevan in [Energia Library] Nordic nRF24L01+ library   
    If someone else is interested in scanning for active devices on known array of addresses, here is my working solution:
     
    Device finder code:
    #include "Enrf24.h" #include "nRF24L01.h" #include <string.h> #include <SPI.h> Enrf24 radio(P2_0, P2_1, P2_2);  // P2.0=CE, P2.1=CSN, P2.2=IRQ const char IDENTIFY=1; char rxaddr[] = {'d','e','v','-','0'}; // address of commander (note that it's out of sequence of device addresses) char txaddr[] = {'d','e','v','-','a'}; // address of the first device unsigned long mil; unsigned long prev_time; char ch='a'; // set first "address" int verbosity=2; //0 - none, 1 - only responsive devices, 2 - only found devices, 3 - all tries char packet[]={0,0,0}; // set empty packet. First byte is command ID, the rest is DATA void setup() {   Serial.begin(9600);   // error led   pinMode(P1_0,OUTPUT);   digitalWrite(P1_0,LOW);   // success led   pinMode(P2_3,OUTPUT);   digitalWrite(P2_3,LOW);   SPI.begin();   SPI.setDataMode(SPI_MODE0);   SPI.setBitOrder(1); // MSB-first   radio.begin();  // Defaults 1Mbps, channel 0, max TX power     radio.setTXaddress((void*)txaddr);   radio.setRXaddress((void*)rxaddr);   radio.enableRX(); } void identifyDevices(int slow=0) // slow var is because of the serial output. If you need high verbosity, the serial could be overloaded {   char inbuf[33];     if(ch>'z'){ch='a';}   txaddr[4]=ch;   ch++;   radio.setTXaddress((void*)txaddr);     digitalWrite(P1_0,LOW);   digitalWrite(P2_3,LOW);     packet[0]=IDENTIFY;     radio.lastTXfailed=false;   radio.print(packet);   radio.flush();   if(radio.lastTXfailed)   { // blink error led (data was not received)     digitalWrite(P1_0,HIGH);     delay(1);     digitalWrite(P1_0,LOW);          if(verbosity>2)     { // No device detected on tested address       Serial.print("NONE [");       Serial.print(txaddr[0]);       Serial.print(txaddr[1]);       Serial.print(txaddr[2]);       Serial.print(txaddr[3]);       Serial.print(txaddr[4]);       Serial.println("]");     }   }   else   { // blink success led (data was received)     digitalWrite(P2_3,HIGH);     delay(5);     digitalWrite(P2_3,LOW);     //     delta_set(); // set delta (start timer)     while (!radio.available(true) && delta_get()<10) // wait 10ms for data to receive     {            }     if (radio.read(inbuf))     {       if(verbosity>0)       { // device found and respond received         Serial.print("OK [");         Serial.print(txaddr[0]);         Serial.print(txaddr[1]);         Serial.print(txaddr[2]);         Serial.print(txaddr[3]);         Serial.print(txaddr[4]);         Serial.print("] - ");         Serial.println(inbuf);       }     }     else     {       if(verbosity>1)       { // device found, but no response         Serial.print("NO RESPONSE [");         Serial.print(txaddr[0]);         Serial.print(txaddr[1]);         Serial.print(txaddr[2]);         Serial.print(txaddr[3]);         Serial.print(txaddr[4]);         Serial.println("]");       }     }     //   }   delay(slow); } void loop() {     identifyDevices(1000); } unsigned long delta_set() {       prev_time = millis();       return prev_time; } unsigned long delta_get() {       unsigned long time;       unsigned long delta;              time = millis();       if (time < prev_time) { // Timer overflow             delta = 0xffffffff - prev_time + time + 1;       } else {             delta = time - prev_time;       }       return delta; } Demo device code:
    #include "Enrf24.h" #include "nRF24L01.h" #include <string.h> #include <SPI.h> Enrf24 radio(P2_0, P2_1, P2_2); // P2.0=CE, P2.1=CSN, P2.2=IRQ const char IDENTIFY=1; char rxaddr[] = {'d','e','v','-','g'}; // address of the device char txaddr[] = {'d','e','v','-','0'}; // address of the commander void setup() {   Serial.begin(9600);   SPI.begin();   SPI.setDataMode(SPI_MODE0);   SPI.setBitOrder(1); // MSB-first     radio.begin();  // Defaults 1Mbps, channel 0, max TX power   radio.setRXaddress((void*)rxaddr);   radio.setTXaddress((void*)txaddr);     pinMode(P1_0, OUTPUT);   digitalWrite(P1_0, LOW);   pinMode(P1_3, OUTPUT);   digitalWrite(P1_3, LOW);   pinMode(P1_4, OUTPUT);   digitalWrite(P1_4, LOW);     radio.enableRX();  // Start listening } void loop() {   char inbuf[33];     while (!radio.available(true))   {     }   if (radio.read(inbuf))   {     Serial.println(inbuf);     if (inbuf[0]==IDENTIFY)     { // if IDENTIFIcation is required, respond      radio.print("Demo device #1");      radio.flush();     }   }   } It goes through all addresses (dev-a to dev-z) in about half a second (without the slow variable, with serial output verbosity 2 and with delays for led blink).
     
  2. Like
    hawwwran reacted to spirilis in TTL UART and FTDI - what is what and for what?   
    So this is where the rabbit hole gets deeper.....
     
    Some MCUs can be programmed over a asynchronous UART using what's called a "Serial Bootloader", or "Bootstrap Loader" (BSL) as TI likes to call it.  On Atmel AVR microcontrollers like those used with the Arduino, if there is a bootloader present (and the "fuse bits" on the AVR is configured to use it) then it runs first thing upon RESET.  An FTDI or CP2102 can use its DTR or CTS line to "pulse" the RESET line on the microcontroller and then immediately perform UART communication with the bootloader stub executing on the microcontroller, thus allowing you to reprogram it (it's physically the bootloader code doing the rewriting of the flash upon receipt of the new code coming over the UART).
     
    The TI MSP430 can do this, but typically you don't see it in the lower-end chips like the Value Line.  I think the G2553 might technically be capable of using a BSL but I've not seen anyone do it.  It's more common in chips with more flash, such as the MSP430F5xxx series chips.  On these, I believe the RESET and/or TEST line has to be driven in some custom sequence to activate the BSL (otherwise the MCU just resets normally without executing the BSL code), then an FTDI or CP2102 can reprogram it over the UART pins.  The DTR/CTS pins can be used to drive that custom sequence.  Also in many cases the UART pins used for BSL are not the same as the general application UART pins too.  The BSL will have custom code to run a special timer-based software UART on different pins.  Because of the special "sequence" needed (and sometimes totally separate pins from the hardware UART your application will use) you don't see too many folks bothering with this.  But it's common to see the BSL implemented in a wide variety of chips because it's the most economical way for engineers to reprogram firmware "in the field" or for providing an application that the end-user can use to reprogram their chips.
  3. Like
    hawwwran reacted to mbeals in TTL UART and FTDI - what is what and for what?   
    If the RST line is just attached the RST line of the CP2102, then that's exactly what it is.  If you pull that pin low, the chip powers down.  So you can use it to allow the MCU to disable or reset the chip.  Attaching it to the RST pin on the launchpad means that when you pull the RST line down to reset the MCU on the launchpad, the adaptor is reset as well.
     
    DTR is 'Data Terminal Ready'.  It's a control signal used by RS232 when you are using hardware flow control.  An Arduino is just an AVR MCU with a special serial based bootloader, which is a layer of software that lets you flash a new program over a serial line instead of using a programmer.  They sort of pirate the DTR line to reset the chip and signal when to enter the bootloader and start accepting new code over the serial interface.  To program a MSP430 like this, you would need to first flash bootloader code in the 'usual' way.  However, since the launchpad has a full programmer/debugger built in, there really is no need.
  4. Like
    hawwwran reacted to jazz in TTL UART and FTDI - what is what and for what?   
    TXD/RXD jumper orientation on Launchpad is used for software/hardware UART selection (on target device, chip in socket). TEST/RESET pins are not related to UART.
     
    http://www.ti.com/lit/ug/slau318d/slau318d.pdf

    Jumpers 4 and 5 connect the UART interface of the emulator to the target device pins P1.1 and P1.2. The
    direction of the UART signal lines can be selected by the orientation of the attached jumpers. In horizontal
    orientation, the jumpers connect TXD to P1.1 and RXD to P1.2, as they are used for the software UART
    communication on the demo application (see Section 3.2). In vertical orientation, the jumpers connect the
    TXD signal to P1.2 and the RXD signal to P1.1, as required for the MSP430G2553 USCI.
  5. Like
    hawwwran reacted to spirilis in [Energia Library] Nordic nRF24L01+ library   
    Working handler:
    #include "Energia.h" #if defined(__MSP430_HAS_USCI__) || defined(__MSP430_HAS_EUSCI_A0__) #include "usci_isr_handler.h" /* This dummy function ensures that, when called from any module that * is interested in having the USCIAB0TX_VECTOR and USCIAB0TX_VECTOR * installed, the linker won't strip the vectors.*/ void usci_isr_install(){} #if defined(__MSP430_HAS_EUSCI_A0__) __attribute__((interrupt(USCI_A0_VECTOR))) void USCIA0_ISR(void) { switch ( UCA0IV ) { case USCI_UART_UCRXIFG: uart_rx_isr(); break; case USCI_UART_UCTXIFG: uart_tx_isr(); break; } } #else // #if defined(__MSP430_HAS_EUSCI_A0__) /* USCI_Ax and USCI_Bx share the same TX interrupt vector. * UART: * USCIAB0TX_VECTOR services the UCA0TXIFG set in UC0IFG. * USCIAB0RX_VECTOR services the UCA0RXIFG set in UC0IFG. * I2C: * USCIAB0TX_VECTOR services both UCB0TXIFG and UCB0RXIFG * set in UC0IFG. * USCIAB0RX_VECTOR services the state change interrupts * UCSTTIFG, UCSTPIFG, UCIFG, UCALIFG set in UCB0STAT.*/ __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(); } __attribute__((interrupt(USCIAB0RX_VECTOR))) void USCIAB0RX_ISR(void) { /* USCI_A0 UART interrupt? */ if (UC0IFG & UCA0RXIFG) uart_rx_isr(); /* USCI_B0 I2C state change interrupt. */ if ((UCB0STAT & (UCALIFG | UCNACKIFG | UCSTTIFG | UCSTPIFG)) != 0) i2c_state_isr(); } #endif // #if defined(__MSP430_HAS_EUSCI_A0__) #endif // if defined(__MSP430_HAS_USCI__) || defined(__MSP430_HAS_EUSCI_A0__) Note there is a USCIAB0TX_ISR and a USCIAB0RX_ISR.  In your examples, the broken example was missing USCIAB0RX_ISR entirely while the working version had USCIAB0RX_ISR (but did not incorporate my changes to the USCIAB0TX_ISR to fix the SPI / Serial conflict)
  6. Like
    hawwwran got a reaction from bluehash in [Energia Library] Nordic nRF24L01+ library   
    If someone else is interested in scanning for active devices on known array of addresses, here is my working solution:
     
    Device finder code:
    #include "Enrf24.h" #include "nRF24L01.h" #include <string.h> #include <SPI.h> Enrf24 radio(P2_0, P2_1, P2_2);  // P2.0=CE, P2.1=CSN, P2.2=IRQ const char IDENTIFY=1; char rxaddr[] = {'d','e','v','-','0'}; // address of commander (note that it's out of sequence of device addresses) char txaddr[] = {'d','e','v','-','a'}; // address of the first device unsigned long mil; unsigned long prev_time; char ch='a'; // set first "address" int verbosity=2; //0 - none, 1 - only responsive devices, 2 - only found devices, 3 - all tries char packet[]={0,0,0}; // set empty packet. First byte is command ID, the rest is DATA void setup() {   Serial.begin(9600);   // error led   pinMode(P1_0,OUTPUT);   digitalWrite(P1_0,LOW);   // success led   pinMode(P2_3,OUTPUT);   digitalWrite(P2_3,LOW);   SPI.begin();   SPI.setDataMode(SPI_MODE0);   SPI.setBitOrder(1); // MSB-first   radio.begin();  // Defaults 1Mbps, channel 0, max TX power     radio.setTXaddress((void*)txaddr);   radio.setRXaddress((void*)rxaddr);   radio.enableRX(); } void identifyDevices(int slow=0) // slow var is because of the serial output. If you need high verbosity, the serial could be overloaded {   char inbuf[33];     if(ch>'z'){ch='a';}   txaddr[4]=ch;   ch++;   radio.setTXaddress((void*)txaddr);     digitalWrite(P1_0,LOW);   digitalWrite(P2_3,LOW);     packet[0]=IDENTIFY;     radio.lastTXfailed=false;   radio.print(packet);   radio.flush();   if(radio.lastTXfailed)   { // blink error led (data was not received)     digitalWrite(P1_0,HIGH);     delay(1);     digitalWrite(P1_0,LOW);          if(verbosity>2)     { // No device detected on tested address       Serial.print("NONE [");       Serial.print(txaddr[0]);       Serial.print(txaddr[1]);       Serial.print(txaddr[2]);       Serial.print(txaddr[3]);       Serial.print(txaddr[4]);       Serial.println("]");     }   }   else   { // blink success led (data was received)     digitalWrite(P2_3,HIGH);     delay(5);     digitalWrite(P2_3,LOW);     //     delta_set(); // set delta (start timer)     while (!radio.available(true) && delta_get()<10) // wait 10ms for data to receive     {            }     if (radio.read(inbuf))     {       if(verbosity>0)       { // device found and respond received         Serial.print("OK [");         Serial.print(txaddr[0]);         Serial.print(txaddr[1]);         Serial.print(txaddr[2]);         Serial.print(txaddr[3]);         Serial.print(txaddr[4]);         Serial.print("] - ");         Serial.println(inbuf);       }     }     else     {       if(verbosity>1)       { // device found, but no response         Serial.print("NO RESPONSE [");         Serial.print(txaddr[0]);         Serial.print(txaddr[1]);         Serial.print(txaddr[2]);         Serial.print(txaddr[3]);         Serial.print(txaddr[4]);         Serial.println("]");       }     }     //   }   delay(slow); } void loop() {     identifyDevices(1000); } unsigned long delta_set() {       prev_time = millis();       return prev_time; } unsigned long delta_get() {       unsigned long time;       unsigned long delta;              time = millis();       if (time < prev_time) { // Timer overflow             delta = 0xffffffff - prev_time + time + 1;       } else {             delta = time - prev_time;       }       return delta; } Demo device code:
    #include "Enrf24.h" #include "nRF24L01.h" #include <string.h> #include <SPI.h> Enrf24 radio(P2_0, P2_1, P2_2); // P2.0=CE, P2.1=CSN, P2.2=IRQ const char IDENTIFY=1; char rxaddr[] = {'d','e','v','-','g'}; // address of the device char txaddr[] = {'d','e','v','-','0'}; // address of the commander void setup() {   Serial.begin(9600);   SPI.begin();   SPI.setDataMode(SPI_MODE0);   SPI.setBitOrder(1); // MSB-first     radio.begin();  // Defaults 1Mbps, channel 0, max TX power   radio.setRXaddress((void*)rxaddr);   radio.setTXaddress((void*)txaddr);     pinMode(P1_0, OUTPUT);   digitalWrite(P1_0, LOW);   pinMode(P1_3, OUTPUT);   digitalWrite(P1_3, LOW);   pinMode(P1_4, OUTPUT);   digitalWrite(P1_4, LOW);     radio.enableRX();  // Start listening } void loop() {   char inbuf[33];     while (!radio.available(true))   {     }   if (radio.read(inbuf))   {     Serial.println(inbuf);     if (inbuf[0]==IDENTIFY)     { // if IDENTIFIcation is required, respond      radio.print("Demo device #1");      radio.flush();     }   }   } It goes through all addresses (dev-a to dev-z) in about half a second (without the slow variable, with serial output verbosity 2 and with delays for led blink).
     
  7. Like
    hawwwran reacted to OzGrant in [Energia Library] Nordic nRF24L01+ library   
    G'day
    Am sure there are smarter guys than me (heck there always is) but do have a few  RF remotes talking to me.  I put a hex switch in each slave that sets the last byte in the address array..
    The other address bytes  don't matter, as long as radio.setTxaddress in master (in my case have a stellaris polling the slaves) is the same as radio.setRXaddress in the 430.
     
    A simple for loop incrementing the LSB address then polls each slave.
     
    There is also an option to reduce the total number of byte in the address, but have not bothered with that at this stage.
    Grant
  8. Like
    hawwwran reacted to spirilis in [Energia Library] Nordic nRF24L01+ library   
    Addressing is quite simple, it's 5 bytes. Incoming packets are continually filtered to find packets whose address matches the 5 byte RX address configured on the transceiver.
     
    There is more to it under the hood but this library is intentionally designed for you to ignore them.
     
    Btw since the .setRXaddress() and .setTXaddress() methods just take a pointer, you could pass a string to it and that would work. Just be sure it is 5-chars long.
     
    Sent from my Galaxy Note II with Tapatalk
     
     
  9. Like
    hawwwran reacted to spirilis in [Energia Library] Nordic nRF24L01+ library   
    Yep that should work. If there are any compilation errors or warnings it's probably a type cast required or something, but I don't think it should error. 
    Sent from my Galaxy Note II with Tapatalk
     
     
×
×
  • Create New...