1. /examples/cc26xx/cc26xx-web-demo/cc26xx-web-demo.c
@@ -55,9 +55,15 @@
#include
#include
#include
+
+#include "ti-lib.h"
+#include "driverlib/aux_adc.h"
+#include "driverlib/aux_wuc.h"
+
/*---------------------------------------------------------------------------*/
PROCESS_NAME(cetic_6lbr_client_process);
PROCESS(cc26xx_web_demo_process, "CC26XX Web Demo");
+PROCESS(adc_process, "ADC process");
/*---------------------------------------------------------------------------*/
/*
* Update sensor readings in a staggered fashion every SENSOR_READING_PERIOD
@@ -84,6 +90,9 @@ static struct uip_icmp6_echo_reply_notification echo_reply_notification;
static struct etimer echo_request_timer;
int def_rt_rssi = 0;
#endif
+
+uint16_t singleSample;
+
/*---------------------------------------------------------------------------*/
process_event_t cc26xx_web_demo_publish_event;
process_event_t cc26xx_web_demo_config_loaded_event;
@@ -110,6 +119,9 @@ DEMO_SENSOR(batmon_temp, CC26XX_WEB_DEMO_SENSOR_BATMON_TEMP,
DEMO_SENSOR(batmon_volt, CC26XX_WEB_DEMO_SENSOR_BATMON_VOLT,
"Battery Volt", "battery-volt", "batmon_volt",
CC26XX_WEB_DEMO_UNIT_VOLT);
+DEMO_SENSOR(adc_dio23, CC26XX_WEB_DEMO_SENSOR_ADC_DIO23,
+ "ADC DIO23", "adc-dio23", "adc_dio23",
+ CC26XX_WEB_DEMO_UNIT_VOLT);
/* Sensortag sensors */
#if BOARD_SENSORTAG
@@ -464,6 +476,14 @@ get_batmon_reading(void *data)
}
}
+ if(adc_dio23_reading.publish) {
+ if(1) {
+ buf = adc_dio23_reading.converted;
+ memset(buf, 0, CC26XX_WEB_DEMO_CONVERTED_LEN);
+ snprintf(buf, CC26XX_WEB_DEMO_CONVERTED_LEN, "%d", singleSample);
+ }
+ }
+
ctimer_set(&batmon_timer, next, get_batmon_reading, NULL);
}
/*---------------------------------------------------------------------------*/
@@ -825,6 +845,7 @@ init_sensors(void)
list_add(sensor_list, &batmon_temp_reading);
list_add(sensor_list, &batmon_volt_reading);
+ list_add(sensor_list, &adc_dio23_reading);
SENSORS_ACTIVATE(batmon_sensor);
#if BOARD_SENSORTAG
@@ -864,6 +885,7 @@ PROCESS_THREAD(cc26xx_web_demo_process, ev, data)
/* Start all other (enabled) processes first */
process_start(&httpd_simple_process, NULL);
+ process_start(&adc_process, NULL);
#if CC26XX_WEB_DEMO_COAP_SERVER
process_start(&coap_server_process, NULL);
#endif
@@ -966,6 +988,56 @@ PROCESS_THREAD(cc26xx_web_demo_process, ev, data)
PROCESS_END();
}
+
+PROCESS_THREAD(adc_process, ev, data)
+{
+ PROCESS_BEGIN();
+ static struct etimer et_adc;
+ while(1)
+ {
+ etimer_set(&et_adc, CLOCK_SECOND*5);
+ PROCESS_WAIT_EVENT();
+ if(etimer_expired(&et_adc)) {
+ //intialisation of ADC
+ ti_lib_aon_wuc_aux_wakeup_event(AONWUC_AUX_WAKEUP);
+ while(!(ti_lib_aon_wuc_power_status_get() & AONWUC_AUX_POWER_ON))
+ { }
+
+ // Enable clock for ADC digital and analog interface (not currently enabled in driver)
+ // Enable clocks
+ ti_lib_aux_wuc_clock_enable(AUX_WUC_ADI_CLOCK | AUX_WUC_ANAIF_CLOCK | AUX_WUC_SMPH_CLOCK);
+ while(ti_lib_aux_wuc_clock_status(AUX_WUC_ADI_CLOCK | AUX_WUC_ANAIF_CLOCK | AUX_WUC_SMPH_CLOCK) != AUX_WUC_CLOCK_READY)
+ { }
+ //printf("clock selected\r\n");
+
+ // Connect AUX IO7 (DIO23, but also DP2 on XDS110) as analog input.
+ AUXADCSelectInput(ADC_COMPB_IN_AUXIO7);
+ //printf("input selected\r\n");
+
+ // Set up ADC range
+ // AUXADC_REF_FIXED = nominally 4.3 V
+ AUXADCEnableSync(AUXADC_REF_FIXED, AUXADC_SAMPLE_TIME_2P7_US, AUXADC_TRIGGER_MANUAL);
+ //printf("init adc --- OK\r\n");
+
+ //Trigger ADC converting
+ AUXADCGenManualTrigger();
+ //printf("trigger --- OK\r\n");
+
+ //reading adc value
+ singleSample = AUXADCReadFifo();
+
+ printf("%d mv on ADC\r\n",singleSample);
+
+ //shut the adc down
+ AUXADCDisable();
+ //printf("disable --- OK\r\n");
+ get_batmon_reading(NULL);
+
+ etimer_reset(&et_adc);
+ }
+ }
+ PROCESS_END();
+}
2./examples/cc26xx/cc26xx-web-demo/cc26xx-web-demo.h
@@ -146,6 +146,7 @@
#define CC26XX_WEB_DEMO_SENSOR_MPU_GYRO_X 12
#define CC26XX_WEB_DEMO_SENSOR_MPU_GYRO_Y 13
#define CC26XX_WEB_DEMO_SENSOR_MPU_GYRO_Z 14
+#define CC26XX_WEB_DEMO_SENSOR_ADC_DIO23 15
/*---------------------------------------------------------------------------*/
extern process_event_t cc26xx_web_demo_publish_event;
extern process_event_t cc26xx_web_demo_config_loaded_event;
3. /examples/cc26xx/cc26xx-web-demo/coap-server.c
@@ -50,6 +50,7 @@ extern resource_t res_leds;
extern resource_t res_batmon_temp;
extern resource_t res_batmon_volt;
+extern resource_t res_adc_dio23;
extern resource_t res_device_sw;
extern resource_t res_device_hw;
@@ -133,6 +134,7 @@ PROCESS_THREAD(coap_server_process, ev, data)
rest_activate_resource(&res_batmon_temp, "sen/batmon/temp");
rest_activate_resource(&res_batmon_volt, "sen/batmon/voltage");
+ rest_activate_resource(&res_adc_dio23, "adc/dio23");
rest_activate_resource(&res_device_hw, "dev/mdl/hw");
rest_activate_resource(&res_device_sw, "dev/mdl/sw");
4. examples/cc26xx/cc26xx-web-demo/resources/res-sensors.c
@@ -111,12 +111,24 @@ res_get_handler_batmon_volt(void *request, void *response, uint8_t *buffer,
buffer, preferred_size, offset);
}
/*---------------------------------------------------------------------------*/
+static void
+res_get_handler_adc_dio23(void *request, void *response, uint8_t *buffer,
+ uint16_t preferred_size, int32_t *offset)
+{
+ res_get_handler_all(CC26XX_WEB_DEMO_SENSOR_ADC_DIO23, request, response,
+ buffer, preferred_size, offset);
+}
+/*---------------------------------------------------------------------------*/
RESOURCE(res_batmon_temp, "title=\"Battery Temp\";rt=\"C\"",
res_get_handler_batmon_temp, NULL, NULL, NULL);
/*---------------------------------------------------------------------------*/
RESOURCE(res_batmon_volt, "title=\"Battery Voltage\";rt=\"mV\"",
res_get_handler_batmon_volt, NULL, NULL, NULL);
/*---------------------------------------------------------------------------*/
+/*---------------------------------------------------------------------------*/
+RESOURCE(res_adc_dio23, "title=\"ADC DIO23\";rt=\"mV\"",
+ res_get_handler_adc_dio23, NULL, NULL, NULL);
+/*---------------------------------------------------------------------------*/
#if BOARD_SENSORTAG
/*---------------------------------------------------------------------------*/
/* MPU resources and handler: Accelerometer and Gyro */
Build cc26xx-web-demo for CC2650 LaunchPad by "make TARGET=srf06-cc26xx BOARD=launchpad/cc2650 cc26xx-web-demo.bin" and download cc26xx-web-demo.bin to your CC2650 LaunchPad. Let it join 6lbr and you should see resource adc/dio23 on COAP interface. You can press Get button to get the ADC reading from DIO23. Try to connect different voltage (0-3.6V) to test.
Hi,I have tested this guide, but in coap I quit BlockOutOfScope, do you know why?
ReplyDeleteHi, Is there an email listed on the blog that can be used to contact you?
ReplyDeleteYou can post your questions on TI E2E forum at https://e2e.ti.com/support/wireless_connectivity/zigbee_6lowpan_802-15-4_mac/f/158 and I will try to help you.
DeleteYou already did answer my question on E2E - Thanks. I am looking for some freelance resource and was wondering if you were a non-TI engineer, because your profile didn't indicate you as a TI employee. Hence I was trying to contact you.
ReplyDeleteI am not TI employee.
ReplyDeleteHi, If you are interested in possibly helping me in the future through some freelance work on TI wireless tech please contact me at my email: kbshetty06-at-gmail. I am in the US. Thanks.
ReplyDeleteHi, When I try to compile this code in contiki it gives an error that adc_dio23_reading is not declared. Can you help me out.
ReplyDeleteThis code already been commit to Contiki github. You can checkout latest code and check CC26XX_WEB_DEMO_ADC_DEMO define in CC26xx-web-demo.
DeleteFor adding the string payload instead of value number. How can I do?
ReplyDeleteThis comment has been removed by the author.
Deletecan i attach to the dio23 pin temperature sensor so it can take the temperature reading??
ReplyDeleteIf your temperature sensor output is analog signal, it’s no problem.
Deleteare these steps necessarily for cc1310 launchpad ??
DeleteIf you git latest source code of Contiki, this example is already in it.
DeleteHello, Even though the DIO23 is port 36 as to the datasheet, you have defined port No.15 to DIO 23 which is not Analog. I'm a bit confused. Would you mind explaining this.
ReplyDelete