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.

TM4C1294NCPDT: ADC conversion without CMSIS library

Part Number: TM4C1294NCPDT
Other Parts Discussed in Thread: TM4C1294NCPDT, EK-TM4C1294XL

Dear TI community.

I am trying to make a program in which the ADC converter performs a conversion and the result is stored in a variable.

This without the CMSIS library, to increase my knowledge about the microcontroller.

I have read the ADC chapter and section 15.4 even provides a step-by-step plan to configure the different registers.

However, my program seems fine, but when debugging it gets stuck at waiting for the conversion to be done (line 49 in the code).

Does anyone know what I am missing/doing wrong? I have followed all steps in the datasheet 4 times and without succes. The code is  

The code even contains comments with steps that refer to section 15.4 in the datasheet.

Please help! I put already enough of my time in this and can't let it go.

EDIT:

Here is the source code again.

#define GPIO_CGC_R                  (*((volatile unsigned long *) 0x400FE608))
#define ADC_CGC_R                   (*((volatile unsigned long *) 0x400FE638))

#define GPIO_PORTE_DIR_R            (*((volatile unsigned long *) 0x4005C400))
#define GPIO_PORTE_AFSEL_R          (*((volatile unsigned long *) 0x4005C420))
#define GPIO_PORTE_DEN_R            (*((volatile unsigned long *) 0x4005C51C))
#define GPIO_PORTE_AMSEL_R          (*((volatile unsigned long *) 0x4005C528))

#define ADCPC_R                     (*((volatile unsigned long *) 0x40038FC4))
#define ADCSSPRI_R                  (*((volatile unsigned long *) 0x40038020))
#define ADCACTSS_R                  (*((volatile unsigned long *) 0x40038000))
#define ADCEMUX_R                   (*((volatile unsigned long *) 0x40038014))
#define ADCSSMUX3_R                 (*((volatile unsigned long *) 0x400380A0))
#define ADCSSCTL3_R                 (*((volatile unsigned long *) 0x400380A4))
#define ADCIM_R                     (*((volatile unsigned long *) 0x40038008))

#define ADCPSSI_R                   (*((volatile unsigned long *) 0x40038028))
#define ADCRIS_R                    (*((volatile unsigned long *) 0x40038004))
#define ADCSSFIFO3_R                (*((volatile unsigned long *) 0x400380A8))
#define ADCISC_R                    (*((volatile unsigned long *) 0x4003800C))


#include <stdint.h>

static uint16_t result;


int main(void)
{
    GPIO_CGC_R |= 0x10;                 /* Enable the GPIO port E module. This is step 1 of module init. */

    GPIO_PORTE_DIR_R &= ~0x10;          /* Direction is an input pin. */
    GPIO_PORTE_AFSEL_R |= 0x10;         /* Use an alternative function. This is step 3 of module init.*/
    GPIO_PORTE_DEN_R &= ~0x10;          /* This pin is not a digital pin. This is step 4 of module init.*/
    GPIO_PORTE_AMSEL_R |= 0x10;         /* This pin is an analog pin. This is step 5 of module init. */

    ADC_CGC_R = 0x01;                   /* Enable the ADC0 module. This is step 2 of module init.*/
    ADCSSPRI_R = 0x0123;                /* Change the priority of the different sequencers.*/
    ADCACTSS_R &= ~0x0008;              /* Disable sample sequencer 3 during configuration. This is step 1 of SS config.*/
    ADCEMUX_R &= ~0xF000;               /* Sequence 3 is software trigger. This is step 2 of SS config.*/
    ADCSSMUX3_R = (ADCSSMUX3_R & 0xFFFFFFF0) + 9; /* Use AIN9 (PE4) as input. ADCSSEMUX3 is already 0. This is step 4 of SS config. */
    ADCSSCTL3_R = 0x0006;               /* No TS0, D0. Yes IE0 and END0. This is step 5 of SS config.*/
    ADCIM_R &= ~0x0008;                 /* Disable Sampler Sequencer 3 (SS3) interrupts. This is step 6 of SS config.*/
    ADCACTSS_R |= 0x0008;               /* Enable SS3. This is step 7 in SS config. */

    while(1)
    {
        ADCPSSI_R = 0x0008;             /* Initiate SS3. */
        while((ADCRIS_R & 0x0008) == 0) {}  /* Wait for the conversion to be done. */
        result = ADCSSFIFO3_R & 0xFFF;  /* Read the 12 bit result. */
        ADCISC_R = 0x0008;              /* Acknowledge completion. */
    }

	return 0;
}

  • Hello Jan,

    We cannot see your code, can you please post it on E2E via the Insert Code, Attach Files and more... feature at the bottom right of the posting box. Clicking that brings up the Rich Text Editor, and you should use the symbol that looks like "</>" to bring up a dialog box where you can paste in your code.

    Regarding the ADC in general, have you looked at TivaWare ADC peripheral examples yet? Are you using TivaWare at all for this? TivaWare should be able to do all the configuration without you needing to reply on the datasheet so much.
  • Dear Ralph Jacobi.

    That is weird. If I press on the big CPP icon in my first post, I am able to view the source code.
    I have edited my original post so you can download the file now to your computer.

    As I said before, I am using no CMSIS library. This means that I do not use the TivaWare library.
    This has a specific reason, namely getting practise with reading a datasheet and produce code.

    I have literarry followed the steps that the datasheet said to do in order to get the ADC working.
    I get stuck at line 49, the while loop waiting for the conversion to be done. The flag indicating completion never gets set.

    I'd appreciate if you take a look at my code and the datasheet and can tell me what I am missing/doing wrong.
    I have put lots of time in it to produce this code, and it isn't working.
  • Hello Jan,

    Per our forum guidelnes, we do not support direct register programming - only TivaWare, see Point 4: e2e.ti.com/.../695568

    You don't need to use CMSIS if you use TivaWare, they are completely separate.

    TivaWare handles all this configuration for you, that is why it was made. If you want to get practice, that is how you should do it, all our customers should use TivaWare.
  • Dear Ralph,

    Can you point me to some ADC examples that makes use of the TivaWare library?
    If I go to the Resource explorer within Code composer and search for the "EK-TM4C1294XL", I do not see any examples that programs the ADC.
    I'd like to get an example that uses the internal PIOSC as clock source.
  • Hello Jan,

    First off I would recommend to download TivaWare from: http://www.ti.com/tool/SW-TM4C

    Resource Explorer is not very helpful for what you are looking for as our ADC examples are kept very generic as the ADC has too many uses to narrow it down like other peripherals, but Resource Explorer doesn't have a good way to reflect this.

    In TivaWare, we have a folder inside of the examples folder called 'Peripherals' and this is where our ADC examples reside.

    We don't have an example which uses the PIOSC as the ADC clock, but this is the API you need to use to achieve this (you need to make sure the ADC base matches your desired ADC, this example is for ADC0):

    ADCClockConfigSet(ADC0_BASE, ADC_CLOCK_SRC_PIOSC |ADC_CLOCK_RATE_FULL, 1);

  • Dear Ralph,

    This may seem as a stupid question, but if I try to download the complete TivaWare, I come at a page
    where most of the files are .exe files (software-dl.ti.com/.../index_FDS.html).
    I using the GNU/Linux operating. Is it possible to download a .zip file or anything like that?
  • Hello Jan,

    I see, in that case you can download it through the online TI REX, it should come as a .zip file for Linux.

    The link you can go to is: dev.ti.com/.../

    Look for the Download All option for "TM4C ARM® Cortex®-M4F MCU"
  • Dear Ralph,

    Thank you very much. I have got the source code of the TivaWare now.