本帖最后由 huiyong828 于 2022-3-18 22:32 编辑
大家好,第一次使用AD7190做压力传感器模数转换,初始化函数如下:
//---------------------------------
//void WriteToAD7190(unsigned char count,unsigned char *buf);
//---------------------------------
//Function that writes to the AD7190 via the SPI port.
//--------------------------------------------------------------------------------
void WriteToAD7190(uint8_t count, uint8_t *buf)
{
CS_LAT = 0;
SPI_WriteBlock(buf,count);
CS_LAT = 1;
}
//---------------------------------
//void ReadFromAD7190(unsigned char count,unsigned char *buf)
//---------------------------------
//Function that reads from the AD7190 via the SPI port.
//--------------------------------------------------------------------------------
void ReadFromAD7190(uint8_t count, uint8_t *buf)
{
CS_LAT = 0;
SPI_ReadBlock(buf,count);
CS_LAT = 1;
}
//
void AD7190_init(void)
{
uint8_t buf[4] = {0,0,0,0};
buf[2] = 0xFF; //
buf[1] = 0xFF; //
buf[0] = 0xFF; //
WriteToAD7190(3,buf); //
WriteToAD7190(3,buf); //
WriteToAD7190(3,buf); //复位
__delay_us(1000); //延时800uS
buf[0] = 0x10; //设置配置寄存器
WriteToAD7190(1,buf); //写入通信寄存器0x10以控制写入配置寄存器的进度
buf[0] = 0x00; //外部基准源Vrl- Vrl+ ,禁止斩波
buf[1] = 0x02; //正输入端AIN3 负输入端AIN4
buf[2] = 0x07; //增益选择128,双极性工作模式,模拟输入端无缓冲器,禁用基准电压检测功能
WriteToAD7190(3,buf); //写入配置寄存器,双极操作,增益=128,通道:AIN3至AIN4
buf[0] = 0x08; //设置模式寄存器
WriteToAD7190(1,buf); //写入通信寄存器0x08以控制写入模式寄存器的进度
buf[1] = 0x02; //外部晶振4.92MHz,工作模式:连续转换模式
buf[1] = 0x03; //sinc滤波器为50Hz,不校验
buf[2] = 0xFF; //输入数据速率4.7Hz
WriteToAD7190(3,buf); //写入模式寄存器,外部4.92MHz时钟,输出数据速率=4.7Hz
buf[0] = 0x48; //读模式寄存器
WriteToAD7190(1,buf); //写入通信寄存器0x48以控制读取配置寄存器的进度
ReadFromAD7190(3,buf); //读取模式寄存器
NOP();
buf[0] = 0x50;
WriteToAD7190(1,buf); //写入通信寄存器0x50以控制读取配置寄存器的进度
ReadFromAD7190(3,buf); //读取配置寄存器
NOP();
buf[0] = 0x40;
WriteToAD7190(1,buf); //写入通信寄存器0x50以控制读取配置寄存器的进度
ReadFromAD7190(3,buf); //读取状态寄存器
NOP();
buf[0] = 0x5C;
WriteToAD7190(1,buf); //写入通信寄存器0x5C以控制读取数据寄存器的进度
ReadFromAD7190(3,buf); //读取数据寄存器
buf[0] = 0x00;
WriteToAD7190(1,buf); //写入通信寄存器0x58以控制读取数据寄存器的进度
ReadFromAD7190(3,buf); //读取状态寄存器
NOP();
}
采用硬件SPI接口,逻辑分析仪读取寄存器数据全是0
哪位朋友用过这个片子,帮忙看下问题出在哪里,谢谢
郑州吴慧勇
|