花了一周时间也没把
ad7192的程序调通,
MCU使用的是
STC12C5A60S2模拟
SPI,目前的问题低速可以采集,速度高就没有数据发出了,起初怀疑是时序问题,示波器观察输入没啥问题,使用的是连续转换模式,而且还遇到一个见鬼的问题就是低速时,上电复位
单片机收不到数据,每次必须按下
RESET复位,
ADC才有信号发出。下图就是分别上电复位(上)和
RST复位(下)的截图,
DOUT绿色,
DIN黄色,
SCLK蓝色。
CS一直是低电平,没采集。图中的
8个字节分别是写入模式和配置寄存器。从示波器看唯一区别就是
DOUT输出的变化,这对
write寄存器有影响吗?,目前上图就无法工作。下图就可以。后面附具体程序,求各位赐教。
最后还有一个问题:
ad7190和
ad7192有啥区别,看
datasheet没找出来。目前是拿
ad7192调试的,官方给的程序也改成手头单片机的了,还是没有任何反应。
#include"STC12C5A60S2.h"
#include"uart.h"
#include"Pin.h"
***it CS = Port1;
***it SCLK = Port2;
***it DIN = Port3;
***it DOUT = Port4;
void AD7192Delay(unsigned int count)
{
unsigned int i,j;
for(i=0; i
for(j=0; j<5000; j++);
}
void Write8BitToAD7192(unsigned char dat)
{
unsigned char i;
for(i=0; i<8; i++)
{
SCLK = 0;
if(0x80 == (0x80 & dat))
{
DIN = 1;
}
else
{
DIN = 0;
}
SCLK = 1;
dat <<= 1;
}
DIN = 1; //UartPrintf("te :n");
}
unsigned long Read24BitFromAD7192(void)
{
unsigned char i;
unsigned long readdat = 0;
// while(!DOUT);
// while(DOUT);
for(i=0; i<24; i++)
{
SCLK = 0;
readdat <<= 1;
SCLK = 1;
if(DOUT)
{
readdat += 1;
}
}
return readdat;
}
void AD7192Initial(void)
{
CS = 0;
/* Write8BitToAD7192(0xff);
Write8BitToAD7192(0xff);
Write8BitToAD7192(0xff);
Write8BitToAD7192(0xff);
Write8BitToAD7192(0xff);*/
AD7192Delay(10);
/*配置寄存器:斩波使能关,通道选择AIN3-AIN4,输入缓冲器开,单极性,增益1*/
Write8BitToAD7192(0x10);
Write8BitToAD7192(0x00);
Write8BitToAD7192(0x02);
Write8BitToAD7192(0x10);
Write8BitToAD7192(0x10);
Write8BitToAD7192(0x00);
Write8BitToAD7192(0x02);
Write8BitToAD7192(0x10);
// /*模式寄存器:内部零电平校准*/
// Write8BitToAD7192(0x08);
// Write8BitToAD7192(0x88);
// Write8BitToAD7192(0x0b);
// Write8BitToAD7192(0xff);
// while(DOUT);
// /*模式寄存器:内部满量程校准*/
// Write8BitToAD7192(0x08);
// Write8BitToAD7192(0xa8);
// Write8BitToAD7192(0x0b);
// Write8BitToAD7192(0xff);
// while(DOUT);
// /*模式寄存器:系统零电平校准*/
// Write8BitToAD7192(0x08);
// Write8BitToAD7192(0xc8);
// Write8BitToAD7192(0x0b);
// Write8BitToAD7192(0xff);
// while(DOUT);
// /*模式寄存器:系统满量程校准*/
// Write8BitToAD7192(0x08);
// Write8BitToAD7192(0xe8);
// Write8BitToAD7192(0x0b);
// Write8BitToAD7192(0xff);
// while(DOUT);
/*模式寄存器:连续转换模式,内部时钟,sinc4滤波器,奇偶校验关,单周期转换开,采样率Hz*/
Write8BitToAD7192(0x08);
Write8BitToAD7192(0x08);
// Write8BitToAD7192(0x0b); //采样率4.7Hz
// Write8BitToAD7192(0xff);
Write8BitToAD7192(0x08); //采样率960Hz
Write8BitToAD7192(0x02);
AD7192Delay(5);
// Write8BitToAD7192(0x5c);
// DIN = 0;
AD7192Delay(10);
}
void main(void)
{
unsigned long tmp;
CS = 0;
UartInit();
UartPrintf("test:n");
AD7192Initial();
while(1)
{
while(!DOUT);UartPrintf("test2:n");
while(DOUT);UartPrintf("test3:n");
Write8BitToAD7192(0x58);
tmp = Read24BitFromAD7192();
UartPrintf("%lxn",tmp);
UartPrintf(" %0.2fn",tmp*0.24414064-2048000);
}
}