API  2.2
TSmarT Software Library
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
ai_read.c

Example showing how to read analog values through a selected pin.

/*
* @file ai.c
* @author TST
* @version V0.0
* @date 20/06/2012
* @brief Analog Input (AI) example. This is an example showing how to initialize the device and read
* analog values from a selected pin. An ADC is used to convert the analog input values
*
*/
/* This file includes all the necessary headers (System, STM32, FreeRTOS, TS_Drivers, TS_Boards, TS_Devices
* and TS_Utils) so the program can work properly */
#include "tsmart.h"
#define AI tsmart_ai0a
/*
* Task function. Main process to read analog values through a selected pin. It makes a measure every second.
*
*/
void vAI_READ(void *pvParameters){
/* Variables */
int32_t value;
for(;;){
/* Read analog input through the selected pin. The measure is stored in the variable "value" */
value = TSMART_AI_Read(&AI);
/* 1 second delay to make the next measurement */
vTaskDelay(1000/portTICK_RATE_MS);
}
}
/*
* @brief init() function
*
* This is the first thing that the user must do for using TSmarT.
* It initializes the specific hardware resources (GPRS, GPS, AI, DIO, MODBUS, MSA...)
* and software resources (queues, mutex, tasks...) for the user application.
*
* The way to fill in this function properly is to initialize first
* hardware resources and after that software resources.
*
* This function must return: TSMART_PASS when every thing is OK or
* TSMART_FAIL when a failure happened.
*
* @return
* @arg TSMART_PASS
* @arg TSMART_FAIL
*/
int32_t init() {
/* Variables */
tsmart_ai_config_t tsmart_ai_config;
/* ************************************************************************* */
/* Debug Mode */
/* ************************************************************************* */
/* ************************************************************************* */
/* Initialize resources */
/* ************************************************************************* */
/* Set Analog Input (AI) configuration (ADC configuration is needed to use the AI).
* User needs to configure the Analog Digital Converter (ADC) with the desire values */
tsmart_ai_config.ai_mode = TSMART_AI_MODE_INDEPENDENT;
tsmart_ai_config.ai_scan_conv_mode = DISABLE;
tsmart_ai_config.ai_continuous_conv_mode = DISABLE;
tsmart_ai_config.ai_data_align = TSMART_AI_DATAALIGN_RIGHT;
tsmart_ai_config.ai_sample_time = TSMART_AI_SAMPLETIME_41CYCLES5;
tsmart_ai_config.adc = TSMART_AI_ADC1;
/* Initialize Analog Input (AI) user is going to use. In this example ai0a is initialized */
TSMART_AI_Init(&AI, &tsmart_ai_config);
/* ************************************************************************* */
/* Application task */
/* ************************************************************************* */
/* Create AI_READ task */
if(xTaskCreate(vAI_READ, "AI_READ", 256, NULL, 7, NULL) != pdPASS){
return TSMART_FAIL;
}
/* Everything OK */
return TSMART_PASS;
}