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.

P2 LED CC2530DK Minikit Target Board

Other Parts Discussed in Thread: CC2530, Z-STACK

Hello,

How can I use my five pins of port 2 (P2 on target board), for example, to turn on a simple led ?

I have tried the follow code:

P2SEL = 0x01;

P2DIR = 0x01;

P2OUT |= 0x01;

but... don't works, unfortunately.

-------

- IAR

- CC2530 Minikit

- LED 3vdc

thanks

  • If you mean to output high on P2.0 pin, you should use the following code.
    P2SEL &= (~BV(0)); // select P2.0 to GPIO
    P2DIR |= BV(0); // set P2.0 as GPO
    P2_0=1; // output P2.0 as high

    You can refer to CC253x user guide at www.ti.com/.../swru191f.pdf for details.
  • Don't works for me...

    Errors:

    - Function external BV is undefined (declared implicity)

    - P2_0 is undefined...

    question still open..

  • Try the following code:
    P2SEL &= (~0x01); // select P2.0 to GPIO
    P2DIR |= 0x01; // set P2.0 as GPO
    P2OUT|=0x01; // output P2.0 as high
  • Thanks for response Yikai,

    But if I want turn on and turn off in 2 lines (without unique command toggle) ?


    while(1){

    P2OUT|=0x01; // output P2.0 as high

    delayMs(1000);

    P2OUT|=0x00; // output P2.0 as low <- dont works

    }
  • To output P2.0 as low, you should use
    P2OUT &= (~0x01);
  • leds for ever turn on...

    The follow code works for me:

    P2SEL = 0x00;
    P2DIR = 0xFF;

    while(1){
    P2OUT ^= BIT1 | BIT2;
    delayMs(1000);

    /*
    or
    P2OUT ^= BIT1;
    delayMs(1000);
    P2OUT ^= BIT2;
    */
    }


    I just want understand the logic behind. For instance, how can I output as high 1 and 2 pins and as low the 3 pin.
  • You can refer to CC2530 user guide at www.ti.com/.../swru191f.pdf.
  • If was so easy I would not come here ;)

    I tried understand these doc, but just showing questions.. To aids Go to forum

    Your code dont works, so dont suggest me to read the doc..

    I just wanna turn on and turn off a simple led, and till now nothing guy..
  • Please don't be rude here. I just try to help you here. If you don't mind, can you let me know which Z-Stack you use ? By the way, are you sure P2 LED is connected to P2.1 on CC2530DK mini kit?
  • I'm so sorry by this..

    Thus, my task is so easy and ends annoying me...



    Lets go!


    My code is CC2530ZNP MIni kit /.../ Communication_example.eww, on iar

    using eZ430-2530, rev 1.0, FF2274,

    In target board having 5 pins on left side, type as P2, so, I connect one LED on seconds hole (P2.1) and another on gnd.


    With the last code type me works, but if I want turn on turn off more than 1 led, how can I do it?..


    Do you need pictures of something?..
  • Hi Leonardo,
    the code snippet YK sent out shows the right way and approach to control external devices through GPIO
    In general, you can do the following

    #define BIT0 0x01
    #define BIT1 0x02
    #define BIT2 0x04
    #define BIT3 0x08
    #define BIT4 0x10
    #define BIT5 0x20
    #define BIT6 0x40
    #define BIT7 0x40

    /* For instance, let's configure P2.0 and P2.3 as LED*/
    /* Fir select the desired pins as GPIO*/
    P2SEL &= ~(BIT0 | BIT3);
    /* Then select the pins as output*/
    P2DIR |= (BIT0 | BIT3);
    /* Set the desired pins as high to turn LED on*/
    P2OUT|= (BIT0 | BIT3);

    /* Set the desired pins as low to turn LED off*/
    P2OUT&= ~(BIT0 | BIT3);

    Please also note that in P2 port P2.1 and P2.2 provide the debug interface to the debugger, and you should avoid modifying settings for those pins.
    Please also understand we point people to documents as we want to provide tangible artifacts and through collateral resources to our statements. For the specific thing you would like to achieve, which is basically controlling an external LED through a GPIO, I would recommend you use as a reference the following:
    www.ti.com/.../swru191f.pdf, chapter 7
    Also, please note Z-Stack SDK contains LED driver for CC2530/SRF05 platform with example code you can look at: \Components\hal\target\CC2530EB\hal_board_cfg.h (for macros and definition
    Components\hal\target\CC2530EB\hal_led.c for high level LED driver

    This is a community forum and people are trying to help each other out by providing code examples, recommendations, suggestions, help with debugging and we are inspired by this sense of community, at the basis of which there is a sense of collaboration and respect for all members.
    Though I can understand sometimes there can be things which don't go right from the first line of code dropped, the best way to continue to get help and making this forum useful is to keep a respectful and positive attitude that foster collaboration.

    Thanks,
    TheDarkSide
  • Hi, thanks for your complete answear, but dont still works...


    Our conditions maybe is different... I dont know..


    I'm trying your example code so much times.. but the external LEDs staying ever turn on!!

    I put 5 LEDS on 5 holes.. when I run your code, nothing different happens... the 1st LED is ever high, the 5th ever low.. none changes..




    Talk me about right hardware components that I need to run correctly your code.

    I'm use CC2530ZNP Minikit (Dongle + target board)
  • After much times... My problem is sorved.

    on my file: msp430x22x4.h, in the standard bits have so much defines incluing BIT0, BIT1 ... BITF, ok.

    On my example_basic_comms_router_application_afzdo.c in the main function I wrote the follows line codes:

    P2SEL = 0x00;
    P2DIR = 0xFF;
    P2OUT = 0x00; // Start turn all off

    delayMs(3000); //wait 3 seconds off

    while(1){

    // HIGH
    P2OUT |= (BIT2 | BIT3 | BIT4);//if want put only BIT2 or (BIT2 | BIT4)

    delayMs(1000);

    // LOW
    P2OUT &= ~(BIT2 | BIT3 | BIT4);
    //P2OUT &= ~(BIT3 | BIT4);// 2nd pin ever high

    delayMs(1000);

    }

    Thanks for all
  • It's not working only because of reason of not having delay after turning off the LED.

    Try this it will work.

    while(1){

    P2OUT|=0x01; // output P2.0 as high

    delayMs(1000);

    P2OUT|=0x00; // output P2.0 as low <- dont works

    delayMs(1000);
    }

    Regards,

    Varun