控制TI的TDC7200,使用N32G435单片机,写入可以,但读取不行
[复制链接]
测试写入TDC7200寄存器数据,波形正常,且正常写入,TDC7200工作。
但是读取TDC7200寄存器数值就出现一直是0的情况,也将N32G单片机的SPI输入输出短接测试过,可以写入和读出。
排SPI问题后,只剩TDC7200配置上,但是读寄存器除了要发送读命令也没其他操作了,实在查不出是什么原因,求大佬帮忙看看。
如下是部分代码:
/*********************************************
函数: void TDC7200_WriteByte(uint8_t addr, uint8_t data)
描述: TDC7200写寄存器数据.
参数: none
返回: none
版本: V1.0, 2025-1-8
**********************************************/
void TDC7200_WriteByte(uint8_t addr, uint8_t data)
{
uint16_t address;
uint8_t Rd_Data;
address = (0x40 | addr);
SPI_CS_L_TDC7200();
SPI_WriteByte(address); //写地址命令
SPI_WriteByte(data); //写数据
Rd_Data = SPI_ReadByte(); //回读寄存器数值
SPI_CS_H_TDC7200();
}
/*********************************************
函数: uint8_t TDC7200_ReadByte(uint8_t addr)
描述: TDC7200读寄存器.
参数: none
返回: none
版本: V1.0, 2025-1-8
**********************************************/
uint8_t TDC7200_ReadByte(uint8_t addr)
{
uint8_t Rd_Data;
SPI_CS_H_TDC7200();
SPI_CS_L_TDC7200();
SPI_WriteByte(addr);
Delay(8000); //延时1ms
Rd_Data = SPI_ReadByte();
SPI_CS_H_TDC7200();
return Rd_Data;
}
/*********************************************
函数: void TDC7200_Config(void)
描述: TDC7200初始化.
参数: none
返回: none
版本: V1.0, 2025-1-8 xudx
**********************************************/
void TDC7200_Config(void)
{
TDC7200_WriteByte(CONFIG1, DATA_CONFIG1);
TDC7200_Read[0] = TDC7200_ReadByte(CONFIG1);
TDC7200_WriteByte(CONFIG2, DATA_CONFIG2);
TDC7200_Read[1] = TDC7200_ReadByte(CONFIG2);
TDC7200_WriteByte(INT_MASK, DATA_INT_MASK);
TDC7200_Read[2] = TDC7200_ReadByte(INT_MASK);
TDC7200_WriteByte(COARSE_CNTR_OVF_H, DATA_COARSE_CNTR_OVF_H);
TDC7200_Read[3] = TDC7200_ReadByte(COARSE_CNTR_OVF_H);
TDC7200_WriteByte(COARSE_CNTR_OVF_L, DATA_COARSE_CNTR_OVF_L);
TDC7200_Read[4] = TDC7200_ReadByte(COARSE_CNTR_OVF_L);
}
/*********************************************
函数: void TDC7200_ReadTOF(void)
描述: TDC7200读取TOF时间.
参数: none
返回: none
版本: V1.0, 2025-1-8 xudx
**********************************************/
void TDC7200_ReadTOF(void)
{
TDC7200_WriteByte(CONFIG1, DATA_CONFIG1_START);
TDC7200_Read[0] = TDC7200_ReadByte(CONFIG1);
TDC7200_Timer1 = TDC7200_ReadByte(TIME1);
TDC7200_Clock_Count1 = TDC7200_ReadByte(CLOCK_COUNT1);
TDC7200_Timer2 = TDC7200_ReadByte(TIME2);
TDC7200_Calibration1 = TDC7200_ReadByte(CALIBRATION1);
TDC7200_Calibration2 = TDC7200_ReadByte(CALIBRATION2);
}
//TDC7200 config data
#define DATA_CONFIG1 0x02
#define DATA_CONFIG2 0x10
#define DATA_INT_STATUS 0x00
#define DATA_INT_MASK 0x01
#define DATA_COARSE_CNTR_OVF_H 0xFF
#define DATA_COARSE_CNTR_OVF_L 0xFF
#define DATA_CONFIG1_START 0x83
|