设置如下:
ENTDC一直为高电平。置高电平后有足够的延时。
SetClockCntrStopMask(400); //40us以后才开始采集停止信号
TDC_CS_L;
WriteTDC7200(0x01); //addr
WriteTDC7200(0x40); //single stop, 1 measure cycle only, measure 10 clock period
TDC_CS_H;
TDC_CS_L;
WriteTDC7200(0x00); //addr
WriteTDC7200(0x8b); //callibration, no parity, trig、start rising edge, stop falling edge, mode 2, start measure TDC_CS_H;
读数据如下:
TDC_CS_L;
WriteTDC7200(0x10); //addr
MeaTime1=Read24bitTDC7200();
TDC_CS_H;
TDC_CS_L;
WriteTDC7200(0x11); //addr
ClockCntr1=Read24bitTDC7200();
TDC_CS_H;
TDC_CS_L;
WriteTDC7200(0x12); //addr
MeaTime2=Read24bitTDC7200();
TDC_CS_H;
TDC_CS_L;
WriteTDC7200(0x1b); //addr
Calibration1=Read24bitTDC7200();
TDC_CS_H;
TDC_CS_L;
WriteTDC7200(0x1c); //addr
Calibration2=Read24bitTDC7200();
TDC_CS_H;
SPI驱动如下:
void WriteTDC7200(uint8_t dat)
{
uint8_t i;
for(i=0;i<8;i++)
{
TDC_CLK_L;
if((0x80&dat)==0x80)
TDC_DI_H;
else
TDC_DI_L;
TDC_CLK_H;
dat=dat<<1;
}
}
uint8_t Read8bitTDC7200(void)
{
uint8_t i;
uint8_t dat=0;
uint32_t val;
TDC_CLK_H;
for(i=0;i<8;i++)
{
TDC_CLK_L;
dat=dat<<1;
val=GPIO_ReadValue(TDC_DO_PORT);
val=val & (1<<TDC_DO_PIN);
if(val==(1<<TDC_DO_PIN))
dat++;
TDC_CLK_H;
}
return(dat);
}
uint32_t Read24bitTDC7200(void)
{
uint8_t i;
uint32_t dat=0;
uint32_t val;
TDC_CLK_H;
for(i=0;i<24;i++)
{
TDC_CLK_L;
dat=dat<<1;
val=GPIO_ReadValue(TDC_DO_PORT);
val=val & (1<<TDC_DO_PIN);
if(val==(1<<TDC_DO_PIN))
dat++;
TDC_CLK_H;
}
return(dat);
}
没有启用中断信号。在延时500us后,读取寄存器的值。START和STOP信号都很干净。
问题出在哪呢?
david fan:
写命令的时候地址忘记加0x40了。加上0x40后,读出的数据全是0x00FFFFFF
david fan:
回复 david fan:
读的时候也加上0x40,结果出错了。写加0X40,读不能加0X40。问题解决了。
Annie Liu:
回复 david fan:
感谢您对TI产品的关注!
很高兴您的问题已经解决,并且谢谢您的分享。