完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
目前是可以正确读取设备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); [size=200%]AD7190.c: [size=75%] #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; } |
|
相关推荐
1个回答
|
|
从您提供的代码片段来看,AD7195数据寄存器读取为0可能有以下几个原因:
1. 硬件连接问题:请确保SPI接口的连接正确,并且AD7195的信号线与微控制器的信号线匹配。检查时钟、数据和片选线等是否正确连接。 2. 通信设置问题:请确保SPI通信的设置正确。AD7195的通信速度、数据位数、传输模式等设置需要与微控制器的SPI配置匹配。 3. AD7195配置问题:请确保您已正确配置AD7195的寄存器,特别是配置了正确的操作模式、增益和数据速率等参数。在读取数据之前,需要将AD7195配置为所需的操作模式。 4. SPI驱动问题:请确保您的SPI驱动程序正确配置和操作SPI外设。您可以通过调试SPI驱动程序来确保数据正确传输,并检查是否有任何错误或超时。 请逐步检查这些可能的问题,并确保每个步骤都正确。如果问题仍然存在,请提供更多细节或完整的代码,以便能够更好地帮助您解决问题。 |
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
635 浏览 1 评论
586 浏览 0 评论
电路小知识 | 交流电路复数的基础知识以及相位差和电抗的计算
512 浏览 0 评论
1650 浏览 3 评论
1445 浏览 1 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-20 01:39 , Processed in 0.580451 second(s), Total 79, Slave 61 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号