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.

CC2530 working with ports in/out

Other Parts Discussed in Thread: CC2530, CC2531, Z-STACK, CC2591

Hello.

I'm working with a TI CC2530 ZDK.

More exactly with an CC2530ZDK_EM on an BB.

I'm using IAR and I'm trying to write some code in the SampleApp.

I want to know how ports are working, and I build a little code that when I put the 3Vcc on a pin to give (+) to another, and the same with GND.

------------
while (1)
{
if ( P1_2 & 1 )
  { //here we're testing
P0_0 = 1; // Testing pin 12 EM_1_11, pin 12 (I/0 B) - giving VCC
}
else
{
P0_0 = 0;
}
}
 ----------

I wrote it first in SampleApp.c in the SampleApp_HandleKeys function.

It works great, but it doesn't exit the loop.

I've tried it in ZMain.c, but there (tried in more places) the code didn't work and even made the EM non operational.

If someone please could help me, I want to go on with a project and I can't until I discover where should I put the code so that it works and also not stops the other functions (tranmitting, etc) from operating.

Thank you for your help.

 

  • hi,

    do anyone have solution for this?? i am also facing the same problem of port pins not functioning properly...

  • Hi Sri,

    Have you read through the IO chapter in the CC253x User Guide?

    What exactly is your problem?

    /Fredrik

  • Hi Sri,


    Try the following code.

    P1SEL &=(~(BV(2));
    P1DIR &=(~(BV(2));
    P0SEL &=(~(BV(0));
    P0DIR |= BV(0);
    while (1)
    {
    if ( P1_2 == 1 )
      { //here we're testing
    P0_0 = 1; // Testing pin 12 EM_1_11, pin 12 (I/0 B) - giving VCC
    }
    else
    {
    P0_0 = 0;
    }
    }

  • I can use my Push Button(P0_2) to control LED(P1_0) with this simple code. LED is default ON, when push button, LED OFF.

    How about if I want to toggle the LED using push button? Thanks.

  • Hi cyclonmaster,

    It should be very easy. If you have already detected toggle signal from P0_2, you can set a toggle flag and use it to turn on or off P1_0.

  • I want to implement this in samplelight and use it with TI Gateway Reference Design.

    This is what working in my current app:

    static void zclSampleLight_HandleKeys( byte shift, byte keys )
    {
    //using hardbutton
    P0SEL &=(~(BV(2))); //Push Button P0_2
    P0DIR &=(~(BV(2)));
    P1SEL &=(~(BV(0))); //LED1 P1_0
    P1DIR |= BV(0);

    int currentState = 0;//stroage for current button state
    int lastState = 0;//storage for last button state
    P1_0 = 1;//storage for the current state of the LED1 (off/on)

    while (1)
    {
    currentState = P0_2;
    if (currentState == 1 && lastState == 0)//if button has just been pressed
    {
    //toggle the state of the LED1
    if (P1_0 == 1)
    { P1_0 = 0; } else { P1_0 = 1; }
    }
    lastState = currentState;
    }

    //sw1 remove

    }

    PushButton now work as toggle button. But the problem is, after enable permit join from the gateway(which is running on CC2531+Beaglebon). No connection happen. I cannot control the light from the TI demo app. I monitor using Packet Sniffer. The CC2530(samplelight) did not trnasmit any signal. When I reset the power on the samplelight, "beacon request" appear once, then nothing.

    If I remove the code above and leave only:

    static void zclSampleLight_HandleKeys( byte shift, byte keys )

    {

    }

    The connection can happen. I can control the light from the TI demo app.

  • Since P1_0 is configured to GPO, you can't use if (P0_1==1). You should use a toggle flag to do it.

    uint8 LED_status=1;//storage for the current state of the LED1 (off/on)

    P1_0 = 1;

    while (1)
    {
    currentState = P0_2;
    if (currentState == 1 && lastState == 0)//if button has just been pressed
    {
    //toggle the state of the LED1
    if (LED_status == 1)
    { P1_0 = 0; LED_status=0;} else { P1_0 = 1; LED_status=1;}
    }
    lastState = currentState;
    }

  • Thanks Yikai, I did follow your suggestion. Unfortunately, still the same problem.

    Can control using push button. Cannot control the light(P1_0) from TI demo app. No network establish. The samplelight did not transmit anything when monitor from packet sniffer.

    This is the code changes:

    static void zclSampleLight_HandleKeys( byte shift, byte keys )
    {
    //using hardbutton
    P0SEL &=(~(BV(2))); //Push Button P0_2
    P0DIR &=(~(BV(2)));
    P1SEL &=(~(BV(0))); //LED P1_0
    P1DIR |= BV(0);

    int currentState = 0;//storage for current button state
    int lastState = 0;//storage for last button state
    uint8 LED_status=1;//storage for the current state of the LED1 (off/on)
    P1_0 = 1;

    while (1)
    {
    currentState = P0_2;
    if (currentState == 1 && lastState == 0)//if button has just been pressed
    {
    //toggle the state of the LED1
    if (LED_status == 1)
    { P1_0 = 0; LED_status=0;} else { P1_0 = 1; LED_status=1;}
    }
    lastState = currentState;
    }
    }

    Btw, I'm using CC2530+CC2591, Z-Stack Home 1.2.1. And this is my compile option:

    HAL_PA_LNA
    SECURE=1
    TC_LINKKEY_JOIN
    NV_INIT
    xNV_RESTORE
    xPOWER_SAVING
    NWK_AUTO_POLL
    xHOLD_AUTO_START
    ZTOOL_P1
    MT_TASK
    MT_APP_FUNC
    MT_SYS_FUNC
    MT_ZDO_FUNC
    LCD_SUPPORTED=DEBUG
    MULTICAST_ENABLED=FALSE
    ZCL_READ
    ZCL_WRITE
    ZCL_REPORT
    ZCL_EZMODE
    ZCL_BASIC
    ZCL_IDENTIFY
    ZCL_ON_OFF
    ZCL_SCENES
    ZCL_GROUPS
    xZCL_LEVEL_CTRL
    ZCL_DIAGNOSTIC
    FEATURE_SYSTEM_STATS
    ZIGBEE_COMMISSIONING
    MT_ZDO_MGMT
    MT_UTIL_FUNC

    Note:

    After further check, I believe the while loop is the cause of the problem.

    while (1){  }

    Any suggestion on how to fix this? Thanks.

  • If you use Z-Stack Home example, I suggest you to implement push button P0_2 in hal_key.c. Please refer to sw6 implementation in hal_key.c and revise accordingly.

  • Nevermind. I already solve the problem. Thanks for helping.

  • Good to hear you solved the issue. Would you share how you fix it to benefit others with similar problem?

  • Just swap sw1 and sw6.

  • Thanks for sharing.

  • hi,

    I am using cc2530ZDK for my project. in my project i need to log the data for all the day..but the kit stops responding after some time and the zsensor monitor software shows "sink no response". how to solve this problem and make the sink respond continuously..please help..

  • Hi sri,

    What SW stack and example do you test? Your description is too rough to answer your question.