就跟TI申請了TLV1571
焊好連接MCU後
卻發現怎麼都讀不到 Registers
仔細看了SPEC後才發現
要先設定 CR1 才能讀回 CR0/CR1的值
所以文件還是要乖乖看
才不會浪費時間 XD
TLV1571 3V-625Ksps
ADC 最快轉換時間公式
Fs(max) = (1/take clk)*Fclk
CLOCK = 10Mhz
TLV1571 need 16clk conversion
Fs = (1/16)*10Mhz
=625000=0.0000016s
#define TLV_DAT P0 //tlv1571 data pin
#define TLV_CS P2_0
#define TLV_WR P2_1
#define TLV_RD P2_2
#define TLV_CLK P2_3
#define TLV_A0 P1_0
#define TLV_A1 P1_1
#define TLV_CSS P1_2 //tlv1571 cstart
void main()
{
unsigned char temp,i,temp1;
GPIO_direct_set(IOP0,0xFF); //P0D = 0xFF; output
GPIO_P0S_set(0xFF); //P0 output cmos
GPIO_attribute_set(IOP0,0xFF); //P0 = 0xFF; output high
GPIO_direct_set(IOP1,0xFF); //P1D = 0xFF; output
GPIO_attribute_set(IOP1,0xFF); //P1 = 0xFF; output high
GPIO_direct_set(IOP2,0xFF); //P2D = 0xFF; output
GPIO_attribute_set(IOP2,0xFF); //P2 = 0xFF; output high
GPIO_direct_set(IOP3,0x00); //P3D = 0x00; input
GPIO_attribute_set(IOP3,0xFF); //P3 = 0xFF; input pull high
while(1)
{
TLV_CS = 0;
TLV_WR = 0;
TLV_A0 = 0; //CR0 REG
TLV_DAT = 0x00;
TLV_A0 = 1; //CR1 REG
TLV_DAT = 0x00;
TLV_WR = 1;
TLV_CS = 1;
GPIO_direct_set(IOP0,0x00);
GPIO_P0S_set(0xFF);
GPIO_attribute_set(IOP0,0xFF);
GPIO_direct_set(IOP1,0xFC);
TLV_CSS = 0; //START CONVERSION
TLV_CSS = 1;
while(P3_2); //WAIT TLV1571 INT PIN
TLV_CS = 0;
TLV_RD = 0;
temp = GPIO_read(IOP0); //READ AD VALUE
temp1 = GPIO_read(IOP1) & 0x03;
TLV_RD = 1;
TLV_CS = 1;
}
}
這不是標準的8051程式
但用法差不多
請自行理解吧...XD
沒有留言:
張貼留言