最近几个星期一直在调TI的ADC芯片,都跳了两个星期了,一直未有斩获,有中断产生,但是出来的数据一直都是全0,附代码
#include<stm32f10x.h>
#include"tlc3574.h"
u16 CHx_value=0;
void Tlc3574_delay_us(u8 t) //2us
{
u8 i,j;
for(j=t;j>0;j--)
for(i=24;i>0;i--);
}
void Write_Tlc3574(u16 CFR_command) //写命令
{
char i;
u16 tlc3574_temp;
for(i=0;i<16;i++)
{
tlc3574_temp = (CFR_command >> (15-i)) & 0x01;
tlc3574_SCLK_1;
if(tlc3574_temp ==1)
tlc3574_SDI_1;
else
tlc3574_SDI_0;
Tlc3574_delay_us(5);
tlc3574_SCLK_0;
Tlc3574_delay_us(5);
}
}
u16 Tlc3574_Read_FIFO()
{
u8 i;
u16 tlc3574_Read_FIFO_value =0;
// tlc3574_CS_0;
tlc3574_SCLK_0; // HOUJIADE
for(i=0;i<14;i++)
{
tlc3574_SCLK_1;
Tlc3574_delay_us(5);
tlc3574_Read_FIFO_value <<= 1;
if(tlc3574_READdata == 1)
{
tlc3574_Read_FIFO_value += 1;
}
tlc3574_SCLK_0;
Tlc3574_delay_us(10);
}
tlc3574_SCLK_1; //两个低位数据舍弃
// delay
Tlc3574_delay_us(10);
tlc3574_SCLK_0;
// delay
Tlc3574_delay_us(10);
tlc3574_SCLK_1;
// delay
Tlc3574_delay_us(10);
tlc3574_SCLK_0;
Tlc3574_delay_us(10);
return tlc3574_Read_FIFO_value ;
}
void Tlc3574_Init()
{
// tlc3574_CS_1;
// tlc3574_SCLK_0;
// Tlc3574_delay_us(10);
tlc3574_CS_0;
Write_Tlc3574(0xa000); //write SFR command ,write 000H
Tlc3574_delay_us(10);
tlc3574_CS_1;
Tlc3574_delay_us(30);
tlc3574_CS_0;
Write_Tlc3574(0xae00);
Tlc3574_delay_us(10);
tlc3574_CS_1;
}
void Start_sampling()
{
Tlc3574_delay_us(50);
tlc3574_CS_0;
Write_Tlc3574(0x0000);
Tlc3574_delay_us(20);
tlc3574_CS_1;
while(tlc3574_INT);
// Tlc3574_delay_us(100);
// Tlc3574_delay_us(10);
CHx_value=Tlc3574_Read_FIFO() /8192;
}
void Tlc3574_CONV()
{
Tlc3574_Init();
Start_sampling();
} |