ADC的问题,不知道是不是9B96的问题还是我程序的问题。
void adc1Init(void)
{
// SysCtlPeripheralEnable(GPIO_PORTB_BASE);
//GPIOPinTypeADC(GPIO_PORTB_BASE,GPIO_PIN_4 );
ADCSequenceDisable(ADC1_BASE,3); // 配置前先禁止采样序列
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC1); // 使能ADC模块
SysCtlADCSpeedSet(SYSCTL_ADCSPEED_1MSPS); // 设置ADC采样速率
// 采样序列配置:ADC基址,采样序列编号,触发事件,采样优先级
ADCSequenceConfigure(ADC1_BASE, 0, ADC_TRIGGER_PROCESSOR, 1);
// 采样步进设置:ADC基址,采样序列编号,步值,通道设置
ADCSequenceStepConfigure(ADC1_BASE, 3, 0, ADC_CTL_TS |
ADC_CTL_END |
ADC_CTL_IE ) ;
ADCReferenceSet(ADC1_BASE,ADC_REF_INT);
ADCResolutionSet(ADC1_BASE,ADC_RES_10BIT) ;
ADCIntClear(ADC1_BASE, 3);
ADCSequenceEnable(ADC1_BASE, 3); // 使能采样序列
ADCIntEnable(ADC1_BASE, 3); // 使能ADC中断
IntEnable(INT_ADC1SS3) ; // 使能ADC采样序列中断
IntMasterEnable() ; // 使能处理器中断
}
在DKLM3S9B96上跑的。换ADC0就能工作,换ADC1就不能工作。调用这个初始化函数,程序就会死在里面。何解?中断向量也注册了
参考例程如下:
//*****************************************************************************
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/gpio.h"
#include "driverlib/interrupt.h"
#include "driverlib/sysctl.h"
#include "driverlib/adc.h"
#include "driverlib/timer.h"
#include "utils/ustdlib.h"
#include "utils/uartstdio.h"
#include "driverlib/sysctl.h"
#include "driverlib/systick.h"
#include "utils/cmdline.h"
void Delay(unsigned long count )
{
unsigned i,j;
for(i=0;i<count;i++)
{for(j=0;j<count;j++) ; }
}
int iADC0_read=1; // Indicates if the ADC is ready (1) or busy (0)
unsigned long ulBlinkSpeed = 0; // Timer interrupt frequency (0=low; 1=high)
//************ User Defines ************
//
// 12-bit resolution bit
//
//#define ADC_RES_12BIT 0x10
//
// Offset for ADC control register
//
#define ADC_O_CTL 0x38
//*****************************************************************************
// Interrupt handler for the Timer0 interrupt
//*****************************************************************************
void Timer0IntHandler(void)
{
unsigned long ulPinStatus;
// Clear the timer interrupt.
TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
// Read the current state of the output
ulPinStatus = GPIOPinRead(GPIO_PORTD_BASE, GPIO_PIN_0);
// Toggle Bit 0
ulPinStatus ^= GPIO_PIN_0;
// Write the result back into the GPIO Pin 0 Data Register
GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_0, ulPinStatus);
// Check if the ADC is ready
if (iADC0_read == 1)
{
// Trigger new ADC Conversion using Sample Sequencer 0
ADCProcessorTrigger(ADC1_BASE,2);
// Indicate that the ADC is busy
iADC0_read = 0;
}
}
//*****************************************************************************
// Interrupt handler for the ADC Sample Sequencer 2 (SS2) interrupt
//*****************************************************************************
void ADC2IntHandler(void)
{
unsigned long adc0Value[4]={0,0,0,0}; // Holds the ADC result
char adc0String[4]; // Holds the string-converted ADC result
unsigned long InputVoltage; //Input voltage
// Clear the ADC0 interrupt.
ADCIntClear(ADC1_BASE,2);
// Read the data from the Result Buffer of ADC SS2
// We know that we have only one result in the buffer
// If we have more than one result then adc0_value must be an array
ADCSequenceDataGet(ADC1_BASE, 2,adc0Value);
//ADC AT 12 BIT MODE,PLEASE REFER TO ADC CONVERSION VALUE Y=1352X+28 =>INPUT VOLTAGE VALUE X=((Y-28)/1352)*1000(MV)
InputVoltage= (adc0Value[0]-28/1352)*1000;
// Delay(6553000);
//adc0Value[1]=((1475 * 1023) - (2250 * adc0Value[1])) / 10230; //centigrade temperature
IntMasterDisable();
UARTprintf("\n%d",adc0Value[0]);
UARTprintf("\n%d",adc0Value[1]);
//UARTprintf("\n%d",adc0Value[2]);
//UARTprintf("\n%d",adc0Value[3]);
// Disable interrupts globally to ensure we don't interrupt communication with the display
//IntMasterDisable();
iADC0_read = 1;
// while(1);
// Re-enable interrupts globally
IntMasterEnable();
}
int main(void)
{
//*****************************************************************************
// Clock Setup
//*****************************************************************************
// Set the clocking to run directly from the crystal.
SysCtlClockSet(SYSCTL_SYSDIV_4| SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
// Enable Timer 0, ADC0 and GPIO Block D Peripheral Clocks
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC1);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
//LED on PD0
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
// Reset the state of Peripheral ADC0
//
//SysCtlPeripheralReset(SYSCTL_PERIPH_ADC0);
//
// Setup the AIN0 on PE7 ...
//
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3);
//GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_6);
//GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_5);
// GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_4);
// Enable the peripherals used by this example.
//
IntMasterDisable();
//
// Set GPIO A0 and A1 as UART.
//
GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
//
// Initialize the UART as a console for text I/O.
//
UARTStdioInit(0);
//
// Print hello message to user.
//
UARTprintf("\n\nADC Test Example Program\n");
//*****************************************************************************
// GPIO Setup
//*****************************************************************************
// Set GPIO_F, pin 0 as output (used for the LED)
GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, GPIO_PIN_0);
// Disable processor interrupts
IntMasterDisable();
//*****************************************************************************
// Timer 0 Setup
//*****************************************************************************
// Configure Timer0 as 32-bit periodic timer
TimerConfigure(TIMER0_BASE, TIMER_CFG_32_BIT_PER);
// Set Timer0 period as 1/4 of the system clock, i.e. 4 interrupts per second
TimerLoadSet(TIMER0_BASE, TIMER_A, SysCtlClockGet() /4);
// Configure the timer to generate an interrupt on time-out
TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
// Enable the TImer Interrupt in the NVIC
IntEnable(INT_TIMER0A);
// Enable the timer
TimerEnable(TIMER0_BASE, TIMER_A);
//
// Set 12-bit resolution
//
HWREG(ADC1_BASE + ADC_O_CTL) = HWREG(ADC1_BASE + ADC_O_CTL)| ADC_RES_12BIT;
//
ADCSequenceConfigure(ADC1_BASE,2, ADC_TRIGGER_PROCESSOR, 0);
ADCHardwareOversampleConfigure(ADC1_BASE,16);
ADCSequenceStepConfigure(ADC1_BASE, 2,0, ADC_CTL_CH0); //ADC0 channel 0
ADCSequenceStepConfigure(ADC1_BASE, 2,1, ADC_CTL_TS|ADC_CTL_IE | ADC_CTL_END ); //setup temperature channel
// Clear the ADC0 interrupt.
ADCIntClear(ADC1_BASE,2);
ADCIntEnable(ADC1_BASE, 2);
// Enable ADC SS2
ADCSequenceEnable(ADC1_BASE, 2);
// Enable the ADC0 interrupt in the NVIC
IntEnable(INT_ADC1SS2);
// Indicate that ADC SS2 is ready for sampling
iADC0_read = 1;
//*****************************************************************************
// Global Interrupt Enable
//*****************************************************************************
// Enable processor interrupts
IntMasterEnable();
IntPrioritySet(INT_TIMER0A,0x40);
IntPrioritySet(INT_ADC1SS2,0x40);
// Loop forever waiting for interrupts
while(1)
{
}
}