Hi, everyone, fine?
I know that this forum is not about Stellaris, but the one which would help no longer exists. Thus, sorry for that.
Could anyone please help me along with a LM3S3748 program ?
I've been trying hard to get some samples using its ADC block and have failed in doing so. I'm just using one channel (CH5) to sample a small DC signal (less than 3 V). The program is supposed to get this signal (a 10-bit value from the FIFO) and compare it with a predetermined value to activate a blinky Led depending on whether the comparison is true or not. The program is very simple (just to test the channel) but it's not working.
I have the Evaluation Board powered up directly from the PC by the USB debugger power input (with SW3 key in SELF position).
Could anyone point out the problem?
Thanks so much in advance.
That's the program:
#include "inc/lm3s3748.h"
#include "driverlib/adc.h"
#include "inc/hw_types.h"
#include "inc/hw_memmap.h"
#include "driverlib/interrupt.h"
#include "driverlib/sysctl.h"
#include "inc/hw_ints.h"
#include "driverlib/gpio.c"
void int_handler(void); // Prototype of int_handler() function.
int main (void)
{
//---------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------//
// Enables ADC clock and set the sample rate.
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
SysCtlADCSpeedSet(SYSCTL_ADCSPEED_125KSPS);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
// Initialize peripheral D - pin 6- to be an ADC analog input.
GPIOPinTypeADC(GPIO_PORTD_BASE, GPIO_PIN_6);
// Enable the fourth sample sequence to capture the value of channel 0 when
// the processor trigger occurs.
ADCSequenceDisable(ADC0_BASE, 3);
ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_ALWAYS, 0);
ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_IE | ADC_CTL_END | ADC_CTL_CH5);
ADCSequenceEnable(ADC0_BASE, 3);
// Trigger the sample sequence.
// ADCProcessorTrigger(ADC0_BASE, 1);
ADCIntRegister(ADC0_BASE, 3, int_handler); //Register int_handler () for ADC0_BASE seq. 1 and ativates interruptions general key.
ADCIntEnable(ADC0_BASE, 3); //Activates interruption for the ADC0_BASE, sequence 1.
IntEnable(INT_ADC0);
for(;;){} // infinite loop. Just wait until the interrupt occurs.
// while(1){} // infinite loop. Just wait until the interrupt occurs
// return (0);
}// End of funtion main().
//-----------------------------------------------------------------------------------------------//
//Interruption treatment
void int_handler(void)
{
volatile unsigned long ulLoop;
unsigned long ulvalue = 0;
unsigned long lSampleCount = 0;
//
// Enable the GPIO port that is used for the on-board LED.
//
SYSCTL_RCGC2_R = SYSCTL_RCGC2_GPIOF;
//
// Do a dummy read to insert a few cycles after enabling the peripheral.
//
ulLoop = SYSCTL_RCGC2_R;
//
// Enable the GPIO pin for the LED (PF0). Set the direction as output, and
// enable the GPIO pin for digital function.
//
GPIO_PORTF_DIR_R = 0x01;
GPIO_PORTF_DEN_R = 0x01;
ADCIntClear(ADC0_BASE, 3);// Clear ADC interrupt register.
// Wait a moment until Int buffer is clear
for(ulLoop = 0; ulLoop < 200000; ulLoop++)
{
}
// Get data from the FIFO
ADCSequenceDataGet(ADC0_BASE, 3, &ulvalue);
ulvalue = ulvalue & 0x000003FF;
if (ulvalue<=0x00000100)
{
//
// Turn on the LED.
//
GPIO_PORTF_DATA_R |= 0x01;
//
// Delay for a bit.
//
for(ulLoop = 0; ulLoop < 200000; ulLoop++)
{
}
//
// Turn off the LED.
//
GPIO_PORTF_DATA_R &= ~(0x01);
//
// Delay for a bit.
//
for(ulLoop = 0; ulLoop < 200000; ulLoop++)
{
}
}
}