微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 硬件电路设计 > TI模拟硬件电路设计 > ADS1258通过SPI接口与STM32F103进行通信

ADS1258通过SPI接口与STM32F103进行通信

时间:10-02 整理:3721RD 点击:

请教各位技术大牛:

        STM32F103与ADS1258之间仅通过SPI的三根线进行连接。软件程序中STM32F103通过SPI发送ADS1258的配置信息给ADS1258。我是按照手册中提供的配置向导部分给的步骤进行配置的。具体配置如下:

void ADS1258_Init(void)
{
// SendDataToADS1258(0x80);//停止转换
while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);
SPI_I2S_SendData(SPI1,0x80); //停止转换
AD_Delay();

while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);
SPI_I2S_SendData(SPI1,0xC0); //复位SPI
AD_Delay();

//----------------------------------------------------------------------
while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);//Transmit buffer empty flag
SPI_I2S_SendData(SPI1,0x60); //选择寄存器CONFIG0
AD_Delay();
while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);
SPI_I2S_SendData(SPI1,0x42); //自动扫描模式,CHOP=0
AD_Delay();

//----------------------------------------------------------------------
while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);
SPI_I2S_SendData(SPI1,0x61); //选择寄存器CONFIG1
AD_Delay();
while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);
SPI_I2S_SendData(SPI1,0x03); //转换延时时间为8us,数据传输速率为:23739 SPS,见数据手册中表5
AD_Delay();

//----------------------------------------------------------------------
while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);
SPI_I2S_SendData(SPI1,0x62); //选择寄存器MUXSCH
AD_Delay();
while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);
SPI_I2S_SendData(SPI1,0x00); //禁用差分通道
AD_Delay();
//----------------------------------------------------------------------
while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);
SPI_I2S_SendData(SPI1,0x63); //选择寄存器MUXDIF
AD_Delay();
while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);
SPI_I2S_SendData(SPI1,0x00); //未选用差分通道
AD_Delay();

//----------------------------------------------------------------------
while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);
SPI_I2S_SendData(SPI1,0x64); //选择寄存器MUXSG0
AD_Delay();
while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);
SPI_I2S_SendData(SPI1,0xFF);
AD_Delay();

//----------------------------------------------------------------------
while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);
SPI_I2S_SendData(SPI1,0x65); //选择寄存器MUXSG1
AD_Delay();
while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);
SPI_I2S_SendData(SPI1,0xFF);
AD_Delay();

//----------------------------------------------------------------------
while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);
SPI_I2S_SendData(SPI1,0x66); //选择寄存器SYSRED
AD_Delay();

while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);
SPI_I2S_SendData(SPI1,0x00); //0x3D读取参考基准、增益、温度、电压、偏移

//----------------------------------------------------------------------
while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);
SPI_I2S_SendData(SPI1,0x67); //GPIO配置寄存器GPIOC
AD_Delay();

while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);
SPI_I2S_SendData(SPI1,0x00); //GPIO引脚作为输出

//----------------------------------------------------------------------
while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);
SPI_I2S_SendData(SPI1,0x68); //GPIO数据寄存器GPIOD
AD_Delay();

while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);
SPI_I2S_SendData(SPI1,0x00); //GPIO的数据为逻辑低电平

//----------------------------------------------------------------------
while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);
SPI_I2S_SendData(SPI1,0x69); //设备ID寄存器ID
AD_Delay();

while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);
SPI_I2S_SendData(SPI1,0x8B); //只能读
}

然后我再读寄存器的值时,回读的寄存器数据全为0xff。我想请问一下,上述函数中的设置是否有问题?另外想知道什么原因导致回读的寄存器数据不对?谢谢各位啦!

读出全 0xFF, 很可能是硬件连接问题, 或者供电和复位问题, 先检查一下低级错误吧

检查了一下,AVDD为4.775V,AVSS为0。参考电压REFN=4.75V,REFP=0V。选择单通道输入。复位引脚没接。现在是STM32的SPI时钟引脚和MOSI引脚都有数据输出,就是MISO引脚暂时无数据。有时为0xFF,有时为0x00。不知道还有哪些地方容易导致这样的问题呢?请教大侠指点一下,不胜感激!

这是时钟引脚和STM32的MOSI引脚波形:MOSI发送0x80

这是时钟引脚和STM32的MISO引脚波形:

怎么接收的数据为0xFF呢?

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top