Tool/software: Code Composer Studio
I am working on a project in which I'm attempting to read from an external Temperature Sensor (TMP36) using ADC module 0 Sample Sequencer 3.
I am connecting the sensor to PD2 for AIN13
The first sample is processor triggered and then I set it to be continuously sampled in the interrupt handler.
I walked through the data sheet multiple times and am not sure what I am doing wrong in my code. It seems that in my code I never enter my interrupt handler and therefore never get data from the sensor but I'm not sure how to fix that. I used a test value to see if I ever entered the interrupt handler and the value never updated.
At this point I am not even sure where the issue may lie, I've been debugging for over a week and am not really sure what to do next.
// this file assumes the temperature sensor // uses analog channel 13 to do the AD Conversion // the voltage reflecting the measured temperature // can be calculated by reading the register ADC0_SSFIFO3_R // where only the lowest 12 bits are accesible // Since AN#13 is multiplexed with GPIO Pin D2 // so relevant GPIO Port D configuration is needed #include <stdio.h> #include <stdlib.h> #include <stdint.h> // providing clock to GPIO module #define SYSCTL_RCGCGPIO_R (*((volatile unsigned long *)0x400FE608)) // providing clock to ADC module #define SYSCTL_RCGCADC_R (*((volatile unsigned long *)0x400FE638)) // ADC0 and SS3 #define ADC0_ACTSS_R (*((volatile unsigned long *)0x40038000)) // enable ss3 #define ADC0_IM_R (*((volatile unsigned long *)0x40038008)) // interrupt mask #define ADC0_ISC_R (*((volatile unsigned long *)0x4003800C)) // interrupt clear #define ADC0_EMUX_R (*((volatile unsigned long *)0x40038014)) #define ADC0_PSSI_R (*((volatile unsigned long *)0x40038028)) #define ADC0_SAC_R (*((volatile unsigned long *)0x40038030)) // oversampling #define ADC0_SSEMUX3_R (*((volatile unsigned long *)0x400380B8)) #define ADC0_SSMUX3_R (*((volatile unsigned long *)0x400380A0)) #define ADC0_SSCTL3_R (*((volatile unsigned long *)0x400380A4)) #define ADC0_SSFIFO3_R (*((volatile unsigned long *)0x400380A8)) #define ADC0_PC_R (*((volatile unsigned long *)0x40038FC4)) // GPIO port D #define GPIO_PORTD_AHB_DIR_R (*((volatile unsigned long *)0x4005B400)) #define GPIO_PORTD_AHB_DEN_R (*((volatile unsigned long *)0x4005B51C)) #define GPIO_PORTD_AHB_AMSEL_R (*((volatile unsigned long *)0x4005B528)) #define GPIO_PORTD_AHB_AFSEL_R (*((volatile unsigned long *)0x4005B420)) //#define GPIO_PORTD_AHB_DATA_R (*((volatile unsigned long *)0x4005B3FC)) // NVIC interrupt module #define NVIC_EN0_R (*((volatile unsigned long *)0xE000E100)) uint32_t TempData; //uint32_t Test = 2; // This function generates the delay void Delay ( volatile unsigned int delay ){ volatile unsigned int i, j; for (i = 0; i < delay ; i++) { // introduces a delay of about 10 us at 16 MHz for (j = 0; j < 12; j ++) ; } } // ADC0 interrupt service routine for sequencer 3 void ADC0SS3_Handler (void) { // Test++; ADC0_EMUX_R |= 0xF000; ADC0_ISC_R |= 0x08; TempData = ADC0_SSFIFO3_R; //& 0x0FFF; } // main function int main ( void ){ volatile float Temp; // 1. Enable the clock for ADC0 SYSCTL_RCGCADC_R |= 0x01; // 2. Enable the clock to Port D SYSCTL_RCGCGPIO_R |= 0x08; // configuration of port D pin2 GPIO_PORTD_AHB_AFSEL_R |= 0x04; // functions as analog let AIN13 work GPIO_PORTD_AHB_DEN_R &= 0x00; // disable digital enable analog GPIO_PORTD_AHB_AMSEL_R |= 0x04; // enable analog GPIO_PORTD_AHB_DIR_R &= 0x00; // 0 for input // Initiate sequencer 3 ADC0_PSSI_R |= 0x08; // and introduce a delay by call Delay function Delay (3); // Select AIN13 ( PD2 ) as the analog input // 1st sample is end of sequence and source of interrupt ADC0_PC_R |= 0x03; // quarter convertion rate; 48*Tadc periods pause ADC0_SAC_R |= 0x04; // 16x oversampling and then averaged // Unmask ADC0 sequence 3 interrupt ADC0_IM_R |= 0xF7; // step 6 // Clear the interrupt for ADC0 sequencer 3 ADC0_ISC_R |= 0x08; // Enable ADC0 module for sequencer 3 ADC0_ACTSS_R &= 0x00; // step 1 disabling sample sequencer 3 ADC0_EMUX_R &= 0x0000; ADC0_SSEMUX3_R = 0x0; ADC0_SSMUX3_R |= 0x0D; // step 4 select AIN13 ADC0_SSCTL3_R |= 0x06; // step 5 ADC0_IM_R |= 0x08; // step 6 ADC0_ACTSS_R |= 0x08; // step 7 enabling sample sequencer 3 ADC0_ISC_R |= 0x08; // Enable ADC0 sequencer 3 interrupt in NVIC interrupt number is 17 NVIC_EN0_R |= 0x020000; // wait certain time for ADC module do the conversion Delay(100); while (1) { } }