Post Go back to editing

AD7195 数据寄存器读取为0

目前是可以正确读取设备ID 也就是写入读取功能是没问题的。在主程序中AD7190_Data显示为0.

以下是主程序以及spi驱动

MAIN:

#include "main.h"

#include "usart.h"

#include "gpio.h"

/* Private includes ----------------------------------------------------------*/

/* USER CODE BEGIN Includes */

#include "ad7190.h"

/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/

/* USER CODE BEGIN PTD */

uint32_t READ_Data = 0 ;

uint8_t READ_State = 0;

void SystemClock_Config(void);

/* USER CODE BEGIN PFP */

uint32_t AD7190_Data = 0;

float AD7190_Val;

int main(void)

{

HAL_Init();

/* USER CODE BEGIN Init */

/* USER CODE END Init */

/* Configure the system clock */

SystemClock_Config();

/* USER CODE BEGIN SysInit */

/* USER CODE END SysInit */

/* Initialize all configured peripherals */

MX_GPIO_Init();

MX_USART3_UART_Init();

/* USER CODE BEGIN 2 */

v_AD7190_Statrt();

u_AD7190_Get_ID(0x84);//检查ID,,AD7195要该成0Xa6

read_reg();

/* USER CODE END 2 */

/* Infinite loop */

/* USER CODE BEGIN WHILE */

while (1)

{

// GetDifferentialData();

/* write_buf = 0x60;

AD7192ReadWrite(&write_buf,NULL,1);

write_buf = 0x00;

AD7192ReadWrite(&write_buf,&AD7190_ID,1);*/

// LED_TEST();

// v_AD7190_Get_Data();//读数据

while(AD7190_DOUT){};//

AD7190Write(0x58);

AD7190_Data = v_AD7190_Read3Byte();

v_AD7190_Cal(AD7190_Data,&AD7190_Val);

// AD7190Write(0x5c);

// READ_Data = AD7190Read();

// READ_State = AD7190Read_Byte();

HAL_GPIO_TogglePin(GPIOB,GPIO_PIN_0);

HAL_Delay(200);

AD7190.c:

#include "ad7190.h"

uint8_t AD7190_ID;

uint8_t conf_reg[3];

uint8_t mode_reg[3];

uint32_t Data;

void Delay(uint32_t nCount)

{

for(; nCount != 0; nCount--);

}

void LED_TEST(void)//AD7190��ͨ��IO P2�����ӵ�LED������LED��˸

{

AD7190_CS_L;

AD7190Write(0x28);//

AD7190Write(0x24);//

AD7190_CS_H;

Delay(1000000);//Լ0.5S��ʱ

AD7190_CS_L;

AD7190Write(0x28);//

AD7190Write(0x20);//

AD7190_CS_H;

Delay(1000000);

}

void read_reg(void)//��ȡ���üĴ�����ģʽ�Ĵ���������������֤���������Ƿ���ȷд��

{

//��ȡ3Byte���üĴ�������

Delay(100);

AD7190_CS_L;

AD7190Write(0x50);//write communication register 0x50 to control the progress to read configuration register

AD7190_CS_H;

Delay(100);

AD7190_CS_L;

conf_reg[0]=AD7190Read_Byte();

conf_reg[1]=AD7190Read_Byte();

conf_reg[2]=AD7190Read_Byte();

AD7190_CS_H;

//��ȡ3Byteģʽ�Ĵ�������

Delay(100);

AD7190_CS_L;

AD7190Write(0x48);//write communication register 0x50 to control the progress to read configuration register

AD7190_CS_H;

Delay(100);

AD7190_CS_L;

mode_reg[0]=AD7190Read_Byte();

mode_reg[1]=AD7190Read_Byte();

mode_reg[2]=AD7190Read_Byte();

AD7190_CS_H;

}

void AD7190Write(uint8_t Data)

{

uint8_t data;

data=Data;

for(uint8_t i=0;i<8;i++)

{

AD7190_SCLK_L;

if(data&0x80)

AD7190_DIN_H;

else

AD7190_DIN_L;

Delay(100);

AD7190_SCLK_H;

Delay(100);

data<<=1;

}

}

uint32_t AD7190Read(void)

{

uint32_t DATA;

DATA=0;

for(uint8_t i=0;i<24;i++)

{

DATA<<=1;

AD7190_SCLK_L;

Delay(100);

if(AD7190_DOUT)

DATA++;

AD7190_SCLK_H;

Delay(100);

}

Delay(100);

return DATA;

}

uint8_t AD7190Read_Byte(void)

{

uint8_t DATA;

DATA=0;

for(uint8_t i=0;i<8;i++)

{

DATA<<=1;

AD7190_SCLK_L;

Delay(100);

if(AD7190_DOUT)

DATA++;

AD7190_SCLK_H;

Delay(100);

}

Delay(100);

return DATA;

}

void AD7190_Reset(void)

{

AD7190_CS_L;

AD7190_DIN_H;

for(uint8_t a=0;a<50;a++)//�ṩ����40��д��������λAD7190

{

AD7190_SCLK_L;

Delay(100);

AD7190_SCLK_H;

Delay(100);

}

AD7190_CS_H;

}

void AD7190_INIT(void)

{

Delay(100);

AD7190_CS_L;

AD7190Write(0x60);

AD7190_ID=AD7190Read_Byte();//��ȡAD7190 ID = 0xX4

AD7190_CS_H;

Delay(100);

AD7190_CS_L;

AD7190Write(0x10);//配置寄存器

AD7190Write(0x00);//CON23-CON16

AD7190Write(0x02);//CON15-CON8 通道选择

AD7190Write(0x00);//CON7-CON0 0x00:GAIN=1;增益设置

//0x03:GAIN=8;

//0x04:GAIN=16;

//0x07:GAIN=128; (GAIN=128ʱ�����뷶ΧΪ+-39.06mV)

AD7190_CS_H;

Delay(100);

AD7190_CS_L;

AD7190Write(0x08);//模式寄存器

AD7190Write(0x08);//MR23-MR16

AD7190Write(0x00);//MR15-MR8

AD7190Write(0x3f);//MR7-MR0 fs(MR0-MR9) = 0x00ff = 255,�������������Ϊ4920/255=19.2sps

//0x00 0xff��19.2sps

//0x00 0x3f��78sps

//0x00 0x1f��164sps

//0x00 0x0f��328sps

//0x00 0x05��984sps

AD7190_CS_H;

}

void v_AD7190_Statrt(void)

{

AD7190_Reset();//��λAD7190���ֽӿ�

AD7190_INIT();

Delay(100);

AD7190_CS_L;

AD7190Write(0x28);//GPOCONGPIO配置寄存器

AD7190Write(0x24);//P2为高,P3为低

AD7190_CS_H;

Delay(100);

AD7190_CS_L;

}

void v_AD7190_Get_Data(void)

{

while(AD7190_DOUT){};//

AD7190Write(0x58);

Data=AD7190Read();//Data

}

void u_AD7190_Get_ID(uint8_t id)

{

while(1)

{

Delay(100);

AD7190_CS_L;

AD7190Write(0x60);

AD7190_ID=AD7190Read_Byte();//��ȡAD7190 ID = 0xX4

AD7190_CS_H;

Delay(100);

if(AD7190_ID == id)

{

HAL_GPIO_WritePin(GPIOB, LD3_Pin, GPIO_PIN_SET);

break;

}

}

}

uint32_t v_AD7190_Read3Byte(void)

{

uint32_t Temp=0;

uint8_t Buf[3];

Buf[0] = AD7190Read_Byte();

Buf[1] = AD7190Read_Byte();

Buf[2] = AD7190Read_Byte();

return Temp = ((uint32_t)Buf[0]<<16) | ((uint32_t)Buf[1]<<8) | Buf[2];

}

void v_AD7190_Cal(uint32_t AD_Reg,float *Data)

{

*Data = ((float)AD_Reg/8388608 - 1)*AD7190_VREF/AD7190_GAIN;

}

还请工程师们解答。