CC2640R2F ADC数据发送问题
如题,我现在想使用CC2640R2F的ADC功能,并将ADC的数据通过蓝牙无线发送出去,不知道应该怎么写程序
我安装了1.50.00.58版本的协议栈,为什么没有看到你上面所说的目录呢?
/*
* Copyright (c) 2016-2017, Texas Instruments Incorporated
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of Texas Instruments Incorporated nor the names of
* its contributors may be used to endorse or promote products derived
* from 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 PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS 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 OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* ======== adcsinglechannel.c ========
*/
#include <stdint.h>
#include <stddef.h>
/* POSIX Header files */
#include <pthread.h>
/* Driver Header files */
#include <ti/drivers/ADC.h>
#if defined(CC2650DK_7ID) || defined(CC1310DK_7XD)
#include <ti/drivers/PIN.h>
#endif
#include <ti/display/Display.h>
/* Example/Board Header files */
#include "Board.h"
/* ADC sample count */
#define ADC_SAMPLE_COUNT (10)
#define THREADSTACKSIZE (768)
/* ADC conversion result variables */
uint16_t adcValue0;
uint32_t adcValue0MicroVolt;
uint16_t adcValue1[ADC_SAMPLE_COUNT];
uint32_t adcValue1MicroVolt[ADC_SAMPLE_COUNT];
static Display_Handle display;
/*
* ======== threadFxn0 ========
* Open an ADC instance and get a sampling result from a one-shot conversion.
*/
void *threadFxn0(void *arg0)
{
ADC_Handle adc;
ADC_Params params;
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);
}
/*
* ======== threadFxn1 ========
* Open a ADC handle and get a array of sampling results after
* calling several conversions.
*/
void *threadFxn1(void *arg0)
{
uint16_t i;
ADC_Handle adc;
ADC_Params params;
int_fast16_t res;
ADC_Params_init(¶ms);
adc = ADC_open(Board_ADC1, ¶ms);
if (adc == NULL) {
Display_printf(display, 0, 0, "Error initializing ADC channel 1\n");
while (1);
}
for (i = 0; i < ADC_SAMPLE_COUNT; i++) {
res = ADC_convert(adc, &adcValue1[i]);
if (res == ADC_STATUS_SUCCESS) {
adcValue1MicroVolt[i] = ADC_convertRawToMicroVolts(adc, adcValue1[i]);
Display_printf(display, 0, 0, "ADC channel 1 convert result (%d): %d uV\n", i,
adcValue1MicroVolt[i]);
}
else {
Display_printf(display, 0, 0, "ADC channel 1 convert failed (%d)\n", i);
}
}
ADC_close(adc);
return (NULL);
}
/*
* ======== mainThread ========
*/
void *mainThread(void *arg0)
{
pthread_t thread0, thread1;
pthread_attr_t attrs;
struct sched_param priParam;
int retc;
int detachState;
/* Call driver init functions */
ADC_init();
Display_init();
/* Open the display for output */
display = Display_open(Display_Type_UART, NULL);
if (display == NULL) {
/* Failed to open display driver */
while (1);
}
Display_printf(display, 0, 0, "Starting the acdsinglechannel example\n");
/*
* The CC2650DK_7ID and CC1310DK_7XD measure an ambient light sensor in this example.
* It is not powered by default to avoid high current consumption in other examples.
* The code below turns on the power to the sensor.
*/
#if defined(CC2650DK_7ID) || defined(CC1310DK_7XD)
PIN_State pinState;
PIN_Config AlsPinTable[] =
{
Board_ALS_PWR | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL, /* Turn on ALS power */
PIN_TERMINATE /* Terminate list */
};
/* Turn on the power to the ambient light sensor */
PIN_open(&pinState, AlsPinTable);
#endif
/* Create application threads */
pthread_attr_init(&attrs);
detachState = PTHREAD_CREATE_DETACHED;
/* Set priority and stack size attributes */
retc = pthread_attr_setdetachstate(&attrs, detachState);
if (retc != 0) {
/* pthread_attr_setdetachstate() failed */
while (1);
}
retc |= pthread_attr_setstacksize(&attrs, THREADSTACKSIZE);
if (retc != 0) {
/* pthread_attr_setstacksize() failed */
while (1);
}
/* Create threadFxn0 thread */
priParam.sched_priority = 1;
pthread_attr_setschedparam(&attrs, &priParam);
retc = pthread_create(&thread0, &attrs, threadFxn0, NULL);
if (retc != 0) {
/* pthread_create() failed */
while (1);
}
/* Create threadFxn1 thread */
retc = pthread_create(&thread1, &attrs, threadFxn1, (void* )0);
if (retc != 0) {
/* pthread_create() failed */
while (1);
}
return (NULL);
}