有大神指导一下吗?
现在我在用CC2640R2F的ADC功能是参考ti例程adcsinglechannel做的。但是我发现我一旦调用ADC_init();函数我所有的按键中断全部失灵。而且ADC功能也不正常。
以下是我的配置:
引用的头文件如下:
#include <ti/drivers/ADC.h>
#include <ti/drivers/adc/ADCCC26XX.h>
配置文件如下:
/* Analog Capable DIOs */
#define CC2640R2_LAUNCHXL_DIO5_ANALOG IOID_5
#define CC2640R2_ADCCOUNT 1
typedef enum CC2640R2_LAUNCHXL_ADCName {
CC2640R2_LAUNCHXL_ADC0 = 0,
CC2640R2_LAUNCHXL_ADC1,
CC2640R2_LAUNCHXL_ADC2,
CC2640R2_LAUNCHXL_ADC3,
CC2640R2_LAUNCHXL_ADC4,
CC2640R2_LAUNCHXL_ADC5,
CC2640R2_LAUNCHXL_ADC6,
CC2640R2_LAUNCHXL_ADC7,
CC2640R2_LAUNCHXL_ADCDCOUPL,
CC2640R2_LAUNCHXL_ADCVSS,
CC2640R2_LAUNCHXL_ADCVDDS,
CC2640R2_LAUNCHXL_ADCCOUNT
} CC2640R2_LAUNCHXL_ADCName;
ADCCC26XX_Object adcCC26xxObjects[CC2640R2_ADCCOUNT];
const ADCCC26XX_HWAttrs adcCC26xxHWAttrs[CC2640R2_ADCCOUNT] = {
{
.adcDIO = CC2640R2_LAUNCHXL_DIO5_ANALOG,
.adcCompBInput = ADC_COMPB_IN_AUXIO5,
.refSource = ADCCC26XX_FIXED_REFERENCE,
.samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US,
.inputScalingEnabled = true,
.triggerSource = ADCCC26XX_TRIGGER_MANUAL,
.returnAdjustedVal = false
}
};
//ADC
const ADC_Config ADC_config[CC2640R2_ADCCOUNT] = {
{&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC2640R2_LAUNCHXL_ADC5], &adcCC26xxHWAttrs[CC2640R2_LAUNCHXL_ADC5]},
};
//ADC_COMPB_IN_AUXIO5
const uint_least8_t ADC_count = CC2640R2_ADCCOUNT;
其他什么都不做,然后我在初始化函数那里加上 ADC_init();就出问题了。请问我哪个地方配置出错了?
有能够正常跑起来的ADC例子可以给我参考一下吗?
Susan Yang:
请问您按键是用的哪些管脚?是否和ADC的引脚有冲突?
Jasmine Wang:
回复 Susan Yang:
我使用的按键IO口是DIO7和IOD6,ADC检测口是DIO5,没有冲突。 Susan有建议吗?
Alvin Chen:
回复 Jasmine Wang:
void *threadFxn0(void *arg0) {ADC_Handleadc;ADC_Paramsparams;int_fast16_t res;ADC_Params_init(¶ms);adc = ADC_open(Board_ADC0, ¶ms);if (adc == NULL) {Display_printf(display, 0, 0, "Error initializing ADC channel 0\n");while (1);}/* Blocking mode conversion */res = ADC_convert(adc, &adcValue0);if (res == ADC_STATUS_SUCCESS) {adcValue0MicroVolt = ADC_convertRawToMicroVolts(adc, adcValue0);Display_printf(display, 0, 0, "ADC channel 0 convert result: %d uV\n", adcValue0MicroVolt);}else {Display_printf(display, 0, 0, "ADC channel 0 convert failed\n");}ADC_close(adc);return (NULL); }你参照这个用ADC_OPEN配置ADC即可,无需使用ADC_INIT。此外如果你要用按键操作推荐使用以下code:/******************************************************************************@fileboard_key.c@brief This file contains the interface to the SRF06EB Key Service.Group: WCS, BTSTarget Device: CC2650, CC2640, CC1350******************************************************************************Copyright (c) 2014-2016, Texas Instruments IncorporatedAll rights reserved.Redistribution and use in source and binary forms, with or withoutmodification, are permitted provided that the following conditionsare met:*Redistributions of source code must retain the above copyrightnotice, this list of conditions and the following disclaimer.*Redistributions in binary form must reproduce the above copyrightnotice, this list of conditions and the following disclaimer in thedocumentation and/or other materials provided with the distribution.*Neither the name of Texas Instruments Incorporated nor the names ofits contributors may be used to endorse or promote products derivedfrom this software without specific prior written permission.THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULARPURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER ORCONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OROTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.******************************************************************************Release Name: ble_sdk_2_02_01_18Release Date: 2016-10-26 15:20:04*****************************************************************************//********************************************************************** INCLUDES*/ #include <stdbool.h> #include <ti/sysbios/knl/Clock.h> #include <ti/sysbios/family/arm/m3/Hwi.h> #include <ti/sysbios/knl/Semaphore.h> #include <ti/sysbios/knl/Queue.h>#include <ti/drivers/pin/PINCC26XX.h>#ifdef USE_ICALL #include <icall.h> #endif#include <inc/hw_ints.h>#include "util.h" #include "board_key.h" #include "board.h"/********************************************************************** TYPEDEFS*//********************************************************************** LOCAL FUNCTIONS*/ static void Board_keyChangeHandler(UArg a0); static void Board_keyCallback(PIN_Handle hPin, PIN_Id pinId);/******************************************************************************** EXTERNAL VARIABLES*//********************************************************************** LOCAL VARIABLES*/// Value of keys Pressed static uint8_t keysPressed;// Key debounce clock static Clock_Struct keyChangeClock;// Pointer to application callback keysPressedCB_t appKeyChangeHandler = NULL;// Memory for the GPIO module to construct a Hwi Hwi_Struct callbackHwiKeys;// PIN configuration structure to set all KEY pins as inputs with pullups enabled PIN_Config keyPinsCfg[] = { #if defined (CC2650_LAUNCHXL) || defined (CC1350_LAUNCHXL)Board_BTN1| PIN_GPIO_OUTPUT_DIS| PIN_INPUT_EN|PIN_PULLUP,Board_BTN2| PIN_GPIO_OUTPUT_DIS| PIN_INPUT_EN|PIN_PULLUP, #elif defined (CC2650DK_7ID)|| defined (CC1350DK_7XD)Board_KEY_SELECT| PIN_GPIO_OUTPUT_DIS| PIN_INPUT_EN|PIN_PULLUP,Board_KEY_UP| PIN_GPIO_OUTPUT_DIS| PIN_INPUT_EN|PIN_PULLUP,Board_KEY_DOWN| PIN_GPIO_OUTPUT_DIS| PIN_INPUT_EN|PIN_PULLUP,Board_KEY_LEFT| PIN_GPIO_OUTPUT_DIS| PIN_INPUT_EN|PIN_PULLUP,Board_KEY_RIGHT| PIN_GPIO_OUTPUT_DIS| PIN_INPUT_EN|PIN_PULLUP, #endifPIN_TERMINATE };PIN_StatekeyPins; PIN_Handle hKeyPins;/********************************************************************** PUBLIC FUNCTIONS*/ /********************************************************************** @fnBoard_initKeys** @briefEnable interrupts for keys on GPIOs.** @paramappKeyCB - application key pressed callback** @returnnone*/ void Board_initKeys(keysPressedCB_t appKeyCB) {// Initialize KEY pins. Enable int after callback registeredhKeyPins = PIN_open(&keyPins, keyPinsCfg);PIN_registerIntCb(hKeyPins, Board_keyCallback);#if defined (CC2650_LAUNCHXL) || defined (CC1350_LAUNCHXL)PIN_setConfig(hKeyPins, PIN_BM_IRQ, Board_BTN1| PIN_IRQ_NEGEDGE);PIN_setConfig(hKeyPins, PIN_BM_IRQ, Board_BTN2| PIN_IRQ_NEGEDGE); #elif defined (CC2650DK_7ID)|| defined (CC1350DK_7XD)PIN_setConfig(hKeyPins, PIN_BM_IRQ, Board_KEY_SELECT| PIN_IRQ_NEGEDGE);PIN_setConfig(hKeyPins, PIN_BM_IRQ, Board_KEY_UP| PIN_IRQ_NEGEDGE);PIN_setConfig(hKeyPins, PIN_BM_IRQ, Board_KEY_DOWN| PIN_IRQ_NEGEDGE);PIN_setConfig(hKeyPins, PIN_BM_IRQ, Board_KEY_LEFT| PIN_IRQ_NEGEDGE);PIN_setConfig(hKeyPins, PIN_BM_IRQ, Board_KEY_RIGHT| PIN_IRQ_NEGEDGE); #endif#ifdef POWER_SAVING//Enable wakeup #if defined (CC2650_LAUNCHXL) || defined (CC1350_LAUNCHXL)PIN_setConfig(hKeyPins, PINCC26XX_BM_WAKEUP, Board_BTN1 | PINCC26XX_WAKEUP_NEGEDGE);PIN_setConfig(hKeyPins, PINCC26XX_BM_WAKEUP, Board_BTN2 | PINCC26XX_WAKEUP_NEGEDGE); #elif defined (CC2650DK_7ID)|| defined (CC1350DK_7XD)PIN_setConfig(hKeyPins, PINCC26XX_BM_WAKEUP, Board_KEY_SELECT | PINCC26XX_WAKEUP_NEGEDGE);PIN_setConfig(hKeyPins, PINCC26XX_BM_WAKEUP, Board_KEY_UP | PINCC26XX_WAKEUP_NEGEDGE);PIN_setConfig(hKeyPins, PINCC26XX_BM_WAKEUP, Board_KEY_DOWN | PINCC26XX_WAKEUP_NEGEDGE);PIN_setConfig(hKeyPins, PINCC26XX_BM_WAKEUP, Board_KEY_LEFT | PINCC26XX_WAKEUP_NEGEDGE);PIN_setConfig(hKeyPins, PINCC26XX_BM_WAKEUP, Board_KEY_RIGHT | PINCC26XX_WAKEUP_NEGEDGE); #endif #endif //POWER_SAVING// Setup keycallback for keysUtil_constructClock(&keyChangeClock, Board_keyChangeHandler,KEY_DEBOUNCE_TIMEOUT, 0, false, 0);// Set the application callbackappKeyChangeHandler = appKeyCB; }/********************************************************************** @fnBoard_keyCallback** @briefInterrupt handler for Keys** @paramnone** @returnnone*/ static void Board_keyCallback(PIN_Handle hPin, PIN_Id pinId) {keysPressed = 0;#if defined (CC2650_LAUNCHXL) || defined (CC1350_LAUNCHXL)if ( PIN_getInputValue(Board_BTN1) == 0 ){keysPressed |= KEY_LEFT;}if ( PIN_getInputValue(Board_BTN2) == 0 ){keysPressed |= KEY_RIGHT;}#elif defined (CC2650DK_7ID)|| defined (CC1350DK_7XD)if ( PIN_getInputValue(Board_KEY_SELECT) == 0 ){keysPressed |= KEY_SELECT;}if ( PIN_getInputValue(Board_KEY_UP) == 0 ){keysPressed |= KEY_UP;}if ( PIN_getInputValue(Board_KEY_DOWN) == 0 ){keysPressed |= KEY_DOWN;}if ( PIN_getInputValue(Board_KEY_LEFT) == 0 ){keysPressed |= KEY_LEFT;}if ( PIN_getInputValue(Board_KEY_RIGHT) == 0 ){keysPressed |= KEY_RIGHT;} #endifUtil_startClock(&keyChangeClock); }/********************************************************************** @fnBoard_keyChangeHandler** @briefHandler for key change** @paramUArg a0 - ignored** @returnnone*/ static void Board_keyChangeHandler(UArg a0) {if (appKeyChangeHandler != NULL){// Notify the application(*appKeyChangeHandler)(keysPressed);} } /********************************************************************* *********************************************************************/
da qin zheng sheng:
你的芯片是7*7的封装不?
Jasmine Wang:
回复 Alvin Chen:
Dear Alvin:
我参考网上的例程已经可以检测到AD值了,但是我发现它的AD基准电压是4.3V,我想要将电源电压作为参考电压,请问要怎么设置?