This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/EK-TM4C1294XL: ADC initialization problem

Part Number: EK-TM4C1294XL

Tool/software: Code Composer Studio

I have to make a program for the ADC from the TIVA, but I can't use libraries other than stdbool and stdint. Here's my code, and when I try to debug it, it stucks when I want to check if the conversion has finished.
The program is intended for using the temperature Sensor in the Microprocessor.

#include <stdbool.h>
#include <stdint.h>

#define SYSCTL_RCGCGPIO_R       (*((volatile uint32_t *)0x400FE608)) 
#define SYSCTL_PRGPIO_R         (*((volatile uint32_t *)0x400FEA08)) 
#define SYSCTL_RCGCADC_R        (*((volatile uint32_t *)0x400FE638)) 
#define SYSCTL_PRADC_R          (*((volatile uint32_t *)0x400FEA38))

#define ADC0_PC_R               (*((volatile uint32_t *)0x40038FC4))
#define ADC0_SSPRI_R            (*((volatile uint32_t *)0x40038020))
#define ADC0_ACTSS_R            (*((volatile uint32_t *)0x40038000))
#define ADC0_EMUX_R             (*((volatile uint32_t *)0x40038014))
#define ADC0_SSEMUX3_R          (*((volatile uint32_t *)0x400380B8))
#define ADC0_SSMUX3_R           (*((volatile uint32_t *)0x400380A0))
#define ADC0_SSCTL3_R           (*((volatile uint32_t *)0x400380A4))
#define ADC0_IM_R               (*((volatile uint32_t *)0x40038008))
#define ADC0_ACTSS_R            (*((volatile uint32_t *)0x40038000))
#define ADC0_ISC_R              (*((volatile uint32_t *)0x4003800C))
#define ADC0_PSSI_R             (*((volatile uint32_t *)0x40038028))
#define ADC0_RIS_R              (*((volatile uint32_t *)0x40038004))
#define ADC0_SSFIFO3_R          (*((volatile uint32_t *)0x400380A8))


void main(void){
    SYSCTL_RCGCADC_R  = 0x01;   // Clock Enable for ADC
    while((SYSCTL_PRADC_R&0x01)==0); // Delay for the clock enable

    ADC0_PC_R = 0x01;       // 125Ksamp/s
    ADC0_SSPRI_R = 0x0123;  // SS3 with the top priority
    ADC0_ACTSS_R = 0x0000;  // Disables SS3 before the configuration
    ADC0_EMUX_R = 0x0000;   // Software enable for the sampling
    ADC0_SSEMUX3_R = 0x00;  // Pins AIn(15:0)
    ADC0_SSMUX3_R = (ADC0_SSMUX3_R & 0xFFFFFFF0) + 9; // AIN9 Channel
    ADC0_SSCTL3_R = 0x000E; // Enabling the Temperature Sensor, INR3 Enable, End Sequence; No diferencial mode
    ADC0_IM_R = 0x0000;     // Disables SS3 interruptions
    ADC0_ACTSS_R |= 0x0008; // Enables SS3

    ADC0_ISC_R = 0x0008;//Clears Flags
    while{
      uint32_t adc_result;
      float TEMP;
      ADC0_PSSI_R = 0x0008;             // Starts Conversion
      while ((ADC0_RIS_R & 0x08)==0);   // ALWAYS STUCK HERE
      adc_result = (ADC0_SSFIFO3_R & 0xFFF);// Saves the conversion result to adc_result
      ADC0_ISC_R = 0x0008;              // Clears flags

      TEMP = 147.5 - ((75 * (3.3) * adc_result)/ 4096);
        }
}
  • Hi,
    You are using the DRM which is not recommended. Since you do not use the TivaWare libary, it makes it hard to debug. I think you want to go to CCS Register browser window and watch if all the registers (i.e. if the SS3 is enabled or not) are properly configured according to the datasheet.
  • Agree 100% with vendor's Charles - DRM is (one) method - but proves extremely inefficient, wasteful of time - and most always, "Fails to Work!" Yet somehow - certain "instructors" claim that this "Aids Learning!"

    You may ask the instructor if, "Coming (very) late to market - always the result of such DRM (only) usage - insures student "hiring?" As successful small tech biz owner (co-founded - took past tech firm Public) - we would NOT allow you to use DRM!      (that view is shared by all other tech firms with which we interact)

    In stark contrast - vendor's "Tried, True, Expansive API" best enables our firm - and multiple others - to, "Keep our doors OPEN!"     And "that" is by far - the most critical LEARNING!

  • user4904668 said:
    but I can't use libraries other than stdbool and stdint

    In that case, you need to complain to whoever imposed you that directive. He is the one throwing you to flames, hence he is the one who must help figuring out why your code does not work.

    PS: You can tell that person that "The Engineers are telling you to use driver libraries!"

    For this particular device, such driver library is called TivaWare.

  • cb1_mobile said:
    certain "instructors"

    Risking endorsement to the saying "Those who can't do teach"... - not that I particularly agree to it.

  • Some - (but never moi) - (may) have noted, "Job Security" as prime motivator for blocking their charges from searching for, finding, and then (effectively) utilizing "best practice" methods, techniques & LONG PROVEN Tech AIDS/SPEEDUPS!

    Adding endless MCU manual, "Page Cranking & "Deep Dive" Register exam" - while "COMPLETELY AVOIDING" the TRIED/TRUE API - makes NO SENSE - either here or w/in the "real-world!"

    It is entirely possible to employ the API (WHILE) examining MCU Registers - and w/key Register Pages printed out - ready - to speed/ease student learning.      Yet - never is this "hybrid technique" mentioned. (Never has appeared here)

    As small tech biz owner we must ALWAYS "Examine our methods - what works - fails - can be done more efficiently?"     This leads (necessarily) to CHANGE!      Thus highlights the obvious question - "Has the course syllabus (likewise) changed, kept up, sought to maximize student value?"     And if not - why not?

    Surely it makes BEST SENSE for "instructors" to migrate their teachings to the BEST/PROPER BLEND of BOTH METHODS!       (Why does this SO OBVIOUS A SUGGESTION ORIGINATE "OUTSIDE" ACADEMIA?)