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.

ADC with Interrupts

I have written this code to sample a potentiometer with Pin E1 using ADC1 with sequencer 3
I used IAR Embedded Workbench IDE

The program works fine in the debugger mode but not in the normal after I reset.

I used CMSIS

The code for main.c

/***********************************************************************

#include <LM4F120H5QR.h>

volatile static uint32_t adcResult = 0;

void ADC1SS3_Handler(void)
{
adcResult = ADC1->SSFIFO3;
ADC1->ISC = (1<<3);
}

int main()
{
SYSCTL->RCGCADC |= (1<<1);
SYSCTL->RCGCGPIO |= (1<<4);
SYSCTL->RCGCGPIO |= (1<<5);

GPIOF->DEN |= (7<<1);
GPIOF->AFSEL &= ~(7<<1);
GPIOF->AMSEL &= ~(7<<1);
GPIOF->DIR |= (7<<1);

GPIOE->DIR |= (1<<1);
GPIOE->AFSEL |= (1<<1);
GPIOE->AMSEL |= (1<<1);
GPIOE->DEN &= ~(1<<1);


ADC1->ACTSS &= ~(1<<3);
for(long x = 800000; x > 0; x--){} GPIOF->DATA &= ~(1<<1);
ADC1->EMUX = (0xF << 12);
for(long x = 800000; x > 0; x--){}GPIOF->DATA |= (1<<1);
ADC1->SSMUX3 = 2;
for(long x = 800000; x > 0; x--){}GPIOF->DATA &= ~(7<<1);
ADC1->SSCTL3 = 0x6;
for(long x = 800000; x > 0; x--){}GPIOF->DATA |= (1<<2);
ADC1->IM = (1<<3);
for(long x = 800000; x > 0; x--){}GPIOF->DATA &= ~(7<<1);
ADC1->ACTSS |= (1<<3);
for(long x = 800000; x > 0; x--){}GPIOF->DATA |= (1<<3);
ADC1->ISC = (1<<3);
for(long x = 800000; x > 0; x--){}GPIOF->DATA &= ~(7<<1);
NVIC->ISER[1] |= (1<<19);
for(long x = 800000; x > 0; x--){}GPIOF->DATA |= (1<<1);

for(long x = 800000; x > 0; x--){}


while(1)
{
if(adcResult > 2047)
{
GPIOF->DATA |= (1<<1);
}
else
{
GPIOF->DATA &= ~(1<<1);
}
}
return 0;
}

*******************************************************************************/

code for cstartup_M.c

/*******************************************************************************

/**************************************************
*
* This file contains an interrupt vector for Cortex-M written in C.
* The actual interrupt functions must be provided by the application developer.
*
* Copyright 2007 IAR Systems. All rights reserved.
*
* $Revision: 66254 $
*
**************************************************/

#pragma language=extended
#pragma segment="CSTACK"

extern void __iar_program_start( void );

extern void NMI_Handler( void );
extern void HardFault_Handler( void );
extern void MemManage_Handler( void );
extern void BusFault_Handler( void );
extern void UsageFault_Handler( void );
extern void SVC_Handler( void );
extern void DebugMon_Handler( void );
extern void PendSV_Handler( void );
extern void SysTick_Handler( void );

extern void ADC1SS3_Handler( void);

typedef void( *intfunc )( void );
typedef union { intfunc __fun; void * __ptr; } intvec_elem;

#pragma location = ".intvec"

const intvec_elem __vector_table[] =
{
{ .__ptr = __sfe( "CSTACK" ) },
__iar_program_start,

NMI_Handler,
HardFault_Handler,
MemManage_Handler,
BusFault_Handler,
UsageFault_Handler,
0,
0,
0,
0,
SVC_Handler,
DebugMon_Handler,
0,
PendSV_Handler,
SysTick_Handler,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
ADC1SS3_Handler
};

#pragma call_graph_root = "interrupt"
__weak void NMI_Handler( void ) { while (1) {} }
#pragma call_graph_root = "interrupt"
__weak void HardFault_Handler( void ) { while (1) {} }
#pragma call_graph_root = "interrupt"
__weak void MemManage_Handler( void ) { while (1) {} }
#pragma call_graph_root = "interrupt"
__weak void BusFault_Handler( void ) { while (1) {} }
#pragma call_graph_root = "interrupt"
__weak void UsageFault_Handler( void ) { while (1) {} }
#pragma call_graph_root = "interrupt"
__weak void SVC_Handler( void ) { while (1) {} }
#pragma call_graph_root = "interrupt"
__weak void DebugMon_Handler( void ) { while (1) {} }
#pragma call_graph_root = "interrupt"
__weak void PendSV_Handler( void ) { while (1) {} }
#pragma call_graph_root = "interrupt"
__weak void SysTick_Handler( void ) { while (1) {} }
#pragma call_graph_root = "interrupt"
__weak void ADC1SS3_Handler( void ) { while (1) {} }

void __cmain( void );
__weak void __iar_init_core( void );
__weak void __iar_init_vfp( void );

#pragma required=__vector_table
void __iar_program_start( void )
{
__iar_init_core();
__iar_init_vfp();
__cmain();
}

**************************************************/

  • Hello Abdel,

    Where is the image being loaded: SRAM or Flash. To check the load location, check if the code when loaded, shows that the PC is in a location like 0x200xxxxxx or 0x00xxxxxx.

    Regards
    Amit
  • Would it not prove helpful if you reported any past successes with your MCU board and your use under IAR?   (no such history has been supplied - most always proves of value.)

    We know little of your past MCU experience - perhaps a far shorter - less involved program (such as blinky) will serve as an easier diagnostic tool.

    Always best to "prove your board AND your methods" via short, simple program.   Adding complexity (usually) "gets in the way."