This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Wireless Hello World Code

Other Parts Discussed in Thread: MSP430F2274, SIMPLICITI

I'm trying what I consider the hello-world of wireless - push the button on the end-device target board, and get the access-point target board to toggle its LED. Has anyone tried anything like this already?

I'm having a hard time breaking down the Demo Sensor Monitor code that comes with the eZ430-RF2500 - the part relating to the message received from the end-device. Does anyone have tips on that? Is there a function dictionary online for the functions used in the demo?

Thanks

  • Is the sensor demo you mention part of SLAC139 from the eZ430-RF2500 Product Folder, or the Wireless Sensor Monitor using the eZ430-RF2500 (SLAA378)?

    Either way, I think the principle is the same.  In these examples, there is a project configuration for the End Device (ie. ED) and Access Point (ie. AP).

    Currently, the ED is setup to use a timer to wake the MSP430F2274 and perform a measurement of the termperature and voltage on ADC10 channel 11.  When it collects this information, it sends both of these values to the AP via message with the SMPL_Send().
    This message is received by the AP which in turns sends the message it received over the UART interface of the MSP430F2274.  This UART interface is connected to the eZ430 USB emulator pod which enables a Virtual COM port of the USB, allowing the message to be displayed via a terminal program such as HyperTerminal or TeraTerm.

    If you don't care for the timer event, this could be removed and you can add either a polling of a GPIO connected to a push button (P1.2) on the RF2500T target board, or make this an interrupt.  At this point, it probably doesn't matter what the actual message contents are, but send a message via SMPL_Send().
    The AP would need to be modified to not transmit this message over the UART interface, but perhaps toggle the GPIO connected to the LED (either P1.1 or P1.0) on the RF2500T target board.

    The AP side demo_AP.c has a registered callback function call sCB() which is passed to the SimpliciTI stack via the SMPL_Init() function.  This callback function is called in the frame-receive ISR thread so it runs in the interrupt context.  Information about this can be obtained by downloading the SimplicTI stack from its Product Folder.
    It is suggested the callback be very thin as it is run in the interrupt context.  The callback should set a flag or otherwise store the information about the waiting frame.  The user thread can then check this flag to call the SMPL_Receive() to retrieve the message in the frame.

  • Thanks Brandon,

                   I'm working off the SLAC139 files. The SLAA378 gives good information. How come there is no reference at all to it in the eZ430-RF2500 user guide SLAU227?

     I'm able to toggle the LED on the target board with an interrupt from the pushbutton. Doing SMPL_Send instead of an LED operation should be straightforward. However, on the A-P target board, I'd like to only toggle the LED with a request from an authorized E-D. So I do need to look at the message.

    When I get into an interrupt routine from the pushbutton, should I use SMPL_Link, or go directly into SMPL_Send to hit the AP?

    Thanks!

  • Here's the code I'm running on the End Device. So far, I'm not having success. When I push the button on the ED target board, the LEDs light up, stay lit about 3 seconds and then go off. If all goes correctly, the LED2 on the Access Point board should light up each time I use the pushbutton on the ED to send a packet.

    AP is running the Demo Sensor Monitor code unchanged, so LED1 keeps toggling at a 1 Hz rate.

    Any help I can get on what to change will be super.

  • Reviewing the code you sent, I guess I would not have implemented the SMPL_Init() in the Port 1 interrupt service routine.  I would suggest using a structure similar to the SLAC139 demo_ED.c file to Initialize the SimpliciTI stack in the main() loop.  Once this is established, you can tell the MSP430F2274 to go to LPM3.  Then a push button event would wake up the device and get the message ready for sending.  I would put a little inside the ISR as possible.

  • Thanks Brandon,

            I need more help though. If I take the timer out, then is it sufficient to do the init only once? Should I do Ioctl calls within my ISR like the demo app does?

    Thanks

  • I probably led you astray with removing the Timer interrupt as this is what wakes the MSP430F2274 up to run the SMPL_Init() calls until they succeed.  Therefore, you should probably keep the timer in there.

    However, you may want to potentially disable the timer, if you don't need it.  Or change the behavior in linkTo() to not process the ADC stuff based on a Timer interrupt, but rather due to a button press.  What this would entail is adding a flag in the Port ISR to set once the interrupt service routine is executed.  The linkTo() would condition execution of the ADC stuff based on the setting of this flag.  Once you are finished with the ADC conversions and sending the data via SMPL_Send(), the flag would be cleared.

    During this time, the timer may wake up the device, but since the Timer ISR would not set this flag, the ADC conversions would be skipped and the device would loop on the while(1) {} within linkTo().

  • Appreciate that Brandon. I'm still a novice at this. If possible, could you give me just some pseudocode detailing how you would do it? What would you put in the main() and what in the interrupt routine? Again, not detailed code, but just pseudocode so I can see easily what you're suggesting.

    Thanks!

  • I don't know if this helps but I tried to do a similar thing with the one you do: I got the old demo_ED app and modified so it uses a timer to try and join the network but then it uses the push button to send the message.Since I am really a beginner, I am not sure if all the new lines of code are needed but the code seems to work fine. If it helps, here is what I did was:

    a) after the while loop in which the end point tries to join the network   while (SMPL_NO_JOIN == SMPL_Init((uint8_t (*)(linkID_t))0)) {.....} I stopped the timer (btw, I am using TimerB instead of the original TimerA):

      TBCCR0 = 0;   // we used the timer to join the network, now stop it

    b) enable the button:
      P1DIR &= ~0x04;                           // P1.2 (button) = input
      P1OUT |= 0x04;                            // P1.2 pullup
      P1REN |= 0x04;                            // P1.2 pullup
      P1IE |= 0x04;                             // P1.2 interrupt enabled
      P1IES |= 0x04;                            // P1.2 Hi/lo edge
      P1IFG &= ~0x04;                           // P1.2 IFG cleared
    c) add the code for the button interrupt:
    #pragma vector=PORT1_VECTOR
    __interrupt void Port_1(void)
    {
      while(!P1IN&&0x04); // Wait for debounce
      P1IFG &= ~0x04;                           // P1.2 IFG cleared key interuped
      __bic_SR_register_on_exit(LPM3_bits);        // Clear LPM3 bit from 0(SR)
    }
    This will make the MCU wait in LPM3 and the radio in sleep mode because of these lines:
        SMPL_Ioctl( IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_SLEEP, "" );
        __bis_SR_register(LPM3_bits+GIE);       // LPM3 with interrupts enabled
        SMPL_Ioctl( IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_AWAKE, "" );
    When the button is pushed, the MCU wakes up and sends a message with the sampled temperature and voltage.
    I hope this helps and if you see problems, please let me know.

  • beginner said:

    a) after the while loop in which the end point tries to join the network   while (SMPL_NO_JOIN == SMPL_Init((uint8_t (*)(linkID_t))0)) {.....} I stopped the timer (btw, I am using TimerB instead of the original TimerA):

      TBCCR0 = 0;   // we used the timer to join the network, now stop it

    That certainly works.

     

    beginner said:

    b) enable the button:

      P1DIR &= ~0x04;                           // P1.2 (button) = input
      P1OUT |= 0x04;                            // P1.2 pullup
      P1REN |= 0x04;                            // P1.2 pullup
      P1IE |= 0x04;                             // P1.2 interrupt enabled
      P1IES |= 0x04;                            // P1.2 Hi/lo edge
      P1IFG &= ~0x04;                           // P1.2 IFG cleared

    I would suggest rearranging the steps above just slightly.  I would enable the P1.2 interrupt at the end of the sequence to make sure that no incidental transitions occur due to the changing of configuration registers in Port 1.  This can sometimes happen and one needs to be careful.  There are some footnotes in the datasheet regarding this.  I would recommend the following:
      P1DIR &= ~0x04;                           // P1.2 (button) = input
      P1OUT |= 0x04;                            // P1.2 pullup
      P1REN |= 0x04;                            // P1.2 pullup
      P1IES |= 0x04;                            // P1.2 Hi/lo edge
      P1IFG &= ~0x04;                           // P1.2 IFG cleared
      P1IE |= 0x04;                             // P1.2 interrupt enabled
    Everything else appears good.
  • Thanks a lot, Brandon.

  • Hi,

            Thanks for the details. Could you paste your complete code as an attachment? I think you need to use .txt instead of .c because of the forum's restrictions.

    I think my interrupt setup was wrong. Some general questions:

    Suppose I don't want to keep trying to join the network and only want to do it once, is that possible? Ideally, upon the push button press, I want to join the network if I haven't already, send a message and leave the network (or not). Is there a timeout involved in belonging to the network? Does "belonging" to the network expire after a certain time interval?

    Suppose the device has joined the network and tries to join again the next time the timer ticks, what happens?

    Why do we have the lines related to radio sleeping? Those tend to confuse things in a hello-world program. I agree they should be made available for optimization, but I'm really looking for a bare-bones widget at this point that I can build on.

    Thanks!

  • Perl Smith said:

    Thanks for the details. Could you paste your complete code as an attachment? I think you need to use .txt instead of .c because of the forum's restrictions.

    My code is not quite a "hello world", it is basically the code is the old demo_ED.c modified a little bit as I mentioned. Anyway, if it helps, I attached the file to my profile here

    Perl Smith said:

    Suppose I don't want to keep trying to join the network and only want to do it once, is that possible? Ideally, upon the push button press, I want to join the network if I haven't already, send a message and leave the network (or not).

    Actually, this is exactly what I did at first, I totally replaced the timer interrupt with the button one and I joined the network and sent the message in the same time. Abd it seemed to work fine. However, since I don't know much about the controller and the radio I was thinking that it may not work right so I went back to timer for join + button for message.
    Perl Smith said:
    Is there a timeout involved in belonging to the network? Does "belonging" to the network expire after a certain time interval?

    Suppose the device has joined the network and tries to join again the next time the timer ticks, what happens?

    I don't know the SimpliciTi code, it could be. Brandon will be able to help you with this

    Perl Smith said:

    Why do we have the lines related to radio sleeping? Those tend to confuse things in a hello-world program. I agree they should be made available for optimization, but I'm really looking for a bare-bones widget at this point that I can build on.

    Again, I'm sorry but I don't know for sure, but I assume they may very well be removed as it is not necessary to put the MCU in low power. I think you can do without them, worth trying.

     

  • Thanks, I found this works. Though it isn't predictable when a SEND on the ED is successful, I've seen that, with the AP code unchanged from SLAC139, a successful SEND on the ED does toggle the LED2 on the AP. I've attached my code. I removed the temperature measurement stuff.

    Certainly, in terms of deviation from the demo, your code is a hello-world example.

    But, there is a mystery. I find this only works with the ED plugged into the USB interface and the AP board connected to the battery board. The other way round, the LED1 of the ED keeps toggling - signalling no successful Link JOIN. Any thoughts?

  • Hello

     

    I using the code www.ti.com/lit/zip/slaa378 for the Wireless Sensor Monitor. I coudl download the code to both boards (AP, and ED) but the ED is not sending data to the AP. Both leds are blinking all the time. I can I do?

    Thanks,

     

    David.

     

  • **Attention** This is a public forum