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.

How to program CC2530 for transmitting a signal wireless?

Other Parts Discussed in Thread: CC2530

Hi folks,

I am Sagar, Grad student at Georgia Tech. I'm developing a wireless application. I got a CC2530 ZDK kit. My goal is to transmit a signal wireless by a cc2530module and recieve the same signal at the rx end and send it to the computer.

I went through the code ADC.c provided by TI's software examples. Here goes the code:

 

/******************************************************************************

* @fn  adcSampleSingle

*

* @brief

*      This function makes the adc sample the given channel at the given

*      resolution with the given reference.

*

* @param uint8 reference

*          The reference to compare the channel to be sampled.

*        uint8 resolution

*          The resolution to use during the sample (8, 10, 12 or 14 bit)

*        uint8 input

*          The channel to be sampled.

*

* @return int16

*          The conversion result

*

******************************************************************************/

int16 adcSampleSingle(uint8 reference, uint8 resolution, uint8 channel)

{

    int16 value;

 

    ADC_ENABLE_CHANNEL(channel);

 

    ADCIF = 0;

    ADC_SINGLE_CONVERSION(reference | resolution | channel);

    while(!ADCIF);

 

    value  = (ADCH << 8) & 0xff00;

    value |= ADCL;

 

    ADC_DISABLE_CHANNEL(channel);

 

    //  The variable 'value' contains 16 bits where

    //     bit 15 is a sign bit

    //     bit [14 .. 0] contain the absolute sample value

    //     Only the r upper bits are significant, where r is the resolution

    //     Resolution:

    //        12   -> [14 .. 3] (bitmask 0x7FF8)

    //        10   -> [14 .. 5] (bitmask 0x7FE0)

    //         9   -> [14 .. 6] (bitmask 0x7FC0)

    //         7   -> [14 .. 8] (bitmask 0x7F00)

 

    return value;

}

Port 0 of cc2530 is used to take the analog inputs which are to be converted to digital. AIN7 pin is the AVdd(Analog reverence voltage). I'm using single ended ADC(not differential).

