| BlueNRG-1 Peripherals drivers Examples

- Main Page
- Modules
- Classes
- Files

- File List
- File Members

ADC_Polling_main.c
Go to the documentation of this file.
1
2 /******************** (C) COPYRIGHT 2016 STMicroelectronics ********************
3 * File Name : ADC_Polling_main.c
4 * Author : VMA DIVISION
5 * Version : 1.0.0
6 * Date : 21-September-2015
7 * Description : Code demostrating the ADC functionality
8 ********************************************************************************
9 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
10 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
11 * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
12 * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
13 * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
14 * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
15 *******************************************************************************/
16
166 /* Includes ------------------------------------------------------------------*/
167 #include "BlueNRG1.h"
168 #include "BlueNRG1_conf.h"
169 #include "SDK_EVAL_Config.h"
170 #include <stdio.h>
171 #include <stdlib.h>
172
185 /* Private typedef -----------------------------------------------------------*/
186 /* Private define ------------------------------------------------------------*/
187 #define SYST_CLOCK 16000000 /* System clock frequency */
188
189 /* Private macro -------------------------------------------------------------*/
190 /* Private variables ---------------------------------------------------------*/
191 volatile uint32_t lSystickCounter=0;
192 ADC_InitType xADC_InitType;
193
194 /* Private function prototypes -----------------------------------------------*/
195 void SdkDelayMs(volatile uint32_t lTimeMs);
196 void ADC_Configuration(void);
197
198 /* Private functions ---------------------------------------------------------*/
199
200
206 int main(void)
207 {
208 float adc_value;
209
210 /* System initialization function */
211 SystemInit();
212
213 /* Identify BlueNRG1 platform */
214 SdkEvalIdentification();
215
216 /* LED initialization function */
217 SdkEvalLedInit(LED1);
218
219 /* UART initialization */
220 SdkEvalComUartInit(UART_BAUDRATE);
221
222 /* SysTick initialization 1ms */
223 SysTick_Config(SYST_CLOCK/1000 - 1);
224
225 /* ADC Initialization */
226 ADC_Configuration();
227
228 /* Start new conversion */
229 ADC_Cmd(ENABLE);
230
231 /* Infinite loop */
232 while(1) {
233
234 /* Polling of End-Of-Conversion flag */
235 if( ADC_GetFlagStatus(ADC_FLAG_EOC)) {
236
237 /* Read converted data */
238 adc_value = ADC_GetConvertedData(xADC_InitType.ADC_Input, xADC_InitType.ADC_ReferenceVoltage);
239
240 /* Print the ADC value converted */
241 if(xADC_InitType.ADC_Input == ADC_Input_TempSensor) {
242 printf("ADC value: %.1f 'C\r\n", adc_value);
243 }
244 else {
245 printf("ADC value: %.0f mV\r\n", adc_value*1000.0);
246 }
247 SdkEvalLedToggle(LED1);
248
249 /* Start new conversion */
250 ADC_Cmd(ENABLE);
251 }
252 /* Application delay before next one shot measurement */
253 SdkDelayMs(100);
254
255 }
256 }
257
263 void SdkDelayMs(volatile uint32_t lTimeMs)
264 {
265 uint32_t nWaitPeriod = ~lSystickCounter;
266
267 if(nWaitPeriod<lTimeMs)
268 {
269 while( lSystickCounter != 0xFFFFFFFF);
270 nWaitPeriod = lTimeMs-nWaitPeriod;
271 }
272 else
273 nWaitPeriod = lTimeMs+ ~nWaitPeriod;
274
275 while( lSystickCounter != nWaitPeriod ) ;
276
277 }
278
279
285 void ADC_Configuration(void)
286 {
287 SysCtrl_PeripheralClockCmd(CLOCK_PERIPH_ADC, ENABLE);
288
289 /* Configure ADC */
290 /* ADC_Input_AdcPin1 == ADC1 */
291 /* ADC_Input_AdcPin2 == ADC2 */
292 /* ADC_Input_AdcPin12 == ADC1 - ADC2 */
293 xADC_InitType.ADC_DecimationRate = ADC_DecimationRate_200;
294 //ADC_Input_BattSensor; //ADC_Input_TempSensor;// ADC_Input_AdcPin1 // ADC_Input_AdcPin12 // ADC_Input_AdcPin2
295 xADC_InitType.ADC_Input = ADC_Input_AdcPin12; //ADC_Input_AdcPin12;
296 xADC_InitType.ADC_ConversionMode = ADC_ConversionMode_Single;
297 xADC_InitType.ADC_ReferenceVoltage = ADC_ReferenceVoltage_0V6; //ADC_ReferenceVoltage_0V6;
298 xADC_InitType.ADC_Attenuation = ADC_Attenuation_9dB54;
299
300 ADC_Init(&xADC_InitType);
301
302 /* Enable auto offset correction */
303 ADC_Calibration(ENABLE);
304 ADC_AutoOffsetUpdate(ENABLE);
305 }
306
307 #ifdef USE_FULL_ASSERT
308
315 void assert_failed(uint8_t* file, uint32_t line)
316 {
317 /* User can add his own implementation to report the file name and line number,
318 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
319
320 /* Infinite loop */
321 while (1)
322 {
323 }
324 }
325
326 #endif
327
328
341 /******************* (C) COPYRIGHT 2015 STMicroelectronics *****END OF FILE****/
SdkDelayMs
void SdkDelayMs(volatile uint32_t lTimeMs)
Delay function in ms.
Definition: ADC_Polling_main.c:263
lSystickCounter
volatile uint32_t lSystickCounter
Definition: ADC_Polling_main.c:191
xADC_InitType
ADC_InitType xADC_InitType
Definition: ADC_Polling_main.c:192
main
int main(void)
Main program.
Definition: ADC_Polling_main.c:206
ADC_Configuration
void ADC_Configuration(void)
ADC_Configuration.
Definition: ADC_Polling_main.c:285
SYST_CLOCK
#define SYST_CLOCK
Definition: ADC_Polling_main.c:187
UART_BAUDRATE
#define UART_BAUDRATE
Definition: ADC_PDM_main.c:225