Hi,
I'm trying to read Temperature Sensor (LM94022) presentt on ICE v2.1 board. However there is no example given to read this sensor in SDK (am335x_sysbios_ind_sdk_1.1.0.3).
I've taken example code (..\sdk\starterware\examples\evmAM335x\adc\adcVoltMeasure.c) of starterware to start with and integrated this code in a sys/bios project.
But I'm not able to read the sensor value correctly. It is always returning a fixed value(0xFFF). I'm adding a snapshot of schematic of ICE v2.1
I'm not sure if I'm configuring the internal ADC correctly. Please correct me as I"ve pasted code for adc configuration.
========================
Code for Reading Temperature Sensor value.
========================
volatile unsigned int flagADC;
unsigned int sample;
unsigned char count_adc_int = 0;
// function prototypes
void StepConfigure(unsigned int stepSel, unsigned int fifo, unsigned int positiveInpChannel);
void ADCInit(void);
Void ADC_Task(UArg arg1, UArg arg2);
Void create_adc_tasks(Void);
Void adc_int_isr(UArg arg);
/**
* ADCInit: Function to Initialize ADC in 1 Ch(AN0) mode, one-shot measurement
* mode.
*
**/
void ADCInit(void)
{
TSCADCModuleClkConfig();
TSCADCConfigureAFEClock(TSC_ADC_INSTANCE, 24000000, 3000000);// Configures ADC to 3Mhz
TSCADCTSTransistorConfig(TSC_ADC_INSTANCE, TSCADC_TRANSISTOR_ENABLE);// Enable Transistor bias
TSCADCStepIDTagConfig(TSC_ADC_INSTANCE, 1);
// Disable Write Protection of Step Configuration regs
TSCADCStepConfigProtectionDisable(TSC_ADC_INSTANCE);
// Configure step 1 for channel 1(AN0)
StepConfigure(0, TSCADC_FIFO_0, TSCADC_POSITIVE_INP_CHANNEL1);
// General purpose inputs
TSCADCTSModeConfig(TSC_ADC_INSTANCE, TSCADC_GENERAL_PURPOSE_MODE);
// Enable step 1
TSCADCConfigureStepEnable(TSC_ADC_INSTANCE, 1, 1);
// Clear the status of all interrupts
//CleanUpInterrupts();
// End of sequence interrupt is enable
TSCADCEventInterruptEnable(TSC_ADC_INSTANCE, TSCADC_END_OF_SEQUENCE_INT);
// Enable the TSC_ADC_SS module
TSCADCModuleStateSet(TSC_ADC_INSTANCE, TSCADC_MODULE_ENABLE);
}
/**
* StepConfigure: Function to Initialize ADC channel, reference voltage, Fifo
* and one-shot measurement mode.
*
**/
void StepConfigure(unsigned int stepSel, unsigned int fifo,
unsigned int positiveInpChannel)
{
// Configure ADC to Single ended operation mode
TSCADCTSStepOperationModeControl(TSC_ADC_INSTANCE,
TSCADC_SINGLE_ENDED_OPER_MODE, stepSel);
// Configure step to select Channel, reference voltages
TSCADCTSStepConfig(TSC_ADC_INSTANCE, stepSel, TSCADC_NEGATIVE_REF_VSSA,
positiveInpChannel, TSCADC_NEGATIVE_INP_CHANNEL1, TSCADC_POSITIVE_REF_VDDA);
// XPPSW Pin is on, Which pull up the AN0 line
TSCADCTSStepAnalogSupplyConfig(TSC_ADC_INSTANCE, TSCADC_XPPSW_PIN_ON, TSCADC_XNPSW_PIN_OFF,
TSCADC_YPPSW_PIN_OFF, stepSel);
// XNNSW Pin is on, Which pull down the AN1 line
TSCADCTSStepAnalogGroundConfig(TSC_ADC_INSTANCE, TSCADC_XNNSW_PIN_ON, TSCADC_YPNSW_PIN_OFF,
TSCADC_YNNSW_PIN_OFF, TSCADC_WPNSW_PIN_OFF, stepSel);
//select fifo 0 or 1
TSCADCTSStepFIFOSelConfig(TSC_ADC_INSTANCE, stepSel, fifo);
// Configure ADC to one shot mode
TSCADCTSStepModeConfig(TSC_ADC_INSTANCE, stepSel, TSCADC_ONE_SHOT_SOFTWARE_ENABLED);
}
Void ADC_Task(UArg arg1, UArg arg2)
{
int analogSensor;
//char t_str[32];
Task_sleep(2500); // Give two and half second to taskOne
// Task will run this loop forever
while(1)
{
ADCInit(); // Set-up ADC for one-shot measure
while(flagADC); // Wait that the analog to digital conversion has been done
analogSensor = sample*439/1000; // Conversion to have a value in mV
//sprintf(t_str,"Temperature: %dmV.\n",analogSensor);
//UARTPutString(uartInstance,t_str); // Push it through the UART you it's readable for users
UARTPutString(uartInstance,"\n\rTemperature ");
UARTPutInteger(uartInstance,count_adc_int);
UARTPutString(uartInstance," : ");
UARTPutIntegerHex(uartInstance,(analogSensor));
flagADC = 1; // Will be turn to 0 at the next conversion
Task_sleep(5000); // Repeat every 5 seconds
}
}
Void create_adc_tasks(Void)
{
////////////Task Creation//////////////////
Task_Params taskParams;
Task_Params_init(&taskParams);
taskParams.priority = 12;
taskParams.stackSize = 1512;
adc_tsk= Task_create (ADC_Task, &taskParams, NULL);
if (NULL == adc_tsk)
{
System_abort("ADC Task create failed");
BIOS_exit(0);
}
//////////HWI Creation//////////////////////
Hwi_Params hwiParams;
Hwi_Params_init(&hwiParams);
hwiParams.priority = 6;
hwiParams.enableInt = false;
adcHwiInt = Hwi_create(SYS_ADC_INT, adc_int_isr, &hwiParams, NULL);
if (NULL == adcHwiInt)
{
System_abort("HWI ADC int creation failed");
BIOS_exit(0);
}
Hwi_enableInterrupt(SYS_ADC_INT);
}
Void adc_int_isr(UArg arg)
{
volatile unsigned int status;
count_adc_int++;
count_adc_int = count_adc_int % 200;
status = TSCADCIntStatus(TSC_ADC_INSTANCE);
TSCADCIntStatusClear(TSC_ADC_INSTANCE, status);
if(status & TSCADC_END_OF_SEQUENCE_INT)
{
/* Read data from fifo 0 */
sample = TSCADCFIFOADCDataRead(TSC_ADC_INSTANCE, TSCADC_FIFO_0);
flagADC = 0;
}
}