/* * This program sets up ADC1 Sample Sequener 2 to convert * channel 8 and internal temperature. The result of channel 8 is * written to the LEDs. * Analog channel 8 uses PORTE 5 pin and is connected to * a temperature sensor on Wytec EduBase board. */ #include "TM4C123GH6PM.h" void delayMs(int n); void delayUs(int n); int main(void) { int extTemp; int intTemp; SYSCTL->RCGCGPIO |= 0x10; // enable clock to GPIOE SYSCTL->RCGCADC |= 2; // enable clock to ADC1 SYSCTL->RCGCGPIO |= 0x02; // enable clock to GPIOB // initialize port pin PE5 for ADC1 input GPIOE->AFSEL |= 0x20; // enable alternate function GPIOE->DEN &= ~0x20; // disable digital function GPIOE->AMSEL |= 0x20; // enable analog function // initialize ADC1 Sample Sequencer 2 ADC1->ACTSS &= ~4; // disable ADC1 Sequencer 2 during configuration ADC1->EMUX &= ~0x0F00; // software trigger for sequencer 2 ADC1->SSMUX2 &= ~0xFFFFFFFF; // clear channel selects first ADC1->SSMUX2 |= 0x00000008; // ch 8 for first sample ADC1->SSCTL2 |= 0x000000E0; // finish sequence at 2nd sample with interal temperature and post RIS bit ADC1->ACTSS |= 4; // enable ADC1 sequencer 2 // enable PORTB 3-0 as output for LEDs GPIOB->DIR |= 0x0F; // set PORTB 3-0 as output pins GPIOB->DEN |= 0x0F; // set PORTB 3-0 as digital pins while(1) { ADC1->PSSI |= 4; // start a conversion at sequencer 2 while((ADC1->RIS & 4) == 0) ; // wait for conversion sequence complete extTemp = ADC1->SSFIFO2; // read conversion result of ch 8 from FIFO intTemp = ADC1->SSFIFO2; // read conversion result of internal temp from FIFO ADC1->ISC = 4; // clear completion flag GPIOB->DATA = extTemp; // write the external temperature to LEDs delayMs(100); } } // delay n milliseconds (16 MHz CPU clock) void delayMs(int n) { int i, j; for(i = 0 ; i < n; i++) for(j = 0; j < 3180; j++) {} // do nothing for 1 ms } // delay n microseconds (16 MHz CPU clock) void delayUs(int n) { int i, j; for(i = 0 ; i < n; i++) for(j = 0; j < 3; j++) {} // do nothing for 1 us } // This function is called by the startup assembly // code to perform system specific initialization tasks. void SystemInit(void) { // Grant coprocessor access // This is required since TM4C123G has // a floating point coprocessor SCB->CPACR |= 0x00f00000; }