tlv5620的硬件接线如图,参考电压(2,3,4,5)和VDD接的是dsp的3.3V端,(6,7)接到dsp2812的SPISIMO口和SPICLK口,但实际测得参考电压只有2.2V,求教
以下是相关程序:
#define SetLOAD GpioDataRegs.GPADAT.bit.GPIOA15=1; //将LOAD置高
#define ClrLOAD GpioDataRegs.GPADAT.bit.GPIOA15=0; //将LOAD置低
int QQ=100,QA=0;
void main(void)
{
InitSysCtrl();
DINT;
IER = 0x0000;
IFR = 0x0000;
InitPieCtrl();
InitPieVectTable();
InitGpio();
spi_init();
EINT;
ERTM;
SetLOAD;
while(1)
{
//temp=47;//REF=2.2V;VO(DACA|B|C|D) =REF* CODE/256
WriteDAC(0,QA,QQ); //0.4V
WriteDAC(1,QA,QQ); //0.8V
WriteDAC(2,QA,QQ); //1.2V
WriteDAC(3,QA,QQ); //1.6V
// delay(1000);
}
}
//===========================================================================
// No more.
//===========================================================================
void InitGpio(void)
{
EALLOW;
GpioMuxRegs.GPAMUX.all=0x0000;
GpioMuxRegs.GPADIR.all=0xFFFF; // upper byte as output/low byte as input
GpioMuxRegs.GPAQUAL.all=0x0000; // Input qualifier disabled
// Set GPIO B port pins, configured as EVB signals
// Input Qualifier =0, none
// Set bits to 1 to configure peripherals signals on the pins
GpioMuxRegs.GPFMUX.bit.SPICLKA_GPIOF2=1;
GpioMuxRegs.GPFMUX.bit.SPISIMOA_GPIOF0=1;
}
void WriteDAC(unsigned char add,unsigned char rng,unsigned char vol)
{
unsigned short int data;
data=0x0000;
///大家要知道这里所定义的各个变量的含义,add是4个通道的地址(00,01,10,11)
/// RNG是输出范围的倍数,可以是0或1。
/// VOL是0~256数据
data = ((add<<14) | (rng<<13) | (vol<<5));
//注意这里的有效数据是11位,SPI初始化中也进行了定义
while(SpiaRegs.SPISTS.bit.BUFFULL_FLAG ==1); //判断SPI的发送缓冲区是否是空的,等于0可写数据
SpiaRegs.SPITXBUF = data; //把发送的数据写如SPI发送缓冲区
while( SpiaRegs.SPISTS.bit.BUFFULL_FLAG==1); //当发送缓冲区出现满标志位时,开始琐存数据
delay(1500);//同通过一负跳变琐存要发送的数据,看TLV5620数据手册即可得知
ClrLOAD;//给个下降沿更新DAC输出
delay(150);
SetLOAD;//LOAD置1重新输入数据
delay(1500);
}
void delay(unsigned int t)
{
while(t>0)
t--;
}
//初始化SPI函数
void spi_init()
{
SpiaRegs.SPICCR.all =0x0a;///进入初始状态,数据在上升沿输出,自测禁止,11位数据模式
SpiaRegs.SPICTL.all =0x0006; // 使能主机模式,正常相位,使能主机发送,禁止接收
//溢出中断,禁止SPI中断;
SpiaRegs.SPIBRR =0x0031; //SPI波特率=37.5M/50 =0.75MHZ;
SpiaRegs.SPICCR.all =0x8a; //退出初始状态;
SpiaRegs.SPIPRI.bit.FREE = 1; // 自由运行
}