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.

CC2540 External Analog Sensor

Other Parts Discussed in Thread: CC2540

All,

I have recently purchased your CC2540 Mini Development Kit which includes the keyfob and USB dongle. All the hardware seems to work fine however I am now trying to get my own working application loaded up and working on the keyfob. However I am running into problems. Here is the basic idea of my project:

1. I have an external sensor with output ranges from 0-5V which I need to hook up to the internal ADC on the CC2540 Keyfob.

2. Then with this ADC data I want to be able to transfer this converted data back to my host computer for processing.

This is the only basic operation I need out of my application. I have looked through plenty of example code and attempted to edit it to fit my needs however none of it seems to work. So if any of you could help me to get my analog sensor hooked up (preferably on pin P0_6) to working ADC, with an external reference of 5V and that will continuously transmit data back to the my computer that would be great.

 

-Christopher Calvo

  • Have you downloaded and installed the KeyFobDemo application?

    http://processors.wiki.ti.com/index.php/Category:KeyFobDemo

    In this application the application uses the ADC HAL drivers to measure the battery voltage once every 5 seconds. You can modify the application to measure your analog signal instead of VDD. The ADC reference voltage cannot exceed VDD (maximum of 3.9V), but you can put a simple voltage divider to convert the range from 0-5V to 0-VDD.

  • Willis,

    I took your advice and went ahead and tried to retro-fit some code together to at least get the pin P0_6 to be read in as an analog ADC value. I used the battery code in the keyfobdemo and changed it around as to read in P0_6 ADC analog value (adc_read) and if the value is less than 511 it sets batteryLevel to 50 however if the analog value (adc_read) is greater than 511 it sets batteryLevel to 100. The problem I having now is that no matter what I do the code always outputs 50 as the batteryLevel meaning that adc_read never gets to be greater than 511 which is simply impossible because I have P0_6 (which I believe is test pin 1) connected to a power supply outputting 1.25 V. What do you think I am doing wrong? Here is the code:

    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    //First of all this is the change of pin registers to set up AIN6 and AIN7 as analog inputs:

      P0SEL = 0xC0; // Configure Port 0 as GPIO
      P1SEL = 0x40; // Configure Port 1 as GPIO, except P1.6 for peripheral function for buzzer
      P2SEL = 0; // Configure Port 2 as GPIO

     // Set AIN6 as analog input
      APCFG = 0xC0;
      /*
      P0DIR = 0xFC; // Port 0 pins P0.0 and P0.1 as input (buttons),
                    // all others (P0.2-P0.7) as output
      */

      P0DIR = 0x3C; // Port 0 pins P0.0, P0.1 and P0.6  and P0.7 as input (buttons and sensor),
                    // all others (P0.2-P0.5 and P0.7) as output
      P1DIR = 0xFF; // All port 1 pins (P1.0-P1.7) as output
      P2DIR = 0x1F; // All port 1 pins (P2.0-P2.4) as output
     
      P0 = 0x03; // All pins on port 0 to low except for P0.0 and P0.1 (buttons)
      P1 = 0;   // All pins on port 1 to low
      P2 = 0;   // All pins on port 2 to low 


      // initialize the ADC for battery reads
      HalAdcInit();

     

    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    // Lastly this is the code I edited within the checkBattery function:

    //Initialize ADC with internal 1.25V set as reference
      HalAdcSetReference( HAL_ADC_REF_125V );
     
      // Read the ADC
      adc_read = HalAdcRead( HAL_ADC_CHANNEL_6, HAL_ADC_RESOLUTION_12 );

    if( batteryLevel_current_read < batteryLevel )
        batteryLevel = batteryLevel_current_read;

      if( batteryLevel < BATTERY_LEVEL_CRITICAL_PCT )
        batteryState = BATTERY_STATE_CRITICAL_REPLACE_NOW;
      else
        batteryState = BATTERY_STATE_DISCHARGING;
     
      if( adc_read > (uint16)(511))
        batteryLevel = (uint8)(100);
      if( adc_read <= (uint16)(511))
        batteryLevel = (uint8)(50);

      // Update the Battery Profile
      Battery_SetParameter( BATTERY_ATTR_LEVEL, sizeof ( uint8 ), &batteryLevel );
      Battery_SetParameter( BATTERY_ATTR_STATE, sizeof ( uint8 ), &batteryState );

    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

     

  • I want to replace the buzzer with a speaker on the CC2540

  • Can anyone help me I need to replace the buzzer on the CC2540 keyfob board with a speaker can it be done