My question is how do I select the channel of ADC, and resolution here.Which part of the code do I need to modify? I need 8 bit resolution. Giving a number to the channel in the code here will automatically reflect to that channel of Port0 on the cc2530 module? I also need transmit the value present in the ADCH and ADCL. So how do I program CC2530 to transmit the data wireless? Writing the ADCL,ADCH values to UxDBUF will solve the purpose of transmitting the data wireless? 

  • Hi Sagar, I am a student at Tech as well and I am trying to do something similar.  Are you going to communicate through ZigBee?  I am just now in the process of trying to find code.  Where are you looking for your code examples?

  • Hi danny,

    Give me a call on 713 410 7054. We shall discuss. We can work together. 

  • Hi,

    I tried compiling the ADC.c program which is in the software examples folder. I included all the required files in the workspace i.e hal_types.h, hal_defs.h etc

    But I keep getting an error

     Fatal Error[Pe005]: could not open source file "hal_types.h"                                                                           C:\Software Examples\source\components\radios\cc2530\adc.h 16 

    Anyone else faced this problem while programming in IAR systems for the ADC?

  • Hi Sagar,

    The error code Pe005 indicates that there is a file path problem somewhere, so the referenced file (hal_types.h) is not found. I will guess that adc.h tries to include this file, and the compiler is not able to find any such file.

    You should either change the include directive to use the correct path (e.g. change from "#include "hal_types.h" to "#include "../../relative/path/to/hal_types.h" to fix this), or the easiest method is to tell the C compiler that it should look in some additional folders for where to find include files: This is done in Project options -> C/C++ Compiler -> Preprocessor (tab) -> Additional include directories. You can probably look at the setup in the project for the ADC example.

  • Thanks esy,

    Can you send me the link where i can find setup of ADC example?

  • Hi,

    I compiled the following program and got these error messages. Can someone help me out in solving this?

     

    /******************************************************************************
        Filename: adc.c

        These functions/macros simplifies usage of the ADC.

    ******************************************************************************/

    #include "adc.h"


    /******************************************************************************
    * @fn  adcSampleSingle
    *
    * @brief
    *      This function makes the adc sample the given channel at the given
    *      resolution with the given reference.
    *
    * @param uint8 reference
    *          The reference to compare the channel to be sampled.
    *        uint8 resolution
    *          The resolution to use during the sample (8, 10, 12 or 14 bit)
    *        uint8 input
    *          The channel to be sampled.
    *
    * @return int16
    *          The conversion result
    *
    ******************************************************************************/
    uint8 channel = 1;
    uint8 resolution = 10;
    uint8 reference = 2;
    int16 adcSampleSingle(uint8 reference, uint8 resolution, uint8 channel)
    {
        int16 value;

        ADC_ENABLE_CHANNEL(channel);

        ADCIF = 0;
        ADC_SINGLE_CONVERSION(reference | resolution | channel);
        while(!ADCIF);

        value  = (ADCH << 8) & 0xff00;
        value |= ADCL;

        ADC_DISABLE_CHANNEL(channel);

        //  The variable 'value' contains 16 bits where
        //     bit 15 is a sign bit
        //     bit [14 .. 0] contain the absolute sample value
        //     Only the r upper bits are significant, where r is the resolution
        //     Resolution:
        //        12   -> [14 .. 3] (bitmask 0x7FF8)
        //        10   -> [14 .. 5] (bitmask 0x7FE0)
        //         9   -> [14 .. 6] (bitmask 0x7FC0)
        //         7   -> [14 .. 8] (bitmask 0x7F00)

        return value;
    }

    /***********************************************************************************
      Copyright 2007 Texas Instruments Incorporated. All rights reserved.


    Error Messages:

     

     
    adc.c 
    icc8051.exe C:\Texas Instruments\source\components\radios\cc2530\adc.c -lCN C:\Documents and Settings\Danny\My Documents\IAR Embedded 
    Workbench\Test\Debug\List\ -o C:\Documents and Settings\Danny\My Documents\IAR Embedded Workbench\Test\Debug\Obj\ -e --no_cse --no_unroll 
    --no_inline --no_code_motion --no_tbaa --debug --core=plain --dptr=16,1 --data_model=small --code_model=near --calling_convention=idata_reentrant 
    --place_constants=data --nr_virtual_regs 8 -I C:\Documents and Settings\Danny\My Documents\IAR Embedded Workbench\Test\ -I C:\Program Files\IAR 
    Systems\Embedded Workbench 5.3 Evaluation version\8051\INC\ -I C:\Program Files\IAR Systems\Embedded Workbench 5.3 Evaluation version\8051\
    INC\CLIB\ -Ol
     
       IAR C/C++ Compiler V7.51A/W32 for 8051
       Copyright 2004-2009 IAR Systems AB. 
       Time limited license: 26 days left
    Error[Pe020]: identifier "ADCCFG" is undefined C:\Texas Instruments\source\components\radios\cc2530\adc.c 36
    Error[Pe020]: identifier "ADCIF" is undefined C:\Texas Instruments\source\components\radios\cc2530\adc.c 38
    Error[Pe020]: identifier "ADCCON3" is undefined C:\Texas Instruments\source\components\radios\cc2530\adc.c 39
    Error[Pe020]: identifier "ADCH" is undefined C:\Texas Instruments\source\components\radios\cc2530\adc.c 42
    Error[Pe020]: identifier "ADCL" is undefined C:\Texas Instruments\source\components\radios\cc2530\adc.c 43
     
    Errors: 5
    Warnings: none
    Error while running C/C++ Compiler
     
    Done. 5 error(s), 0 warning(s)

     

    Anyone out there faced the same problem?

     

  • Hi Danny,

    I am facing the same problem too!

    You can solve it by following my piece of code.

     

    #ifndef ADC_ENABLE_CHANNEL
    #define ADC_ENABLE_CHANNEL


        ADC_ENABLE_CHANNEL(channel);

        ADCIF = 0;
        ADC_SINGLE_CONVERSION(

    reference | resolution | channel);
        while(!ADCIF);

        value  = (ADCH << 8) & 0xff00;
        value |= ADCL;

        ADC_DISABLE_CHANNEL(channel);
    #endif

    all you need to do is define the registers using #ifndef ADC_ENABLE_CHANNEL

    But I'm having some other problems with this piece of code when I compile it.
    I am getting these errors.



    Warning[Pe549]: variable "value" is used before its value is set C:\Texas Instruments\source\components\
    radios\cc2530\adc.c 63
    Warning[Pe550]: parameter "reference" was set but never used C:\Texas Instruments\source\components\radios\cc2530\adc.c 31
    Warning[Pe550]: parameter "resolution" was set but never used C:\Texas Instruments\source\components\radios\cc2530\adc.c 31
    Warning[Pe550]: parameter "channel" was set but never used C:\Texas Instruments\source\components\radios\cc2530\adc.c 31

    Anyone out there who can fix this??? I need help!!!

    Thanks in advance.
  • Hi, esy,

    I am experiencing the same problem. I added the path in the preprecessor under c/c++ compiler and also made sure the file is not excluded from compiling . However, the system still gives me the following error:

    Fatal Error[Pe005]: could not open source file "hal_types.h" C:\ZStack_27_12_2010\COMPONENTS\OSAL\INCLUDE\ZComDef.h 54 

    In my project, various other files included "hal_types.h" like Hal_timer.c and Hal_led.c, but the compiler only complains about the file 'ZComDef.h".
    I also tried to add the other way you suggested "#include "../../relative/path/to/hal_types.h". This method would solve the error Pe005 for the particular file but would report another file with the same error. I kept on changing them to the exact directory and there was never a stop.

    This problem is too erratic. I have no clue at all. Does IAR have any bugs? Btw, I am using IAR EW8051 7.30B.

    Thanks in advance.