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.
i want to utilize the adc module and DMA module to complete the sampling without cpu .i modify the codes in C:\ti\controlSUITE\device_support\F2837xD\v210\F2837xD_examples_Cpu1\dma_gsram_transfer.and add the adc module in it. the C:\ti\controlSUITE\device_support\F2837xD\v210\F2837xD_examples_Cpu1\adc_soc_continuous\cpu01 .i modify it's channel for my board.but it can not work ,the program will end at "
while (0==AdcaRegs.ADCINTFLG.bit.ADCINT1);",but when i mask the "dma_inlt()" fuction.the ADC can run normally.is the configuration of DMA conflict to the interruput of ADC? I can not understand .can somebody help me solve the problem? very appreciate you.
follow by codes that i modified a little
//###########################################################################
//
// FILE: dma_gsram_transfer_cpu01.c
//
// TITLE: DMA GSRAM Transfer
//
//! \addtogroup cpu01_example_list
//! <h1>DMA GSRAM Transfer (dma_gsram_transfer)</h1>
//!
//! This example uses one DMA channel to transfer data from a buffer in
//! RAMGS0 to a buffer in RAMGS1. The example sets the DMA channel
//! PERINTFRC bit repeatedly until the transfer of 16 bursts (where each
//! burst is 8 16-bit words) has been completed. When the whole transfer is
//! complete, it will trigger the DMA interrupt.
//!
//! \b Watch \b Variables \n
//! - \b sdata - Data to send
//! - \b rdata - Received data
//!
//
//###########################################################################
// $TI Release: F2837xD Support Library v210 $
// $Release Date: Tue Nov 1 14:46:15 CDT 2016 $
// $Copyright: Copyright (C) 2013-2016 Texas Instruments Incorporated -
// http://www.ti.com/ ALL RIGHTS RESERVED $
//###########################################################################
//
// Included Files
//
#include "F28x_Project.h"
//
// DMA data sections
//
#pragma DATA_SECTION(sdata, "ramgs0"); // map the TX data to memory
#pragma DATA_SECTION(rdata, "ramgs1"); // map the RX data to memory
//
// Defines
//
#define BURST 7 // write 7 to the register for a burst size of 8
#define TRANSFER 15 // [(MEM_BUFFER_SIZE/(BURST + 1)) - 1]
#define RESULTS_BUFFER_SIZE 1024
//
// Globals
//
Uint16 sdata[1024]; // Send data buffer
Uint16 rdata[1024]; // Receive data buffer
Uint16 AdcaResult2[1024];
//Uint16 AdcaResult3[1024];
volatile Uint16 *DMADest;
volatile Uint16 *DMASource;
volatile Uint16 done;
//
// Function Prototypes
void ConfigureADC(void);
void dma_init(void);
//Setup the ADC for continuous conversions on channel 0
void SetupADCContinuous(void);
__interrupt void local_D_INTCH6_ISR(void);
//void dma_init(void);
void error();
//
// Main
//
void main(void)
{
Uint16 resultsIndex;
//
// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the F2837xD_SysCtrl.c file.
//
InitSysCtrl();
// Step 2. Initialize GPIO:
// This example function is found in the F2837xD_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
InitGpio(); // Skipped for this example
// Step 3. Clear all interrupts and initialize PIE vector table:
// Disable CPU interrupts
DINT;
// Initialize the PIE control registers to their default state.
// The default state is all PIE interrupts disabled and flags
// are cleared.
// This function is found in the F2837xD_PieCtrl.c file.
InitPieCtrl();
// Disable CPU interrupts and clear all CPU interrupt flags:
IER = 0x0000;
IFR = 0x0000;
// Initialize the PIE vector table with pointers to the shell Interrupt
// Service Routines (ISR).
// This will populate the entire table, even if the interrupt
// is not used in this example. This is useful for debug purposes.
// The shell ISR routines are found in F2837xD_DefaultIsr.c.
// This function is found in F2837xD_PieVect.c.
InitPieVectTable();
EALLOW; // This is needed to write to EALLOW protected registers
PieVectTable.DMA_CH6_INT= &local_D_INTCH6_ISR;
EDIS; // This is needed to disable write to EALLOW protected registers
// Ensure DMA is connected to Peripheral Frame 2 bridge (EALLOW protected)
//
ConfigureADC();
//Setup the ADC for continuous conversions on channel 0
SetupADCContinuous();
dma_init(); // set up the dma
StartDMACH6();
EALLOW;
CpuSysRegs.SECMSEL.bit.PF2SEL = 1;
EDIS;
for(resultsIndex=0;resultsIndex<1024;resultsIndex++)
{
AdcaResult2[resultsIndex]=0;
}
//
PieCtrlRegs.PIECTRL.bit.ENPIE = 1; // Enable the PIE block
PieCtrlRegs.PIEIER7.bit.INTx6 = 1; // Enable PIE Group 7, INT 2 (DMA CH2)
IER= M_INT7; // Enable CPU INT6
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM
// Step 5. User specific code, enable interrupts:
// Initialize the data buffers
//
// Enable interrupts required for this example
//
resultsIndex=0;
do
{
//enable ADCINT flags 若不配置这里,ADC采样后中断不会置位
AdcaRegs.ADCINTSEL1N2.bit.INT1E = 1;
AdcaRegs.ADCINTFLGCLR.all = 0x000F;
//software force start SOCs
AdcaRegs.ADCSOCFRC1.all = 0x000C;// initiate the software initiate conversition
//keep taking samples until the results buffer is full
while(resultsIndex < RESULTS_BUFFER_SIZE)
{
//wait for current set of 6 conversions to complete
while(0 == AdcaRegs.ADCINTFLG.bit.ADCINT1);
//clear INT flags generated by current 6 conversions
AdcaRegs.ADCINTFLGCLR.bit.ADCINT1 = 1;
//save results for current 6 conversions
//
AdcaResult2[resultsIndex] = AdcaResultRegs.ADCRESULT2;
resultsIndex++;
}
//disable all ADCINT flags to stop sampling
AdcaRegs.ADCINTSEL1N2.bit.INT1E = 0;
asm(" ESTOP0");
}while(1);
}
//
// When the DMA transfer is complete the program will stop here
//
//
// error - Error Function which will halt the debugger
//
void error(void)
{
asm(" ESTOP0"); //Test failed!! Stop!
for (;;);
}
//
// dma_init - DMA setup for both TX and RX channels.
//
void dma_init()
{
//
// Refer to dma.c for the descriptions of the following functions.
//
//
//Initialize DMA
//
DMAInitialize();
DMASource = (volatile Uint16 *)&AdcaResultRegs.ADCRESULT2;
DMADest = (volatile Uint16 *)rdata;
//
// configure DMA CH6
//
DMACH6AddrConfig(DMADest,DMASource);
DMACH6BurstConfig(BURST,1,1);
DMACH6TransferConfig(TRANSFER,1,1);
DMACH6ModeConfig(DMA_ADCAINT1,PERINT_ENABLE,ONESHOT_DISABLE,CONT_DISABLE,
SYNC_DISABLE,SYNC_SRC,OVRFLOW_DISABLE,SIXTEEN_BIT,
CHINT_END,CHINT_ENABLE);
}
//
// local_D_INTCH6_ISR - DMA Channel6 ISR
//
__interrupt void local_D_INTCH6_ISR(void)
{
Uint16 i;
EALLOW; // NEED TO EXECUTE EALLOW INSIDE ISR !!!
DmaRegs.CH6.CONTROL.bit.HALT = 1;
PieCtrlRegs.PIEACK.all = PIEACK_GROUP7; // ACK to receive more interrupts
// from this PIE group
EDIS;
for( i = 0; i < 1024; i++ )
{
//
// check for data integrity
//
if (rdata[i] != i)
{
error();
}
}
done = 1; // Test done.
return;
}
//
// End of file
//
//Write ADC configurations and power up the ADC for both ADC A and ADC B
void ConfigureADC(void)
{
EALLOW;
//write configurations
AdcaRegs.ADCCTL2.bit.PRESCALE = 15; //set ADCCLK divider to /4 配置ADC时钟,有系统时钟参考时钟
AdcSetMode(ADC_ADCA, ADC_RESOLUTION_16BIT, ADC_SIGNALMODE_DIFFERENTIAL);
//Set pulse positions to late
AdcaRegs.ADCCTL1.bit.INTPULSEPOS = 1;//设置ADC中断产生时机在转换完成后
//power up the ADC
AdcaRegs.ADCCTL1.bit.ADCPWDNZ = 1;//上电需要掩饰1ms左右等待上电完成
//delay for 1ms to allow ADC time to power up
DELAY_US(1000);
EDIS;
}
//setup the ADC to continuously convert on one channel
void SetupADCContinuous(void)
{
Uint16 acqps;
//determine minimum acquisition window (in SYSCLKS) based on resolution
if(ADC_RESOLUTION_12BIT == AdcaRegs.ADCCTL2.bit.RESOLUTION){
acqps = 511; //2560ns
}
else { //resolution is 16-bit
acqps = 511; //320ns
}
EALLOW;
AdcaRegs.ADCSOC2CTL.bit.CHSEL = 2; //SOC will convert on channel
AdcaRegs.ADCSOC3CTL.bit.CHSEL = 3; //SOC will convert on channel
AdcaRegs.ADCSOC2CTL.bit.ACQPS = acqps; //sample window is acqps + 1 SYSCLK cycles
AdcaRegs.ADCSOC3CTL.bit.ACQPS = acqps; //sample window is acqps + 1 SYSCLK cycles
AdcaRegs.ADCINTSEL1N2.bit.INT1E = 0; //disable INT1 flag
AdcaRegs.ADCINTSEL1N2.bit.INT1CONT = 1;
AdcaRegs.ADCINTSEL1N2.bit.INT1SEL = 2; //end of SOC5 will set INT1 flag 最后一个优先级的SOC即可,随时需要修改
// AdcaRegs.ADCINTFLGCLR.bit.ADCINT1=1;
//ADCINT1 will trigger SOCs
AdcaRegs.ADCINTSOCSEL1.bit.SOC2 = 1;
AdcaRegs.ADCINTSOCSEL1.bit.SOC3 = 1;
}