Example program to create IoT devices for a local network, which connect to a local server.
Dependencies: WebSocketClient WiflyInterface mbed messages
ADC.cpp
00001 /** 00002 * @author Damien Frost 00003 * 00004 * @section LICENSE 00005 * 00006 * Copyright (c) 2016 Damien Frost 00007 * 00008 * Permission is hereby granted, free of charge, to any person obtaining a copy 00009 * of this software and associated documentation files (the "Software"), to deal 00010 * in the Software without restriction, including without limitation the rights 00011 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00012 * copies of the Software, and to permit persons to whom the Software is 00013 * furnished to do so, subject to the following conditions: 00014 * 00015 * The above copyright notice and this permission notice shall be included in 00016 * all copies or substantial portions of the Software. 00017 * 00018 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00019 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00020 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00021 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00022 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00023 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00024 * THE SOFTWARE. 00025 * 00026 * @file "ADC.cpp" 00027 * 00028 * @section DESCRIPTION 00029 * Configuration of the ADC for the IoT example. 00030 * 00031 */ 00032 00033 #include "ADC.h " 00034 #include "globals.h " 00035 #include "mbed.h" 00036 00037 00038 //#define DEBUG 00039 #define INFOMESSAGES 00040 #define WARNMESSAGES 00041 #define ERRMESSAGES 00042 #define FUNCNAME "ADC" 00043 #include "messages.h" 00044 00045 00046 void ConfigureADC(void){ 00047 00048 unsigned int value; 00049 00050 // ensure power is turned on 00051 // Grabbed from lines 54-57 of analogin_api.c 00052 // This turns on the clock to Ports A, B, and C 00053 RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN | RCC_AHB1ENR_GPIOBEN | RCC_AHB1ENR_GPIOCEN; 00054 // This turns on the clock to the ADC: 00055 RCC->APB2ENR |= RCC_APB2ENR_ADC1EN; 00056 00057 00058 // Turn on the ADC: 00059 value = ADC_CR2_ADON; 00060 ADC1->CR2 = value; 00061 wait_us(100); 00062 00063 // Set the EOC flag at the end of every regular conversion: 00064 ADC1->CR2 |= ADC_CR2_EOCS; 00065 00066 // Turn on the internal temperature sensor: 00067 ADC->CCR |= ADC_CCR_TSVREFE; 00068 00069 // Set the first (and only channel) to convert to CH16, the internal temperature sensor: 00070 ADC1->SQR3 |= ADC_SQR3_SQ1_4; 00071 00072 // Set the sample numbers (making this bigger samples more slowly): 00073 ADC1->SMPR2 = ADC_SMPR1_SMP16_1 | ADC_SMPR1_SMP16_2; // Set for 144 ADC clock cycles 00074 00075 00076 INFO("ADC configuration complete!"); 00077 DBG("ADC Registers:"); 00078 DBG("The SR Register reads: %d", ADC1->SR); 00079 DBG("The CR1 Register reads: %d", ADC1->CR1); 00080 DBG("The CR2 Register reads: %d", ADC1->CR2); 00081 DBG("The JSQR Register reads: %d", ADC1->JSQR); 00082 00083 return; 00084 }
Generated on Wed Jul 13 2022 16:56:12 by 1.7.2