Tool/software: Code Composer Studio
Good day everyone,
The code below should Set the led when the result of the ADC is more than 2048, but the problem is the code stuck at this line READBIT(ADC1->RIS,3) and the BUSY bit in ADCACTSS register is always on after initialing the SS3 bit in the ADCPSSI register.
So why is that happening ?
#include "GPIO.h"
#include "ADC.h"
uint16_t result = 5;
int main(void){
GPIO_c LED(PORTN,1,GPIO_OUTPUT_MODE);
GPIO_n::SetSysClock(PORTE); /* enable clock to GPIOE (AIN0 is on PE3) */
ADC_n::SetSysClock(ADC1_MODULE); /* enable clock to ADC1 */
for(int i = 0;i<1200;i++); // delay
/* initialize ADC1 */
ADC1->ACTSS &= ~8; /* disable SS3 during configuration */
/* initialize PE3 for AIN0 input */
GPIOE->AFSEL |= 0x8; /* enable alternate function */
GPIOE->DEN &= ~0x8; /* disable digital function */
GPIOE->AMSEL |= 0x8; /* enable analog function */
ADC1->SSPRI=0x123; // priority
ADC1->EMUX &= ~0xF000; /* software trigger conversion */
ADC1->SSMUX3 = 0x0; /* get input from channel 0 */
ADC1->SSCTL3 |= 0x6; /* take one sample at a time, set flag at 1st sample */
ADC1->ACTSS |= 0x8; /* enable ADC1 sequencer 3 */
ADC1->ISC |= 0x8;
while(1)
{
if(result >2048)
{
LED.Clear();
}
else{
LED.Set();
}
ADC1->PSSI |= 0x8; /* start a conversion sequence 3 */
while(READBIT(ADC1->RIS,3) == 0) ; /* wait for conversion complete */
result = ADC1->SSFIFO3; /* read conversion result */
ADC1->ISC |= 0x8; /* clear completion flag */
}