Hi, i'm trying to read an analog value from AIN0 = PE3, but the adc module after start the trigger is stuck with busy pin active. I followed the instructions on the microprocessor datasheet, without using the driverlib.
#include <stdint.h>
#include <stdio.h>
#include "tm4c1294ncpdt.h"
#include <TM4C1294NCPDT.H>
#include "delay.h"
void UART0_puts(char* s);
void UART0Tx(char c);
int main(){
SYSCTL_RCGCGPIO_R |= (1U << 8); /*enable cock for GPIOJ*/
SYSCTL_RCGCGPIO_R |= (1U << 12); /*enable clock for GPION*/
SYSCTL_RCGCGPIO_R |= (1U << 0); /*enable clock for GPIOA*/
SYSCTL_RCGCADC_R |= (1U << 0); /*enable clock for ADC0*/
SYSCTL_RCGCGPIO_R |= (1U << 4); /*enable clock for GPIOE*/
SYSCTL_RCGCUART_R |= (1U << 0); /*enable clock for UART_0*/
delay(100);
/*UART_0 initialization*/
UART0_CTL_R |= 0x00; /*disable UART_0*/
UART0_IBRD_R = 104; /*16MHz/16=1MHz, 1MHz/104=9600 baudrate*/
UART0_FBRD_R = 11; /*fraction part*/
UART0_CC_R |= 0x0; /*use system clock*/
UART0_LCRH_R |= 0x60; /*8-bit, no parity, 1-stop bit, no FIFO*/
UART0_CTL_R |= 0x301; /*enable UART_0, TXE, RXE */
/*enable PA0, PA1 for UART use*/
GPIO_PORTA_AHB_DEN_R |= 0x03; /*make PA1 and PA0 as digital*/
GPIO_PORTA_AHB_AFSEL_R |= 0x03; /*use PA0 PA1 alternate function*/
GPIO_PORTA_AHB_PCTL_R |= 0x11; /*configure PA0 and PA1 for UART*/
/*initialize PE3 for AIN0 input*/
GPIO_PORTE_AHB_AFSEL_R |= 0x08U; /*enable alternate function*/
GPIO_PORTE_AHB_DEN_R &= ~0x08U; /*disable digital function*/
GPIO_PORTE_AHB_AMSEL_R |= 0x08U; /*enable analog function*/
/*initialize ADC0*/
ADC0_ACTSS_R &= ~0x08U; /*disable SS3 during configuration*/
ADC0_EMUX_R &= ~0xF000U; /*software trigger conversion*/
ADC0_SSMUX3_R = 0; /*get input from channel 0*/
ADC0_SSEMUX3_R &= ~0x01U;
ADC0_SSCTL0_R |= 0x02;
ADC0_SSCTL3_R |= 0x06U; /*take 1 saple at the time set flag 1st sample*/
ADC0_ACTSS_R = 0x08U; /*enable ADC0 sequencer*/
volatile int result;
int temperature;
char buffer[16];
while(1){
ADC0_PSSI_R |= 0X08U;
while((ADC0_RIS_R & 0x08U)==0); // -> ALWAYS STUCK HERE
temperature = (ADC0_SSFIFO3_R - 500)/10;
ADC0_ISC_R = 0x08U;
sprintf(buffer, "\r\nTemp = %dC" , temperature);
UART0_puts(buffer);
delay(100000);
}
return 0;
}
void UART0Tx(char c){
while((UART0_FR_R & (1 << 5)) != 0);
UART0_DR_R = c;
}
void UART0_puts(char* s){
while(*s != 0)
UART0Tx(*s++);
}
the program remains locked in while loop and the register ADC0ACTSS remains with the Busy bit high.
I'm working on it for two days, but i can't find a solution, thanks in advance for your support.