Jump to content
43oh

hawwwran

Members
  • Content Count

    29
  • Joined

  • Last visited

Posts posted by hawwwran

  1. Hello. I have a problem with timers. I would like to use the longdelay function above, but I use 2452 chip, not the 2553 and if I try to compile it, energia says "TIMER1_A0_VECTOR was not declared in ths scope"... Could someone rewrite the code to work with MSP430G2452? Thank you

  2. Now it makes complete sense. Which means that for me (with MSP430G2553) both devices we are talking about are the same for me, only pins TXD and RXD are useful for me for serial communication, but for the programming stuff I have to use the Launchpad's top part as I use it now. OK, that's not problem. I just like to know stuff. Thank you

  3. I know that, I use it that way, I even splitted the board for that purpose, but it's not effective. I can buy those devices above for about $2 each, that would be much better solution. And as a note, you don't actually need to connect the TXD and RXD to programm it.

     

    - Ok, so I cannot use those devices above, because they are not programmers with JTAG/SBW capability. I can use them for fine PC to MSP serial communication.

    - Now question about the first red one from sparkfun... What are those CTS and DTR pins good for when they do not provide JTAG?

  4. I'm  noob in this area so forgive me my silly and repetitive questions.

     

    - I get now the difference between the devices RST and DTR, thank you mbeals

    - I still don't really understand how the programming works. I know that launchpad (the top part) is using RST and TEST pins to programm the MSP. Is the launchpad's programmer somehow transforming the TXD RXD communication to those TEST and RST pins to programm the MSP or is it possible to find those pins (TEST RST) as output on the CP2102 to point them to TEST and RST on MSP to programm it? My point is, that I want to free myself from having to use launchpad for programming my devices which uses standalone MSP430G2553 chip. I would like to embedd the small device above into my devices or make programming cable for that purpose.

  5. Hello again. Now I have this question:

     

    I'm awaiting this device to come soon and I don't get one thing... the RST line. What is it for?

    But my question is little bit more complicated. This device uses chip CP2102 so I searched little bit and found few articles how to take out DTR instead of the RST. But, as I found out.. for MSP430 it seems the DTR is usualy connected to RST pin, so what the RST on the device stands for? Here is the article how to bring the DTR out instead of the RST: http://jimlaurwilliams.org/wordpress/?p=999

     

    And what I would be glad to do: to programm the MSP430 using this device. Is it possible? Apparantely not without some HW hack, but it looks arduino guys are able to programm arduino. I know I need the RST and TEST pins from launchpad to programm the chip... so after I figure out the mess with the DTR and RST, only TEST would remain to find and it could work... Have some of you guys any experience with this?

     

     

    cp2102.jpg

  6. So you say, that connecting TXD and RXD pins from MSP to the device will allow me to communicate propperly the same as launchpad do?

     

    So my question is, why do I use launchpad with disabled TXD and RXD pins on top? I mean I have the jumpers horizontaly for SW UART, but I don't know what the SW UART actualy means... if I connect MSP's TXD and RXD pins, then it uses RST and TEST to communicate? I don't understand the mechanism how it works.

  7. Another question about those devices.

     

    If I'm right, connecting the first (FTDI, red, sparkfun) one means connect it like this:

    device     msp

    ------------------

    dtr       -> rst (reset)

    rxi        -> rxd

    txo       -> txd

    cts       -> tst (test)

     

    The second one (TTL, blue)

    ------------------------------------

    device     msp

    ------------------

    r       -> rxd

    t       -> txd

     

     

    Now my questions are:

    - am I right about the connection?

    - Will the first one work just like the launchpad's serial communication using "Serial.print();" in Energia?

    - Will the second one work just like the launchpad's serial communication using "Serial.print();" in Energia? I guess not (there are not the test and reset pins) so how to use it? How to simple communicate using the second one? Hello world example appreciated.

     

    Hawwwran

  8. Hello,

    I found some devices which should allow me to connect naked MSP430G2553 chip to PC over USB. But here is one problem I don't really understand. I found devices with FTDI chip (I know it's a brand name) and devices which I found under "TTL UART" or "USB to TTL".

     

    Here is link to the FTDI one: https://www.sparkfun.com/products/9873

    09873-01.jpg

     

    Here is link to the TTL one: http://dx.com/p/usb-2-0-to-ttl-uart-5-pin-cp2102-module-serial-converter-blue-152317

     

    So, my question is: is there any difference between those two? Because there is huge difference in price.

     

    Thanks for replies

     

     

     

     

     

     

  9. With this one it does not work (restart of energia needed):

    #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();
    
    }
    #endif // #if defined(__MSP430_HAS_EUSCI_A0__)
    #endif // if defined(__MSP430_HAS_USCI__) || defined(__MSP430_HAS_EUSCI_A0__)
    

    This one works (fot the serial read):

    #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__)
    
    
  10. here is the code. With the usci_isr_handler fix it prints nothing, without it it prints everithing sent to the Serial from PC ending with "."

    int incomingByte = 0;     // for incoming serial data
    char chr='.';             // var to store char from serial port
    char string2[16];         // command string (maximum length of the command is set to 16 bytes)
    int string2idx = 0;
    char commandDivider='.';  // char which devides commands
    int moveDelay = 30;       // delay between moves. Usable for slowing down the motor movements
    int command_int=0;
    
    void setup()                    // run once, when the sketch starts
    {
      Serial.begin(9600);           // set up Serial library at 9600 bps
    }
    
    void loop() // run over and over again
    {
      while (Serial.available() > 0) {  // while there are data on serial input
        int inChar = Serial.read(); // fill the byte on input into char variable
        chr=(char)inChar;
        if (chr!=commandDivider) { // if input is not command divider
          string2[string2idx++] = inChar;  // add the char in the string array
          string2[string2idx] = 0;         // add 0 byte on the end of the array
        }
        if (chr == commandDivider) {   // if it's the same char as the divider of commands
          command_int=atoi(string2);       // if you want to transform the input string into an integer, use this function
          
          Serial.print("Command: ");
          Serial.println(string2);
          
          if(strcmp(string2,"red")==0)
          {
            analogWrite(2,255); // turn the red LED on
            Serial.println("Red LED is on");
          }
          if(strcmp(string2,"green")==0)
          {
            analogWrite(14,255); // turn the green LED on
            Serial.println("Green LED is on");
          }
          if(strcmp(string2,"off")==0)
          {
            // turn the LEDs off
            analogWrite(14,0);
            analogWrite(2,0);
            Serial.println("LEDs are off");
          }
          
          string2[0] = 0;string2idx = 0; // empty the command
        }
      }
    }
    
    
  11. I have a question for you who know how to calculate it.

     

    I woud like to make small device which would periodically (every 10s) sent (let's say 5 bytes if it's important). I would use MCU MSP430G2553 (or better G2452?)

     

    My question is, how long will it work on battery CR2032 3V 220mAh?

     

    I'm planning to use deepsleep and such to maximize the time, but I have no idea what time it could be, I don't know the consumption of NRF24 and the G2553 (or G2452) and don't know how to calculate it.

     

    EDIT: Could someone show me an example how to sleep G2553 for 10s, blink LED and sleep again? Thank you

     

    Thank you

  12. Here's my code for everyone who would like test it:

     

    Sender device periodically checks all addresses from dev-a to dev-z and all found devices prints to serial

     

    Receiver device is listening on it's address and if receives the right command, it send's back identification string which should be printed to serial by sender device

     

    Sender 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','-','0'};
    char txaddr[] = {'d','e','v','-','a'};
    
    unsigned long mil;
    unsigned long prev_time;
    
    char ch='a';
    int verbosity=2; //0 - none, 1 - only responsive devices, 2 - only found devices, 3 - all tries
    char packet[]={0,0,0};
    
    void setup() {
      Serial.begin(9600);
    
      // error
      pinMode(P1_0,OUTPUT);
      digitalWrite(P1_0,LOW);
      // success
      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
    
      for(int i=0; i<10; i++)
      {
        digitalWrite(P1_0,HIGH);
        digitalWrite(P2_3,HIGH);
        delay(50);
        digitalWrite(P1_0,LOW);
        digitalWrite(P2_3,LOW);
        delay(50);
      }
      digitalWrite(P1_0,HIGH);
      digitalWrite(P2_3,HIGH);
      delay(1000);
      digitalWrite(P1_0,LOW);
      digitalWrite(P2_3,LOW);
     
      radio.setTXaddress((void*)txaddr);
      radio.setRXaddress((void*)rxaddr);
      radio.enableRX();
      //radio.autoAck(false);
    }
    
    void identifyDevices(int slow=0)
    {
      char inbuf[33];
     
      if(ch>'z'){ch='a';}
      txaddr[4]=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(ch!='a' && ch!='g'){radio.lastTXfailed=true;}
     
      //Serial.println(ch);
     
      //if(ch!='a' && ch!='g')
      if(radio.lastTXfailed)
      {
        digitalWrite(P1_0,HIGH);
        delay(1);
        digitalWrite(P1_0,LOW);
        
        if(verbosity>2)
        {
          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
      {
        digitalWrite(P2_3,HIGH);
        delay(5);
        digitalWrite(P2_3,LOW);
        //
        delta_set();
        while (!radio.available(true) && delta_get()<500)
        {
          
        }
        if (radio.read(inbuf))
        {
          if(verbosity>0)
          {
            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
        {
          radio.lastTXfailed=false;
          radio.print(packet);
          radio.flush();
          if(!radio.lastTXfailed)
          {
            delta_set();
            while (!radio.available(true) && delta_get()<500){}
            if (radio.read(inbuf))
            {
              if(verbosity>0)
              {
                Serial.print("OK #2[");
                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)
              {
                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("]");
              }
            }
          }
          else
          {
            if(verbosity>2)
            {
              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("]");
            }
          }
        }
        //
      }
      ch++;
      delay(slow);
    }
    
    void loop()
    {  
      identifyDevices(100);
    }
    
    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;
    }

    receiver 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'};
    char txaddr[] = {'d','e','v','-','0'};
    
    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);
     
      digitalWrite(P1_0, HIGH);
      delay(100);
      digitalWrite(P1_0, LOW);
      delay(100);
      digitalWrite(P1_0, HIGH);
      delay(100);
      digitalWrite(P1_0, LOW);
      delay(100);
     
      radio.enableRX();  // Start listening
    }
    
    void loop() {
     
      char inbuf[33];
     
      while (!radio.available(true))
      {
     
      }
      if (radio.read(inbuf))
      {
        Serial.println(inbuf);
        if (inbuf[0]==IDENTIFY)
        {
         radio.lastTXfailed=false;
         radio.print("Demo device #1");
         radio.flush();
         if(radio.lastTXfailed)
         {
           radio.print("Demo device2 #1");
           radio.flush();
         }
        }
      }
     
    }
  13. I tried put delays to different places with no result.

     

    On device - wait 100ms before sending reply

     

    on sender - wait 500ms in the wait() before giving it up

                     - wait 500ms before the wait()

                     - wait 500ms after the wait() before .read

     

    nothing helped, still the same problem

     

    OK [dev-a] - CameraMover
    OK #2[dev-g] - Demo device #1
    OK [dev-a] - CameraMover
    OK #2[dev-g] - Demo device #1
    OK [dev-a] - CameraMover
    OK #2[dev-g] - Demo device #1
    OK [dev-a] - CameraMover
    OK #2[dev-g] - Demo device #1
    OK [dev-a] - CameraMover
    OK #2[dev-g] - Demo device #1
    OK [dev-a] - CameraMover
    OK #2[dev-g] - Demo device #1
    OK [dev-a] - CameraMover

  14. So, I turned off the auto ACK and changed the check for lastTXfailed to check what address the message was sent to, because I know the two which exists. That means, that the program is doing the same... sending message to all addresses, but it's waiting for the response only for the two of them. And the result is, that it's working well

     

    OK [dev-a] - CameraMover
    OK [dev-g] - Demo device #1
    OK [dev-a] - CameraMover
    OK [dev-g] - Demo device #1
    OK [dev-a] - CameraMover
    OK [dev-g] - Demo device #1
    OK [dev-a] - CameraMover
    OK [dev-g] - Demo device #1

  15. Hi. The auto ACK is essential for me.

    I use MSP430G2553

     

    If you are talking about the 10ms in the wait() waiting for receiving message from device after confirmed package was sent, then I think it's not the problem. Don't know why or how, but even 1ms wait works the same and 1000ms as well. If the message is received, the delta_time is 0ms. If it does the "bug", it waits all 1000ms (or other time whatever I set) and still receive no data. So my Idea is... the problem has to be that the problem is on the side of the device (but auto ack says it's delivered) or on sender (discarded received message somehow, but even waiting on the side of the device 100ms before sending back message didn't work)

     

    I'll try again some ideas to confirm the behavior, the devices are one next to the other, no noise on the channel 0

     

    EDIT: And it's happening precisely regurarely. Here is small dump from my serial reader when I added second try send/read if first failed. You can see the "OK #2" which is second attempt success. And it's not just the dev-a device's problem. If I turn one off and on again, I can change the #2 to the dev-g device. and another thing to think, If there is only one device, it works everytime for the first attempt

     

    OK #2[dev-a] - CameraMover
    OK [dev-g] - Demo device #1
    OK #2[dev-a] - CameraMover
    OK [dev-g] - Demo device #1
    OK #2[dev-a] - CameraMover
    OK [dev-g] - Demo device #1

  16. But I found one problem I don't understand.

    If there are more devices (two), every second device is marked ad non responding. It does not seem to be problem of the device, but the finder. It simply looks, that sometimes, the message is not sent, but on the sender device it looks like it was, so it is waiting for the response, but the response does not happen. But next time it's ok and then it's not and so on.

     

    Any idea?

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

  18. Great!

    So, let's say I plan to have maximum 20 devices (in fact about five, but just to be sure). That makes an alphabet enough big to use it as ID's like this to go through ids from dev-a to dev-z to make the addresses easy to remember.

    const uint8_t txaddr[] = "dev-a";
    .
    .
    .
    for(uint8_t i='a'; i<='z'; i++)
    {
      txaddr[4]=i
      radio.setTXaddress(txaddr);
    }
    .
    .
    .
    

    and of course on the RX side (for example)

    const uint8_t rxaddr[] = "dev-a";

    So you say it's valid?

     

    Thank you

×
×
  • Create New...