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.

Code worked the first time after that debug error!

Other Parts Discussed in Thread: TM4C1294NCPDT

#include <stdint.h>
#include "tm4c1294ncpdt.h"


#define ADC0_SSMUX_AIN 0x0067CDEF    // AIN6,7,12,13,14,15

/*
 * main.c
 */
int main(void) {
	

	int dummy;
	// ADC init
	SYSCTL_RCGCADC_R |= SYSCTL_RCGCADC_R0;				// clock for adc0
	dummy = SYSCTL_RCGCGPIO_R3;
	SYSCTL_RCGCGPIO_R |= SYSCTL_RCGCGPIO_R3;			// clock for portD
	dummy = SYSCTL_RCGCGPIO_R3;

	GPIO_PORTD_DIR_R &= 0x0;							// making it input
	GPIO_PORTD_AFSEL_R |= 0x3F;							// Alternate function enabled for PD_0123456
	GPIO_PORTD_DEN_R &= 0x00;							// Analog pins
	GPIO_PORTD_AMSEL_R |= 0x3F;							// Analog isolation disabled

	// SS config
	ADC0_ACTSS_R &= ~(ADC_ACTSS_ASEN0);  				// DISABLE SS0
	ADC0_EMUX_R |= ADC_EMUX_EM0_ALWAYS;					// always trigger
	ADC0_SSMUX0_R |= ADC0_SSMUX_AIN; 					// input analog pins
	ADC0_IM_R &= 0X0;							// dont send to interrupt controller
	ADC0_SSCTL0_R |= (ADC_SSCTL0_END5 | ADC_SSCTL0_IE5);// end bit set for sample 6 and interrupt enabled
	ADC0_ACTSS_R &= ADC_ACTSS_ASEN0;  					// ENABLE SS0

	// reading the value
	int adcValues[6];
	while(1)
	{
	ADC0_PSSI_R = ADC_PSSI_SS0;							// initiate sampling
	while( (ADC0_RIS_R&0x01) == 0) {};					// Wait for conversion done ( When done RIS = 1 )
	adcValues[0] = ADC0_SSFIFO0_R&0xFFF;						// read result
	adcValues[1] = ADC0_SSFIFO0_R&0xFFF;
	adcValues[2] = ADC0_SSFIFO0_R&0xFFF;
	adcValues[3] = ADC0_SSFIFO0_R&0xFFF;
	adcValues[4] = ADC0_SSFIFO0_R&0xFFF;
	adcValues[5] = ADC0_SSFIFO0_R&0xFFF;
	ADC0_ISC_R = 0x1;									// Acknowledge (Clear RIS)
	}
	//

	return 0;
}


tm4c1294ncpdt.hHey,

I'm using TM4C1294 and was trying to configure 6 ADC channels, my code was working the first time I ran it but wasn't reading the values, so I just unmasked the ADCIM bit and after that it has totally stopped working even after reverting back to the previous code. I've tried everything but still no success, can please someone help me find the problem? I've attached the screen shot along with my code.

Thanks for the help and time.

P.S. I just changed this line before it stopped working

ADC0_IM_R &= 0X0;

to

ADC0_IM_R = 0X01;

  • Hello Arsalan

    Please avoid using the DRM method and instead use the TivaWare API's. It will help us debug the code better.

    In the current code when the IM bit is set the interrupt to the CPU gets generated. Do you want to use the interrupt status or the interrupt handler to read the data?

    Regards
    Amit
  • Hello Arsalan,

    Looking at the screen snapshot it is evident that the ADC0 clock has not been enabled after the new program has been loaded. Also you have not run the code yet and that is why it may be showing the error.

    Also there is no address space defined for 0x20086008. Please check the cmd file for the project

    Regards
    Amit
  • I'm new to TivaWare API, but I'll surely give it a try. I'm looking to just use the interrupt status to read and not the handler that's why I reset the bit to 0 again but the code wouldn't work.
  • Hello Arsalan,

    You can use the existing example in TivaWare path to jumpstart the development.

    D:\ti\TivaWare_C_Series-2.1.1.71\examples\peripherals\adc

    Regards
    Amit
  • Ok I did manage to get the ADC working, initially I thought the ADC is giving me the correct values but after a while I noticed that the values in the array often get exchanged with each other or sometimes repeat , for example I have 1 pin at Vcc while 3 at ground but still some times 2 of the values come out to be maximum i.e. 4095? This happens after I repeatedly start and stop the debugging process. I've no clue why the ADC is behaving this way.

    Also I noticed that when I'm reading the values, inside the ADCSequenceDataGet() function the number of samples read (i.e. ui32Count) increments to 8 before restarting, where as I'm only using 4 steps? Shouldn't this restart after counting till 4, when the IE bit would be set? May be I haven't configured my ADC properly. I've attached the my code below.

    Thanks for your help again.

    adc3.cpp

  • Hello Arsalan

    Your new post has some questions to be answered...

    e2e.ti.com/.../458387

    Regards
    Amit