我想问一下,我不太明白。我使用的外接AD采样是ADI的AD7606,和TI的ADS8568是一样的。dsp是28335,我不太明白,把AD芯片的DB(数据输出口)和dsp的GPIO64-79口连接在一起。是当每次AD采样完成之后,采样的数据就自动送入到dsp28335里面去了吗?那为什么我运行程序之后观察GPCDAT寄存器的值没有变化呢?是不是还需要加上什么通信或者读写指令,和AD连接的GPIO口的GPXDAT寄存器的值才会发生变化?不然,怎么将AD采样完成之后的数据送入dsp呢?
这是我的程序,可以看到,我是把输出的DB接到28335的GPIO64-79端口上,我想通过GPCDAT的值来看DB的数字量的输出。
可是我每次运行完程序,GPCDAT的值总是不变的,一直全部是1,不知道为什么,不是应该GPCDAT应该正确读取AD采样之后的结果吗?还是我哪里理解有问题,希望大佬指教一下
include "DSP2833x_Device.h" // Headerfile Include File
#include "DSP2833x_Examples.h" // Examples Include File
#define AD7656_BASIC (*((volatile Uint16 *)0x4000))
#define SET_ADRST GpioDataRegs.GPBSET.bit.GPIO49=1
#define CLEAR_ADRST GpioDataRegs.GPBCLEAR.bit.GPIO49=1
#define AD_BUSY GpioDataRegs.GPBDAT.bit.GPIO48
#define SET_ADCLK GpioDataRegs.GPBSET.bit.GPIO62=1
#define CLR_ADCLK GpioDataRegs.GPBCLEAR.bit.GPIO62=1
int DOUT[8];
int testtest[8];
float AdcSample[8];
//int test[256];
long sampleCount=0;
float testSample1[256],testSample2[256],testSample3[256],//8个数组存放AD数据
testSample4[256],testSample5[256],testSample6[256],
testSample7[256],testSample8[256];
float gpiodata1[256],gpiodata2[256],gpiodata3[256],
gpiodata4[256],gpiodata5[256],gpiodata6[256],
gpiodata7[256],gpiodata8[256],gpiodata9[256],gpiodata10[256],gpiodata11[256],
gpiodata12[256],gpiodata13[256],gpiodata14[256],gpiodata15[256],gpiodata16[256];
int i;
int testgpio48;
Uint16 adc_cnt=0;
int conv_flg=0;
extern void InitXintf(void);
void chipselect(void)
{
EALLOW;
GpioCtrlRegs.GPBMUX1.bit.GPIO36=2;
GpioCtrlRegs.GPBDIR.bit.GPIO36=1;
EDIS;
}
interrupt void cpu_timer0_isr(void)
{
EDIS;
GpioDataRegs.GPBCLEAR.bit.GPIO36=1;
EALLOW;
SET_ADCLK;//启动转换信号
DELAY_US(1); //给予适当的电平延时
CLR_ADCLK;
DELAY_US(1);
testgpio48=GpioDataRegs.GPBDAT.bit.GPIO48;
EALLOW;
GpioCtrlRegs.GPCMUX1.bit.GPIO79=0;
GpioCtrlRegs.GPCMUX1.bit.GPIO78=0;
GpioCtrlRegs.GPCMUX1.bit.GPIO77=0;
GpioCtrlRegs.GPCMUX1.bit.GPIO76=0;
GpioCtrlRegs.GPCMUX1.bit.GPIO75=0;
GpioCtrlRegs.GPCMUX1.bit.GPIO74=0;
GpioCtrlRegs.GPCMUX1.bit.GPIO73=0;
GpioCtrlRegs.GPCDIR.bit.GPIO79=0;
GpioCtrlRegs.GPCDIR.bit.GPIO78=0;
GpioCtrlRegs.GPCDIR.bit.GPIO77=0;
GpioCtrlRegs.GPCDIR.bit.GPIO76=0;
GpioCtrlRegs.GPCDIR.bit.GPIO75=0;
EDIS;
while(AD_BUSY) //等待转换结束
{
}
for(i=0;i<8;i++)
{
DOUT[i]=AD7656_BASIC; //读取8路AD通道数据
testtest[i]=AD7656_BASIC;
gpiodata1[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO79;
gpiodata2[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO78;
gpiodata3[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO77;
gpiodata4[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO76;
gpiodata5[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO75;
gpiodata6[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO74;
gpiodata7[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO73;
gpiodata8[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO72;
gpiodata9[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO71;
gpiodata10[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO70;
gpiodata11[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO69;
gpiodata12[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO68;
gpiodata13[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO67;
gpiodata14[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO66;
gpiodata15[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO65;
gpiodata16[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO64;
}
conv_flg=1;
EALLOW;
// Acknowledge this interrupt to receive more interrupts from group 1
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
EDIS;
}
void AD7606Init(void){
EALLOW; //寄存器保护开启
GpioCtrlRegs.GPBMUX2.bit.GPIO48 = 0; //复用为GPIO
GpioCtrlRegs.GPBMUX2.bit.GPIO49 = 0; //复用为GPIO
GpioCtrlRegs.GPBMUX2.bit.GPIO62 = 0; //复用为GPIO
GpioCtrlRegs.GPBDIR.bit.GPIO49 = 1; //设置为输出
GpioCtrlRegs.GPBDIR.bit.GPIO48 = 0; //设置为输入
GpioCtrlRegs.GPBDIR.bit.GPIO62 = 1; //设置为输出
/* GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 0; //复用为GPIO
GpioCtrlRegs.GPAMUX1.bit.GPIO1 = 0;
GpioCtrlRegs.GPAMUX1.bit.GPIO2 = 0;
GpioCtrlRegs.GPADIR.bit.GPIO0 = 1; //设置为输出
GpioCtrlRegs.GPADIR.bit.GPIO1 = 1; //设置为输出
GpioCtrlRegs.GPADIR.bit.GPIO2 = 1; //设置为输出*/
EDIS; //寄存器保护结束
/* GpioDataRegs.GPADAT.bit.GPIO0 = 0;
DELAY_US(1);
GpioDataRegs.GPADAT.bit.GPIO1 = 0;
DELAY_US(1);
GpioDataRegs.GPADAT.bit.GPIO2 = 0;*/
DELAY_US(1);
CLEAR_ADRST;
SET_ADCLK;
}
/*void output(void){
EALLOW;
GpioCtrlRegs.GPCMUX1.bit.GPIO79 = 0; //复用为GPIO
GpioCtrlRegs.GPCMUX1.bit.GPIO78 = 0; //复用为GPIO
GpioCtrlRegs.GPCMUX1.bit.GPIO77 = 0; //复用为GPIO
GpioCtrlRegs.GPCDIR.bit.GPIO79 = 0; //设置为输出
GpioCtrlRegs.GPCDIR.bit.GPIO78 = 1; //设置为输入
GpioCtrlRegs.GPCDIR.bit.GPIO77 = 0; //设置为输出
GpioDataRegs.GPCDAT.bit.GPIO78 = 0;
EDIS;
}
*/
void main(void)
{
Uint16 i;
// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the DSP2833x_SysCtrl.c file.
InitSysCtrl();
// Step 2. Initalize GPIO:
// This example function is found in the DSP2833x_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
// InitGpio(); // Skipped for this example
InitXintf16Gpio(); //zq
InitXintf();
// 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 DSP2833x_PieCtrl.c file.
InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();
//output();
EALLOW; // This is needed to write to EALLOW protected registers
PieVectTable.TINT0 = &cpu_timer0_isr;
EDIS; // This is needed to disable write to EALLOW protected registers
// Step 4. Initialize the Device Peripheral. This function can be
// found in DSP2834x_CpuTimers.c
InitCpuTimers(); // For this example, only initialize the Cpu Timers
// Configure CPU-Timer 0, 1, and 2 to interrupt every second:
// 150MHz CPU Freq, 1 second Period (in uSeconds)
ConfigCpuTimer(&CpuTimer0, 150,1000);
IER |= M_INT1;
// Enable TINT0 in the PIE: Group 1 interrupt 7
// Enable TINT0 in the PIE: Group 1 interrupt 7
PieCtrlRegs.PIECTRL.bit.ENPIE = 1;
PieCtrlRegs.PIEIER1.bit.INTx7 = 1;
// Enable global Interrupts and higher priority real-time debug events:
for(i=0;i<8;i++)
testtest[i]=0;
AD7606Init();
SET_ADRST;
DELAY_US(100);
CLEAR_ADRST;
DELAY_US(100);
StartCpuTimer0();
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM
for(;;)
{
if(conv_flg==1)
{
for(i=0;i<8;i++)
AdcSample[i] = (20.0/65536.0)* DOUT[i];//数字量转换为模拟量,输入范围是正负10V,精度为16位
//相当于将20V分成了65536份,公式为A=(20.0/65536.0)*D;A为模拟量值,D为数字量值;
//如果输入范围是正负5V则公式为A=(10.0/65536.0)*D
conv_flg=0;
testSample1[adc_cnt] = AdcSample[0]; //存放每个通道的历史数值
testSample2[adc_cnt] = AdcSample[1];
testSample3[adc_cnt] = AdcSample[2];
testSample4[adc_cnt] = AdcSample[3];
testSample5[adc_cnt] = AdcSample[4];
testSample6[adc_cnt] = AdcSample[5];
testSample7[adc_cnt] = AdcSample[6];
testSample8[adc_cnt] = AdcSample[7];
adc_cnt++;
if(adc_cnt > 255)
adc_cnt = 0;
}
}
}
//===========================================================================
// No more.
//===========================================================================
Emma Wang:
将GPIO64-79配置成为外部数据接口线后,他们就不再是普通的GPIO了。
正确的做法是,看一下AD7606与芯片的地址线的接法,从确定的地址上读取AD转换结果。
我想问一下,我不太明白。我使用的外接AD采样是ADI的AD7606,和TI的ADS8568是一样的。dsp是28335,我不太明白,把AD芯片的DB(数据输出口)和dsp的GPIO64-79口连接在一起。是当每次AD采样完成之后,采样的数据就自动送入到dsp28335里面去了吗?那为什么我运行程序之后观察GPCDAT寄存器的值没有变化呢?是不是还需要加上什么通信或者读写指令,和AD连接的GPIO口的GPXDAT寄存器的值才会发生变化?不然,怎么将AD采样完成之后的数据送入dsp呢?
这是我的程序,可以看到,我是把输出的DB接到28335的GPIO64-79端口上,我想通过GPCDAT的值来看DB的数字量的输出。
可是我每次运行完程序,GPCDAT的值总是不变的,一直全部是1,不知道为什么,不是应该GPCDAT应该正确读取AD采样之后的结果吗?还是我哪里理解有问题,希望大佬指教一下
include "DSP2833x_Device.h" // Headerfile Include File
#include "DSP2833x_Examples.h" // Examples Include File
#define AD7656_BASIC (*((volatile Uint16 *)0x4000))
#define SET_ADRST GpioDataRegs.GPBSET.bit.GPIO49=1
#define CLEAR_ADRST GpioDataRegs.GPBCLEAR.bit.GPIO49=1
#define AD_BUSY GpioDataRegs.GPBDAT.bit.GPIO48
#define SET_ADCLK GpioDataRegs.GPBSET.bit.GPIO62=1
#define CLR_ADCLK GpioDataRegs.GPBCLEAR.bit.GPIO62=1
int DOUT[8];
int testtest[8];
float AdcSample[8];
//int test[256];
long sampleCount=0;
float testSample1[256],testSample2[256],testSample3[256],//8个数组存放AD数据
testSample4[256],testSample5[256],testSample6[256],
testSample7[256],testSample8[256];
float gpiodata1[256],gpiodata2[256],gpiodata3[256],
gpiodata4[256],gpiodata5[256],gpiodata6[256],
gpiodata7[256],gpiodata8[256],gpiodata9[256],gpiodata10[256],gpiodata11[256],
gpiodata12[256],gpiodata13[256],gpiodata14[256],gpiodata15[256],gpiodata16[256];
int i;
int testgpio48;
Uint16 adc_cnt=0;
int conv_flg=0;
extern void InitXintf(void);
void chipselect(void)
{
EALLOW;
GpioCtrlRegs.GPBMUX1.bit.GPIO36=2;
GpioCtrlRegs.GPBDIR.bit.GPIO36=1;
EDIS;
}
interrupt void cpu_timer0_isr(void)
{
EDIS;
GpioDataRegs.GPBCLEAR.bit.GPIO36=1;
EALLOW;
SET_ADCLK;//启动转换信号
DELAY_US(1); //给予适当的电平延时
CLR_ADCLK;
DELAY_US(1);
testgpio48=GpioDataRegs.GPBDAT.bit.GPIO48;
EALLOW;
GpioCtrlRegs.GPCMUX1.bit.GPIO79=0;
GpioCtrlRegs.GPCMUX1.bit.GPIO78=0;
GpioCtrlRegs.GPCMUX1.bit.GPIO77=0;
GpioCtrlRegs.GPCMUX1.bit.GPIO76=0;
GpioCtrlRegs.GPCMUX1.bit.GPIO75=0;
GpioCtrlRegs.GPCMUX1.bit.GPIO74=0;
GpioCtrlRegs.GPCMUX1.bit.GPIO73=0;
GpioCtrlRegs.GPCDIR.bit.GPIO79=0;
GpioCtrlRegs.GPCDIR.bit.GPIO78=0;
GpioCtrlRegs.GPCDIR.bit.GPIO77=0;
GpioCtrlRegs.GPCDIR.bit.GPIO76=0;
GpioCtrlRegs.GPCDIR.bit.GPIO75=0;
EDIS;
while(AD_BUSY) //等待转换结束
{
}
for(i=0;i<8;i++)
{
DOUT[i]=AD7656_BASIC; //读取8路AD通道数据
testtest[i]=AD7656_BASIC;
gpiodata1[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO79;
gpiodata2[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO78;
gpiodata3[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO77;
gpiodata4[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO76;
gpiodata5[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO75;
gpiodata6[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO74;
gpiodata7[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO73;
gpiodata8[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO72;
gpiodata9[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO71;
gpiodata10[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO70;
gpiodata11[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO69;
gpiodata12[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO68;
gpiodata13[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO67;
gpiodata14[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO66;
gpiodata15[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO65;
gpiodata16[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO64;
}
conv_flg=1;
EALLOW;
// Acknowledge this interrupt to receive more interrupts from group 1
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
EDIS;
}
void AD7606Init(void){
EALLOW; //寄存器保护开启
GpioCtrlRegs.GPBMUX2.bit.GPIO48 = 0; //复用为GPIO
GpioCtrlRegs.GPBMUX2.bit.GPIO49 = 0; //复用为GPIO
GpioCtrlRegs.GPBMUX2.bit.GPIO62 = 0; //复用为GPIO
GpioCtrlRegs.GPBDIR.bit.GPIO49 = 1; //设置为输出
GpioCtrlRegs.GPBDIR.bit.GPIO48 = 0; //设置为输入
GpioCtrlRegs.GPBDIR.bit.GPIO62 = 1; //设置为输出
/* GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 0; //复用为GPIO
GpioCtrlRegs.GPAMUX1.bit.GPIO1 = 0;
GpioCtrlRegs.GPAMUX1.bit.GPIO2 = 0;
GpioCtrlRegs.GPADIR.bit.GPIO0 = 1; //设置为输出
GpioCtrlRegs.GPADIR.bit.GPIO1 = 1; //设置为输出
GpioCtrlRegs.GPADIR.bit.GPIO2 = 1; //设置为输出*/
EDIS; //寄存器保护结束
/* GpioDataRegs.GPADAT.bit.GPIO0 = 0;
DELAY_US(1);
GpioDataRegs.GPADAT.bit.GPIO1 = 0;
DELAY_US(1);
GpioDataRegs.GPADAT.bit.GPIO2 = 0;*/
DELAY_US(1);
CLEAR_ADRST;
SET_ADCLK;
}
/*void output(void){
EALLOW;
GpioCtrlRegs.GPCMUX1.bit.GPIO79 = 0; //复用为GPIO
GpioCtrlRegs.GPCMUX1.bit.GPIO78 = 0; //复用为GPIO
GpioCtrlRegs.GPCMUX1.bit.GPIO77 = 0; //复用为GPIO
GpioCtrlRegs.GPCDIR.bit.GPIO79 = 0; //设置为输出
GpioCtrlRegs.GPCDIR.bit.GPIO78 = 1; //设置为输入
GpioCtrlRegs.GPCDIR.bit.GPIO77 = 0; //设置为输出
GpioDataRegs.GPCDAT.bit.GPIO78 = 0;
EDIS;
}
*/
void main(void)
{
Uint16 i;
// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the DSP2833x_SysCtrl.c file.
InitSysCtrl();
// Step 2. Initalize GPIO:
// This example function is found in the DSP2833x_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
// InitGpio(); // Skipped for this example
InitXintf16Gpio(); //zq
InitXintf();
// 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 DSP2833x_PieCtrl.c file.
InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();
//output();
EALLOW; // This is needed to write to EALLOW protected registers
PieVectTable.TINT0 = &cpu_timer0_isr;
EDIS; // This is needed to disable write to EALLOW protected registers
// Step 4. Initialize the Device Peripheral. This function can be
// found in DSP2834x_CpuTimers.c
InitCpuTimers(); // For this example, only initialize the Cpu Timers
// Configure CPU-Timer 0, 1, and 2 to interrupt every second:
// 150MHz CPU Freq, 1 second Period (in uSeconds)
ConfigCpuTimer(&CpuTimer0, 150,1000);
IER |= M_INT1;
// Enable TINT0 in the PIE: Group 1 interrupt 7
// Enable TINT0 in the PIE: Group 1 interrupt 7
PieCtrlRegs.PIECTRL.bit.ENPIE = 1;
PieCtrlRegs.PIEIER1.bit.INTx7 = 1;
// Enable global Interrupts and higher priority real-time debug events:
for(i=0;i<8;i++)
testtest[i]=0;
AD7606Init();
SET_ADRST;
DELAY_US(100);
CLEAR_ADRST;
DELAY_US(100);
StartCpuTimer0();
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM
for(;;)
{
if(conv_flg==1)
{
for(i=0;i<8;i++)
AdcSample[i] = (20.0/65536.0)* DOUT[i];//数字量转换为模拟量,输入范围是正负10V,精度为16位
//相当于将20V分成了65536份,公式为A=(20.0/65536.0)*D;A为模拟量值,D为数字量值;
//如果输入范围是正负5V则公式为A=(10.0/65536.0)*D
conv_flg=0;
testSample1[adc_cnt] = AdcSample[0]; //存放每个通道的历史数值
testSample2[adc_cnt] = AdcSample[1];
testSample3[adc_cnt] = AdcSample[2];
testSample4[adc_cnt] = AdcSample[3];
testSample5[adc_cnt] = AdcSample[4];
testSample6[adc_cnt] = AdcSample[5];
testSample7[adc_cnt] = AdcSample[6];
testSample8[adc_cnt] = AdcSample[7];
adc_cnt++;
if(adc_cnt > 255)
adc_cnt = 0;
}
}
}
//===========================================================================
// No more.
//===========================================================================
mangui zhang:
从你的连接看 不是普通的gpio 配置为总线形式
这个需要根据时序进行读取操作
我想问一下,我不太明白。我使用的外接AD采样是ADI的AD7606,和TI的ADS8568是一样的。dsp是28335,我不太明白,把AD芯片的DB(数据输出口)和dsp的GPIO64-79口连接在一起。是当每次AD采样完成之后,采样的数据就自动送入到dsp28335里面去了吗?那为什么我运行程序之后观察GPCDAT寄存器的值没有变化呢?是不是还需要加上什么通信或者读写指令,和AD连接的GPIO口的GPXDAT寄存器的值才会发生变化?不然,怎么将AD采样完成之后的数据送入dsp呢?
这是我的程序,可以看到,我是把输出的DB接到28335的GPIO64-79端口上,我想通过GPCDAT的值来看DB的数字量的输出。
可是我每次运行完程序,GPCDAT的值总是不变的,一直全部是1,不知道为什么,不是应该GPCDAT应该正确读取AD采样之后的结果吗?还是我哪里理解有问题,希望大佬指教一下
include "DSP2833x_Device.h" // Headerfile Include File
#include "DSP2833x_Examples.h" // Examples Include File
#define AD7656_BASIC (*((volatile Uint16 *)0x4000))
#define SET_ADRST GpioDataRegs.GPBSET.bit.GPIO49=1
#define CLEAR_ADRST GpioDataRegs.GPBCLEAR.bit.GPIO49=1
#define AD_BUSY GpioDataRegs.GPBDAT.bit.GPIO48
#define SET_ADCLK GpioDataRegs.GPBSET.bit.GPIO62=1
#define CLR_ADCLK GpioDataRegs.GPBCLEAR.bit.GPIO62=1
int DOUT[8];
int testtest[8];
float AdcSample[8];
//int test[256];
long sampleCount=0;
float testSample1[256],testSample2[256],testSample3[256],//8个数组存放AD数据
testSample4[256],testSample5[256],testSample6[256],
testSample7[256],testSample8[256];
float gpiodata1[256],gpiodata2[256],gpiodata3[256],
gpiodata4[256],gpiodata5[256],gpiodata6[256],
gpiodata7[256],gpiodata8[256],gpiodata9[256],gpiodata10[256],gpiodata11[256],
gpiodata12[256],gpiodata13[256],gpiodata14[256],gpiodata15[256],gpiodata16[256];
int i;
int testgpio48;
Uint16 adc_cnt=0;
int conv_flg=0;
extern void InitXintf(void);
void chipselect(void)
{
EALLOW;
GpioCtrlRegs.GPBMUX1.bit.GPIO36=2;
GpioCtrlRegs.GPBDIR.bit.GPIO36=1;
EDIS;
}
interrupt void cpu_timer0_isr(void)
{
EDIS;
GpioDataRegs.GPBCLEAR.bit.GPIO36=1;
EALLOW;
SET_ADCLK;//启动转换信号
DELAY_US(1); //给予适当的电平延时
CLR_ADCLK;
DELAY_US(1);
testgpio48=GpioDataRegs.GPBDAT.bit.GPIO48;
EALLOW;
GpioCtrlRegs.GPCMUX1.bit.GPIO79=0;
GpioCtrlRegs.GPCMUX1.bit.GPIO78=0;
GpioCtrlRegs.GPCMUX1.bit.GPIO77=0;
GpioCtrlRegs.GPCMUX1.bit.GPIO76=0;
GpioCtrlRegs.GPCMUX1.bit.GPIO75=0;
GpioCtrlRegs.GPCMUX1.bit.GPIO74=0;
GpioCtrlRegs.GPCMUX1.bit.GPIO73=0;
GpioCtrlRegs.GPCDIR.bit.GPIO79=0;
GpioCtrlRegs.GPCDIR.bit.GPIO78=0;
GpioCtrlRegs.GPCDIR.bit.GPIO77=0;
GpioCtrlRegs.GPCDIR.bit.GPIO76=0;
GpioCtrlRegs.GPCDIR.bit.GPIO75=0;
EDIS;
while(AD_BUSY) //等待转换结束
{
}
for(i=0;i<8;i++)
{
DOUT[i]=AD7656_BASIC; //读取8路AD通道数据
testtest[i]=AD7656_BASIC;
gpiodata1[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO79;
gpiodata2[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO78;
gpiodata3[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO77;
gpiodata4[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO76;
gpiodata5[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO75;
gpiodata6[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO74;
gpiodata7[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO73;
gpiodata8[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO72;
gpiodata9[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO71;
gpiodata10[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO70;
gpiodata11[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO69;
gpiodata12[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO68;
gpiodata13[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO67;
gpiodata14[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO66;
gpiodata15[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO65;
gpiodata16[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO64;
}
conv_flg=1;
EALLOW;
// Acknowledge this interrupt to receive more interrupts from group 1
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
EDIS;
}
void AD7606Init(void){
EALLOW; //寄存器保护开启
GpioCtrlRegs.GPBMUX2.bit.GPIO48 = 0; //复用为GPIO
GpioCtrlRegs.GPBMUX2.bit.GPIO49 = 0; //复用为GPIO
GpioCtrlRegs.GPBMUX2.bit.GPIO62 = 0; //复用为GPIO
GpioCtrlRegs.GPBDIR.bit.GPIO49 = 1; //设置为输出
GpioCtrlRegs.GPBDIR.bit.GPIO48 = 0; //设置为输入
GpioCtrlRegs.GPBDIR.bit.GPIO62 = 1; //设置为输出
/* GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 0; //复用为GPIO
GpioCtrlRegs.GPAMUX1.bit.GPIO1 = 0;
GpioCtrlRegs.GPAMUX1.bit.GPIO2 = 0;
GpioCtrlRegs.GPADIR.bit.GPIO0 = 1; //设置为输出
GpioCtrlRegs.GPADIR.bit.GPIO1 = 1; //设置为输出
GpioCtrlRegs.GPADIR.bit.GPIO2 = 1; //设置为输出*/
EDIS; //寄存器保护结束
/* GpioDataRegs.GPADAT.bit.GPIO0 = 0;
DELAY_US(1);
GpioDataRegs.GPADAT.bit.GPIO1 = 0;
DELAY_US(1);
GpioDataRegs.GPADAT.bit.GPIO2 = 0;*/
DELAY_US(1);
CLEAR_ADRST;
SET_ADCLK;
}
/*void output(void){
EALLOW;
GpioCtrlRegs.GPCMUX1.bit.GPIO79 = 0; //复用为GPIO
GpioCtrlRegs.GPCMUX1.bit.GPIO78 = 0; //复用为GPIO
GpioCtrlRegs.GPCMUX1.bit.GPIO77 = 0; //复用为GPIO
GpioCtrlRegs.GPCDIR.bit.GPIO79 = 0; //设置为输出
GpioCtrlRegs.GPCDIR.bit.GPIO78 = 1; //设置为输入
GpioCtrlRegs.GPCDIR.bit.GPIO77 = 0; //设置为输出
GpioDataRegs.GPCDAT.bit.GPIO78 = 0;
EDIS;
}
*/
void main(void)
{
Uint16 i;
// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the DSP2833x_SysCtrl.c file.
InitSysCtrl();
// Step 2. Initalize GPIO:
// This example function is found in the DSP2833x_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
// InitGpio(); // Skipped for this example
InitXintf16Gpio(); //zq
InitXintf();
// 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 DSP2833x_PieCtrl.c file.
InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();
//output();
EALLOW; // This is needed to write to EALLOW protected registers
PieVectTable.TINT0 = &cpu_timer0_isr;
EDIS; // This is needed to disable write to EALLOW protected registers
// Step 4. Initialize the Device Peripheral. This function can be
// found in DSP2834x_CpuTimers.c
InitCpuTimers(); // For this example, only initialize the Cpu Timers
// Configure CPU-Timer 0, 1, and 2 to interrupt every second:
// 150MHz CPU Freq, 1 second Period (in uSeconds)
ConfigCpuTimer(&CpuTimer0, 150,1000);
IER |= M_INT1;
// Enable TINT0 in the PIE: Group 1 interrupt 7
// Enable TINT0 in the PIE: Group 1 interrupt 7
PieCtrlRegs.PIECTRL.bit.ENPIE = 1;
PieCtrlRegs.PIEIER1.bit.INTx7 = 1;
// Enable global Interrupts and higher priority real-time debug events:
for(i=0;i<8;i++)
testtest[i]=0;
AD7606Init();
SET_ADRST;
DELAY_US(100);
CLEAR_ADRST;
DELAY_US(100);
StartCpuTimer0();
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM
for(;;)
{
if(conv_flg==1)
{
for(i=0;i<8;i++)
AdcSample[i] = (20.0/65536.0)* DOUT[i];//数字量转换为模拟量,输入范围是正负10V,精度为16位
//相当于将20V分成了65536份,公式为A=(20.0/65536.0)*D;A为模拟量值,D为数字量值;
//如果输入范围是正负5V则公式为A=(10.0/65536.0)*D
conv_flg=0;
testSample1[adc_cnt] = AdcSample[0]; //存放每个通道的历史数值
testSample2[adc_cnt] = AdcSample[1];
testSample3[adc_cnt] = AdcSample[2];
testSample4[adc_cnt] = AdcSample[3];
testSample5[adc_cnt] = AdcSample[4];
testSample6[adc_cnt] = AdcSample[5];
testSample7[adc_cnt] = AdcSample[6];
testSample8[adc_cnt] = AdcSample[7];
adc_cnt++;
if(adc_cnt > 255)
adc_cnt = 0;
}
}
}
//===========================================================================
// No more.
//===========================================================================
hellodsp:
回复 Emma Wang:
Emma Wang1
将GPIO64-79配置成为外部数据接口线后,他们就不再是普通的GPIO了。
正确的做法是,看一下AD7606与芯片的地址线的接法,从确定的地址上读取AD转换结果。
我想问一下,我不太明白。我使用的外接AD采样是ADI的AD7606,和TI的ADS8568是一样的。dsp是28335,我不太明白,把AD芯片的DB(数据输出口)和dsp的GPIO64-79口连接在一起。是当每次AD采样完成之后,采样的数据就自动送入到dsp28335里面去了吗?那为什么我运行程序之后观察GPCDAT寄存器的值没有变化呢?是不是还需要加上什么通信或者读写指令,和AD连接的GPIO口的GPXDAT寄存器的值才会发生变化?不然,怎么将AD采样完成之后的数据送入dsp呢?
这是我的程序,可以看到,我是把输出的DB接到28335的GPIO64-79端口上,我想通过GPCDAT的值来看DB的数字量的输出。
可是我每次运行完程序,GPCDAT的值总是不变的,一直全部是1,不知道为什么,不是应该GPCDAT应该正确读取AD采样之后的结果吗?还是我哪里理解有问题,希望大佬指教一下
include "DSP2833x_Device.h" // Headerfile Include File
#include "DSP2833x_Examples.h" // Examples Include File
#define AD7656_BASIC (*((volatile Uint16 *)0x4000))
#define SET_ADRST GpioDataRegs.GPBSET.bit.GPIO49=1
#define CLEAR_ADRST GpioDataRegs.GPBCLEAR.bit.GPIO49=1
#define AD_BUSY GpioDataRegs.GPBDAT.bit.GPIO48
#define SET_ADCLK GpioDataRegs.GPBSET.bit.GPIO62=1
#define CLR_ADCLK GpioDataRegs.GPBCLEAR.bit.GPIO62=1
int DOUT[8];
int testtest[8];
float AdcSample[8];
//int test[256];
long sampleCount=0;
float testSample1[256],testSample2[256],testSample3[256],//8个数组存放AD数据
testSample4[256],testSample5[256],testSample6[256],
testSample7[256],testSample8[256];
float gpiodata1[256],gpiodata2[256],gpiodata3[256],
gpiodata4[256],gpiodata5[256],gpiodata6[256],
gpiodata7[256],gpiodata8[256],gpiodata9[256],gpiodata10[256],gpiodata11[256],
gpiodata12[256],gpiodata13[256],gpiodata14[256],gpiodata15[256],gpiodata16[256];
int i;
int testgpio48;
Uint16 adc_cnt=0;
int conv_flg=0;
extern void InitXintf(void);
void chipselect(void)
{
EALLOW;
GpioCtrlRegs.GPBMUX1.bit.GPIO36=2;
GpioCtrlRegs.GPBDIR.bit.GPIO36=1;
EDIS;
}
interrupt void cpu_timer0_isr(void)
{
EDIS;
GpioDataRegs.GPBCLEAR.bit.GPIO36=1;
EALLOW;
SET_ADCLK;//启动转换信号
DELAY_US(1); //给予适当的电平延时
CLR_ADCLK;
DELAY_US(1);
testgpio48=GpioDataRegs.GPBDAT.bit.GPIO48;
EALLOW;
GpioCtrlRegs.GPCMUX1.bit.GPIO79=0;
GpioCtrlRegs.GPCMUX1.bit.GPIO78=0;
GpioCtrlRegs.GPCMUX1.bit.GPIO77=0;
GpioCtrlRegs.GPCMUX1.bit.GPIO76=0;
GpioCtrlRegs.GPCMUX1.bit.GPIO75=0;
GpioCtrlRegs.GPCMUX1.bit.GPIO74=0;
GpioCtrlRegs.GPCMUX1.bit.GPIO73=0;
GpioCtrlRegs.GPCDIR.bit.GPIO79=0;
GpioCtrlRegs.GPCDIR.bit.GPIO78=0;
GpioCtrlRegs.GPCDIR.bit.GPIO77=0;
GpioCtrlRegs.GPCDIR.bit.GPIO76=0;
GpioCtrlRegs.GPCDIR.bit.GPIO75=0;
EDIS;
while(AD_BUSY) //等待转换结束
{
}
for(i=0;i<8;i++)
{
DOUT[i]=AD7656_BASIC; //读取8路AD通道数据
testtest[i]=AD7656_BASIC;
gpiodata1[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO79;
gpiodata2[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO78;
gpiodata3[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO77;
gpiodata4[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO76;
gpiodata5[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO75;
gpiodata6[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO74;
gpiodata7[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO73;
gpiodata8[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO72;
gpiodata9[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO71;
gpiodata10[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO70;
gpiodata11[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO69;
gpiodata12[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO68;
gpiodata13[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO67;
gpiodata14[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO66;
gpiodata15[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO65;
gpiodata16[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO64;
}
conv_flg=1;
EALLOW;
// Acknowledge this interrupt to receive more interrupts from group 1
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
EDIS;
}
void AD7606Init(void){
EALLOW; //寄存器保护开启
GpioCtrlRegs.GPBMUX2.bit.GPIO48 = 0; //复用为GPIO
GpioCtrlRegs.GPBMUX2.bit.GPIO49 = 0; //复用为GPIO
GpioCtrlRegs.GPBMUX2.bit.GPIO62 = 0; //复用为GPIO
GpioCtrlRegs.GPBDIR.bit.GPIO49 = 1; //设置为输出
GpioCtrlRegs.GPBDIR.bit.GPIO48 = 0; //设置为输入
GpioCtrlRegs.GPBDIR.bit.GPIO62 = 1; //设置为输出
/* GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 0; //复用为GPIO
GpioCtrlRegs.GPAMUX1.bit.GPIO1 = 0;
GpioCtrlRegs.GPAMUX1.bit.GPIO2 = 0;
GpioCtrlRegs.GPADIR.bit.GPIO0 = 1; //设置为输出
GpioCtrlRegs.GPADIR.bit.GPIO1 = 1; //设置为输出
GpioCtrlRegs.GPADIR.bit.GPIO2 = 1; //设置为输出*/
EDIS; //寄存器保护结束
/* GpioDataRegs.GPADAT.bit.GPIO0 = 0;
DELAY_US(1);
GpioDataRegs.GPADAT.bit.GPIO1 = 0;
DELAY_US(1);
GpioDataRegs.GPADAT.bit.GPIO2 = 0;*/
DELAY_US(1);
CLEAR_ADRST;
SET_ADCLK;
}
/*void output(void){
EALLOW;
GpioCtrlRegs.GPCMUX1.bit.GPIO79 = 0; //复用为GPIO
GpioCtrlRegs.GPCMUX1.bit.GPIO78 = 0; //复用为GPIO
GpioCtrlRegs.GPCMUX1.bit.GPIO77 = 0; //复用为GPIO
GpioCtrlRegs.GPCDIR.bit.GPIO79 = 0; //设置为输出
GpioCtrlRegs.GPCDIR.bit.GPIO78 = 1; //设置为输入
GpioCtrlRegs.GPCDIR.bit.GPIO77 = 0; //设置为输出
GpioDataRegs.GPCDAT.bit.GPIO78 = 0;
EDIS;
}
*/
void main(void)
{
Uint16 i;
// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the DSP2833x_SysCtrl.c file.
InitSysCtrl();
// Step 2. Initalize GPIO:
// This example function is found in the DSP2833x_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
// InitGpio(); // Skipped for this example
InitXintf16Gpio(); //zq
InitXintf();
// 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 DSP2833x_PieCtrl.c file.
InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();
//output();
EALLOW; // This is needed to write to EALLOW protected registers
PieVectTable.TINT0 = &cpu_timer0_isr;
EDIS; // This is needed to disable write to EALLOW protected registers
// Step 4. Initialize the Device Peripheral. This function can be
// found in DSP2834x_CpuTimers.c
InitCpuTimers(); // For this example, only initialize the Cpu Timers
// Configure CPU-Timer 0, 1, and 2 to interrupt every second:
// 150MHz CPU Freq, 1 second Period (in uSeconds)
ConfigCpuTimer(&CpuTimer0, 150,1000);
IER |= M_INT1;
// Enable TINT0 in the PIE: Group 1 interrupt 7
// Enable TINT0 in the PIE: Group 1 interrupt 7
PieCtrlRegs.PIECTRL.bit.ENPIE = 1;
PieCtrlRegs.PIEIER1.bit.INTx7 = 1;
// Enable global Interrupts and higher priority real-time debug events:
for(i=0;i<8;i++)
testtest[i]=0;
AD7606Init();
SET_ADRST;
DELAY_US(100);
CLEAR_ADRST;
DELAY_US(100);
StartCpuTimer0();
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM
for(;;)
{
if(conv_flg==1)
{
for(i=0;i<8;i++)
AdcSample[i] = (20.0/65536.0)* DOUT[i];//数字量转换为模拟量,输入范围是正负10V,精度为16位
//相当于将20V分成了65536份,公式为A=(20.0/65536.0)*D;A为模拟量值,D为数字量值;
//如果输入范围是正负5V则公式为A=(10.0/65536.0)*D
conv_flg=0;
testSample1[adc_cnt] = AdcSample[0]; //存放每个通道的历史数值
testSample2[adc_cnt] = AdcSample[1];
testSample3[adc_cnt] = AdcSample[2];
testSample4[adc_cnt] = AdcSample[3];
testSample5[adc_cnt] = AdcSample[4];
testSample6[adc_cnt] = AdcSample[5];
testSample7[adc_cnt] = AdcSample[6];
testSample8[adc_cnt] = AdcSample[7];
adc_cnt++;
if(adc_cnt > 255)
adc_cnt = 0;
}
}
}
//===========================================================================
// No more.
//===========================================================================
user5145621:
回复 hellodsp:
不一样的!外设总线是并行的!直接读取相应外设总线地址就可以得到采集数据了!
我想问一下,我不太明白。我使用的外接AD采样是ADI的AD7606,和TI的ADS8568是一样的。dsp是28335,我不太明白,把AD芯片的DB(数据输出口)和dsp的GPIO64-79口连接在一起。是当每次AD采样完成之后,采样的数据就自动送入到dsp28335里面去了吗?那为什么我运行程序之后观察GPCDAT寄存器的值没有变化呢?是不是还需要加上什么通信或者读写指令,和AD连接的GPIO口的GPXDAT寄存器的值才会发生变化?不然,怎么将AD采样完成之后的数据送入dsp呢?
这是我的程序,可以看到,我是把输出的DB接到28335的GPIO64-79端口上,我想通过GPCDAT的值来看DB的数字量的输出。
可是我每次运行完程序,GPCDAT的值总是不变的,一直全部是1,不知道为什么,不是应该GPCDAT应该正确读取AD采样之后的结果吗?还是我哪里理解有问题,希望大佬指教一下
include "DSP2833x_Device.h" // Headerfile Include File
#include "DSP2833x_Examples.h" // Examples Include File
#define AD7656_BASIC (*((volatile Uint16 *)0x4000))
#define SET_ADRST GpioDataRegs.GPBSET.bit.GPIO49=1
#define CLEAR_ADRST GpioDataRegs.GPBCLEAR.bit.GPIO49=1
#define AD_BUSY GpioDataRegs.GPBDAT.bit.GPIO48
#define SET_ADCLK GpioDataRegs.GPBSET.bit.GPIO62=1
#define CLR_ADCLK GpioDataRegs.GPBCLEAR.bit.GPIO62=1
int DOUT[8];
int testtest[8];
float AdcSample[8];
//int test[256];
long sampleCount=0;
float testSample1[256],testSample2[256],testSample3[256],//8个数组存放AD数据
testSample4[256],testSample5[256],testSample6[256],
testSample7[256],testSample8[256];
float gpiodata1[256],gpiodata2[256],gpiodata3[256],
gpiodata4[256],gpiodata5[256],gpiodata6[256],
gpiodata7[256],gpiodata8[256],gpiodata9[256],gpiodata10[256],gpiodata11[256],
gpiodata12[256],gpiodata13[256],gpiodata14[256],gpiodata15[256],gpiodata16[256];
int i;
int testgpio48;
Uint16 adc_cnt=0;
int conv_flg=0;
extern void InitXintf(void);
void chipselect(void)
{
EALLOW;
GpioCtrlRegs.GPBMUX1.bit.GPIO36=2;
GpioCtrlRegs.GPBDIR.bit.GPIO36=1;
EDIS;
}
interrupt void cpu_timer0_isr(void)
{
EDIS;
GpioDataRegs.GPBCLEAR.bit.GPIO36=1;
EALLOW;
SET_ADCLK;//启动转换信号
DELAY_US(1); //给予适当的电平延时
CLR_ADCLK;
DELAY_US(1);
testgpio48=GpioDataRegs.GPBDAT.bit.GPIO48;
EALLOW;
GpioCtrlRegs.GPCMUX1.bit.GPIO79=0;
GpioCtrlRegs.GPCMUX1.bit.GPIO78=0;
GpioCtrlRegs.GPCMUX1.bit.GPIO77=0;
GpioCtrlRegs.GPCMUX1.bit.GPIO76=0;
GpioCtrlRegs.GPCMUX1.bit.GPIO75=0;
GpioCtrlRegs.GPCMUX1.bit.GPIO74=0;
GpioCtrlRegs.GPCMUX1.bit.GPIO73=0;
GpioCtrlRegs.GPCDIR.bit.GPIO79=0;
GpioCtrlRegs.GPCDIR.bit.GPIO78=0;
GpioCtrlRegs.GPCDIR.bit.GPIO77=0;
GpioCtrlRegs.GPCDIR.bit.GPIO76=0;
GpioCtrlRegs.GPCDIR.bit.GPIO75=0;
EDIS;
while(AD_BUSY) //等待转换结束
{
}
for(i=0;i<8;i++)
{
DOUT[i]=AD7656_BASIC; //读取8路AD通道数据
testtest[i]=AD7656_BASIC;
gpiodata1[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO79;
gpiodata2[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO78;
gpiodata3[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO77;
gpiodata4[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO76;
gpiodata5[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO75;
gpiodata6[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO74;
gpiodata7[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO73;
gpiodata8[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO72;
gpiodata9[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO71;
gpiodata10[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO70;
gpiodata11[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO69;
gpiodata12[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO68;
gpiodata13[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO67;
gpiodata14[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO66;
gpiodata15[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO65;
gpiodata16[adc_cnt]=GpioDataRegs.GPCDAT.bit.GPIO64;
}
conv_flg=1;
EALLOW;
// Acknowledge this interrupt to receive more interrupts from group 1
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
EDIS;
}
void AD7606Init(void){
EALLOW; //寄存器保护开启
GpioCtrlRegs.GPBMUX2.bit.GPIO48 = 0; //复用为GPIO
GpioCtrlRegs.GPBMUX2.bit.GPIO49 = 0; //复用为GPIO
GpioCtrlRegs.GPBMUX2.bit.GPIO62 = 0; //复用为GPIO
GpioCtrlRegs.GPBDIR.bit.GPIO49 = 1; //设置为输出
GpioCtrlRegs.GPBDIR.bit.GPIO48 = 0; //设置为输入
GpioCtrlRegs.GPBDIR.bit.GPIO62 = 1; //设置为输出
/* GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 0; //复用为GPIO
GpioCtrlRegs.GPAMUX1.bit.GPIO1 = 0;
GpioCtrlRegs.GPAMUX1.bit.GPIO2 = 0;
GpioCtrlRegs.GPADIR.bit.GPIO0 = 1; //设置为输出
GpioCtrlRegs.GPADIR.bit.GPIO1 = 1; //设置为输出
GpioCtrlRegs.GPADIR.bit.GPIO2 = 1; //设置为输出*/
EDIS; //寄存器保护结束
/* GpioDataRegs.GPADAT.bit.GPIO0 = 0;
DELAY_US(1);
GpioDataRegs.GPADAT.bit.GPIO1 = 0;
DELAY_US(1);
GpioDataRegs.GPADAT.bit.GPIO2 = 0;*/
DELAY_US(1);
CLEAR_ADRST;
SET_ADCLK;
}
/*void output(void){
EALLOW;
GpioCtrlRegs.GPCMUX1.bit.GPIO79 = 0; //复用为GPIO
GpioCtrlRegs.GPCMUX1.bit.GPIO78 = 0; //复用为GPIO
GpioCtrlRegs.GPCMUX1.bit.GPIO77 = 0; //复用为GPIO
GpioCtrlRegs.GPCDIR.bit.GPIO79 = 0; //设置为输出
GpioCtrlRegs.GPCDIR.bit.GPIO78 = 1; //设置为输入
GpioCtrlRegs.GPCDIR.bit.GPIO77 = 0; //设置为输出
GpioDataRegs.GPCDAT.bit.GPIO78 = 0;
EDIS;
}
*/
void main(void)
{
Uint16 i;
// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the DSP2833x_SysCtrl.c file.
InitSysCtrl();
// Step 2. Initalize GPIO:
// This example function is found in the DSP2833x_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
// InitGpio(); // Skipped for this example
InitXintf16Gpio(); //zq
InitXintf();
// 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 DSP2833x_PieCtrl.c file.
InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();
//output();
EALLOW; // This is needed to write to EALLOW protected registers
PieVectTable.TINT0 = &cpu_timer0_isr;
EDIS; // This is needed to disable write to EALLOW protected registers
// Step 4. Initialize the Device Peripheral. This function can be
// found in DSP2834x_CpuTimers.c
InitCpuTimers(); // For this example, only initialize the Cpu Timers
// Configure CPU-Timer 0, 1, and 2 to interrupt every second:
// 150MHz CPU Freq, 1 second Period (in uSeconds)
ConfigCpuTimer(&CpuTimer0, 150,1000);
IER |= M_INT1;
// Enable TINT0 in the PIE: Group 1 interrupt 7
// Enable TINT0 in the PIE: Group 1 interrupt 7
PieCtrlRegs.PIECTRL.bit.ENPIE = 1;
PieCtrlRegs.PIEIER1.bit.INTx7 = 1;
// Enable global Interrupts and higher priority real-time debug events:
for(i=0;i<8;i++)
testtest[i]=0;
AD7606Init();
SET_ADRST;
DELAY_US(100);
CLEAR_ADRST;
DELAY_US(100);
StartCpuTimer0();
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM
for(;;)
{
if(conv_flg==1)
{
for(i=0;i<8;i++)
AdcSample[i] = (20.0/65536.0)* DOUT[i];//数字量转换为模拟量,输入范围是正负10V,精度为16位
//相当于将20V分成了65536份,公式为A=(20.0/65536.0)*D;A为模拟量值,D为数字量值;
//如果输入范围是正负5V则公式为A=(10.0/65536.0)*D
conv_flg=0;
testSample1[adc_cnt] = AdcSample[0]; //存放每个通道的历史数值
testSample2[adc_cnt] = AdcSample[1];
testSample3[adc_cnt] = AdcSample[2];
testSample4[adc_cnt] = AdcSample[3];
testSample5[adc_cnt] = AdcSample[4];
testSample6[adc_cnt] = AdcSample[5];
testSample7[adc_cnt] = AdcSample[6];
testSample8[adc_cnt] = AdcSample[7];
adc_cnt++;
if(adc_cnt > 255)
adc_cnt = 0;
}
}
}
//===========================================================================
// No more.
//===========================================================================
hellodsp:
回复 user5145621:
yang yang54
不一样的!外设总线是并行的!直接读取相应外设总线地址就可以得到采集数据了!