I am using TM4C123GH6PM lauchpad.
IAR developement software.
I wanted to use two sensor on A0 & A1 pins.
Read the values sequencially, do the processing.
Here is my code.
Please correct:
......................................................................................................................................................................................................................................
#include <lm4f120h5qr.h>
#include <stdlib.h>
#include <stdio.h>
//#include <intrins.h>
#include <math.h>
#include <string.h>
/* ...........................................
DATA PA4 13
SCK PA2 11
SS PA3 12
............................................*/
unsigned long ADC_RESULT=0;
float ADC_RESULT1=0;
void adc_init();
unsigned long ADC();
void send_dac();
void serial_clk();
unsigned long ADC()
{
unsigned long result;
ADC0->PSSI = 0X0004; //Begin sampling on Sample Sequencer 2
while((ADC0->RIS &0X04)==0);
result = ADC0->SSFIFO2 &0XFFF;
ADC0->ISC = 0X0004;
return result;
}
int main(void)
{
//...13.4.1 Module Initialization pg. 817
SYSCTL->RCGCADC =0X00000001; //1. ADC 0 module selected
//General purpose I/O Run Mode Clock RRCGCGPIO pg. 340
SYSCTL->RCGCGPIO=0X00000011; //2. Port A & Port E are selected
//DAC Pin settings
// GPIO direction GPIODIR pg. 663
GPIOA->DIR =0X1C; // PA2, PA3, PA4 as output pin
// GPIO Digital Enable (GPIODEN) pg.682
GPIOA->DEN =0X1C; // PA2, PA3, PA4 are Digital Enabled
// GPIO Data (GPIODATA) pg. 662
GPIOA->DATA =0X08; // Initial pin data
//ADC port pin initialization
GPIOE->AFSEL = (1<<2)|(1<<3); //3. Set the GPIOAFSELbits for the ADC input pins
GPIOE->DEN &= ~0X0C; //4. Configure theAINx signals to be analog inputs by clearing the correspondingDENbit in the GPIO Digital Enable (GPIODEN)
GPIOE->AMSEL = (1<<2)|(1<<3); //5. Disable the analog isolation circuit for all ADC input pins that are to be used by writing a 1 to the appropriate bits of the GPIOAMSELregister
GPIOE->DIR &= ~0X0C;
//13.4.2 Sample Sequencer Configuration
ADC0->ACTSS &= ~0X0004; //1. Ensure that the sample sequencer is disabled by clearing the correspondingASENnbit in the ADCACTSSregister
// ADC SS2 Enable- 4 sample
ADC0->EMUX = 0XF000; //2. Configure the trigger event for the sample sequencer in theADCEMUX register
// set as Continuously sample
ADC0->SSMUX3 = 1; //4. For each sample in the sample sequence, configure the corresponding input source in the ADCSSMUXnregister
ADC0->SSMUX2 = 0; // SSMUX3 -> AIN1 & SSMUX2 -> AIN0
ADC0->SSCTL2 = 0X60; //5. For each sample in the sample sequence, configure the sample control bits in the corresponding nibble in theADCSSCTLn register
// 2nd sample is last sample and Interrupt enabled after that (This for SS2)
ADC0->IM = (1<<2); //6. interrupts are to be used, set the corresponding MASKbit in the ADCIM
// ADCSSCTL2 IEn bit is set
ADC0->ACTSS |= 0X0004; //7. Enable the sample sequencer logic by setting the correspondingASENnbit in the ADCACTSS register
ADC0->SSPRI = 0X1023;
while(1)
{
ADC_RESULT = ADC();
ADC_RESULT1 = (ADC_RESULT/4095)*3.3;
ADC_RESULT = ADC_RESULT | 0x3000;
}
}.....................................................................................................................................................................................................................................
I dont understand ADC_RESULT will have which value, from AIN0 or AIN1.
and how to get both value from AIN0 or AIN1.