完善资料让更多小伙伴认识你,还能领取20积分哦,立即完善>
朋友们好 ,我最近在做 ads1247 这个芯片 我的SPI通讯是正常的 能够正确都出我写入的寄存器的值,但是读的书不正确 附上我的
电路图 和 测试波形 请问 这种情况 是怎么回事 啊 我测了差分输入和电压基准输入都没问题的 我的电阻计算公式是 RTD=(D24*820)/(Gain*8388608);
#include "ADS1247FUNC tiON.h" #include "usart1.h" #include "BSP_LED.H" char Reg_cmd; uint8_t WaitBusy() { char i; i = 0; while(ADS1247_DRDY_Val) { i++; if(i > 20) return 1; } return 0; } void ADS1247_init(void) //ζȳõʼ»¯ { ADS1247_CS_0; /****Ïȸ´Î»****/ ADS1247_WriteCmd(ADC_CMD_RESET); ADS1247_CS_1; delay_ms(50); //ÖÁÉÙ0.6ms Reg_cmd=0x0a; // AIN1¡¢AIN2·Ö±ðÉèÖÃΪ²ÉÑùÕý¸ºÊäÈë¶Ë ADS1247_CS_0; Delay(50); ADS1247_WriteCmd(ADC_CMD_WREG|ADS1247_REG_MUX0); ADS1247_WriteCmd(0x00); ADS1247_WriteCmd(Reg_cmd); ADS1247_CS_1; Reg_cmd=0x00; ADS1247_CS_0; Delay(50); ADS1247_WriteCmd(ADC_CMD_WREG|ADS1247_REG_VBIAS);//¹Ø±ÕÆ«Öõçѹ ADS1247_WriteCmd(0x00); ADS1247_WriteCmd(Reg_cmd); ADS1247_CS_1; Reg_cmd=0x20; //Ñ¡ÔñÄÚ²¿²Î¿¼µçѹ ADS1247_CS_0; Delay(50); ADS1247_WriteCmd(ADC_CMD_WREG|ADS1247_REG_MUX1); ADS1247_WriteCmd(0x00); ADS1247_WriteCmd(Reg_cmd); ADS1247_CS_1; Reg_cmd=0x20; //ÔöÒæ ²ÉÑùÂÊΪ ºóÐøÐÞ¸ÄÕâ¸öÖµ½øÐе÷ÊÔ ADS1247_CS_0; Delay(50); ADS1247_WriteCmd(ADC_CMD_WREG|ADS1247_REG_SYS0); ADS1247_WriteCmd(0x00); ADS1247_WriteCmd(Reg_cmd); ADS1247_CS_1; Reg_cmd=0x0E; //ÉèÖÃIDAC0Ϊ1mA ¸´ÓÃDOUT/DRDYÒý½Å ADS1247_CS_0; Delay(50); ADS1247_WriteCmd(ADC_CMD_WREG|ADS1247_REG_IDAC0); ADS1247_WriteCmd(0x00); ADS1247_WriteCmd(Reg_cmd); ADS1247_CS_1; Reg_cmd=0x03; //AIN0ΪµÚÒ»µçÁ÷Ô´Êä³ö AIN3ΪµÚ¶þµçÁ÷Ô´Êä³ö ADS1247_CS_0; Delay(50); ADS1247_WriteCmd(ADC_CMD_WREG|ADS1247_REG_IDAC1); ADS1247_WriteCmd(0x00); ADS1247_WriteCmd(Reg_cmd); ADS1247_CS_1; /*¶Á¼Ä´æÆ÷Öµ²¢ÏÔʾ³öÀ´*/ uint16_t MUX0,VBIAS,MUX1,SYS0,IDAC0,IDAC1; ADS1247_CS_0; //¸´Î»ºóÒªÏÈÑÓʱ ÖÁÉÙ10ns Delay(50); WaitBusy(); ADS1247_WriteCmd(ADC_CMD_RREG|ADS1247_REG_MUX0); ADS1247_WriteCmd(0x00); MUX0=ADS1247_ReadCmd(ADC_CMD_NOP); WaitBusy(); ADS1247_WriteCmd(ADC_CMD_RREG|ADS1247_REG_VBIAS); ADS1247_WriteCmd(0x00); VBIAS=ADS1247_ReadCmd(ADC_CMD_NOP); WaitBusy(); ADS1247_WriteCmd(ADC_CMD_RREG|ADS1247_REG_MUX1); ADS1247_WriteCmd(0x00); MUX1=ADS1247_ReadCmd(ADC_CMD_NOP); WaitBusy(); ADS1247_WriteCmd(ADC_CMD_RREG|ADS1247_REG_SYS0); ADS1247_WriteCmd(0x00); SYS0=ADS1247_ReadCmd(ADC_CMD_NOP); WaitBusy(); ADS1247_WriteCmd(ADC_CMD_RREG|ADS1247_REG_IDAC0); ADS1247_WriteCmd(0x00); IDAC0=ADS1247_ReadCmd(ADC_CMD_NOP); WaitBusy(); ADS1247_WriteCmd(ADC_CMD_RREG|ADS1247_REG_IDAC1); ADS1247_WriteCmd(0x00);//Í˳ö˯Ãßģʽ IDAC1=ADS1247_ReadCmd(ADC_CMD_NOP); printf("rn MUX0 %x", MUX0);//Êä³ö16½øÖÆÎÞ·ûºÅÕûÊý printf("rn VBIAS %x", VBIAS); printf("rn MUX1 %x", MUX1); printf("rn SYS0 %x", SYS0);//Êä³ö16½øÖÆÎÞ·ûºÅÕûÊý printf("rn IDAC0 %x", IDAC0); printf("rn IDAC1 %x", IDAC1); ADS1247_WriteCmd(ADC_CMD_NOP); ADS1247_CS_1; } void SPI1_ReadReg(char RegAddr,char *Buffer,char Length) { char Cmd[2]; ADS1247_CS_0; Cmd[0]=ADC_CMD_RREG|RegAddr; Cmd[1]=Length-1; SPI1_WriteBytes(Cmd,2); SPI1_ReadBytes(Buffer,Length); /******·¢Ò»¸öNOPÃüÁî¿ÉÒÔÇ¿ÖÆDOUTÒý½ÅÊä³ö¸ßµçƽ******/ Cmd[0]=ADC_CMD_NOP; SPI1_WriteBytes(Cmd,1); ADS1247_CS_1; } void SPI1_WriteReg(char RegAddr,char *Buffer,char Length) { char Cmd[2]; ADS1247_CS_0; Cmd[0]=ADC_CMD_WREG|RegAddr; Cmd[1]=Length-1; SPI1_WriteBytes(Cmd,2); SPI1_WriteBytes(Buffer,Length); /******·¢Ò»¸öNOPÃüÁî¿ÉÒÔÇ¿ÖÆDOUTÒý½ÅÊä³ö¸ßµçƽ******/ //Cmd[0]=ADC_CMD_NOP; //SPI1_WriteBytes(Cmd,1); ADS1247_CS_1; } void SPI1_WriteBytes(char *TxBuffer,char TxLenth) { char Temp=0; while(TxLenth--) { while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET); SPI1->DR=*TxBuffer++; while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET); Temp=(char)SPI1->DR; //ÕâÒ»²½ÊÇʲôÒâ˼ } Temp++; //±ÜÃâkeil-MKD²úÉú±àÒ뾯¸æ } void SPI1_ReadBytes(char *RxBuffer,char RxLenth) { while(RxLenth--) { while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET); SPI1->DR=*RxBuffer; while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET); *RxBuffer++=(char)SPI1->DR; } } char ADS1247_ReadCmd(char Cmd) { while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET); SPI1->DR=Cmd; while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET); return SPI_I2S_ReceiveData(SPI1); } char ADS1247_Return_read_val(char Cmd) //cx AD²ÉÑù¶ÁÊý¾ÝÓõĺ¯Êý { while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET); SPI1->DR=Cmd; while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET); return SPI_I2S_ReceiveData(SPI1); } void ADS1247_WriteCmd(char Cmd) { char Temp; while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);//µÈ´ý·¢ËÍ»º³åÇøΪ¿ÕTXEʼþ SPI1->DR=Cmd; while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET);//µÈ´ý½ÓÊÕ»º³åÇøΪ¿Õ Temp=(char)SPI1->DR; //ÕâÒ»²½ÊÇʲôÒâ˼ ÕâÒ»²½ÊǶÁÈ¡·µ»ØÀ´µÄÊý¾Ý Temp++; //±ÜÃâkeil-MKD²úÉú±àÒ뾯¸æ //ADS1247_CS_1; } // AD¶ÁÊý¾Ý //uint32_t ADS1247_Read_once(void) //{ // // uint32_t T_D24,RTD; // char Return_val[4]; // char DATA_Cmd = ADC_CMD_RDATA; // //Cmd[0]=ADC_CMD_RDATAC; // Return_val[0] = ADC_CMD_NOP; // Return_val[1] = ADC_CMD_NOP; // Return_val[2] = ADC_CMD_NOP; // Return_val[3] = ADC_CMD_NOP; // // ADS1247_CS_0; // delay_us(50); // SPI1_WriteBytes(&DATA_Cmd,1); // while(WaitBusy()); //Á¬Ðøģʽ¿ÉÄÜÓõ½ // // Return_val[0] = ADS1247_Return_read_val(ADC_CMD_NOP); // Return_val[1] = ADS1247_Return_read_val(ADC_CMD_NOP); // Return_val[2] = ADS1247_Return_read_val(ADC_CMD_NOP); // Return_val[3] = ADS1247_Return_read_val(ADC_CMD_NOP); // // ADS1247_CS_1; // // T_D24 = (Return_val[0]<<16) | (Return_val[1]<<8) | Return_val[2];//SPIÒ»´ÎͨѶֻÄÜ·µ»ØÒ»¸ö×Ö½ÚµÄÊý¾Ý // T_D24 &= 0x00FFFFFF;//ADÊÇ24λоƬ È¡³ö24λÊý¾Ý // RTD=(205*T_D24)/16777216; // printf("rn RTD %d", RTD); //} uint32_t ADS1247_Read_once(void) { //GPIO_ResetBits(GPIOC, GPIO_Pin_11); uint32_t D24,RTD,T; uint32_t Return_val_0,Return_val_1,Return_val_2,Return_val_3; // Return_val_1=ADC_CMD_NOP; // Return_val_2=ADC_CMD_NOP; // Return_val_3=ADC_CMD_NOP; // Return_val_4=ADC_CMD_NOP; //while(WaitBusy()) // ; ADS1247_CS_0; Delay(50); while(WaitBusy()); // ADS1247_WriteCmd(0x00); Return_val_0=ADS1247_ReadCmd(ADC_CMD_RDATA);//µ¥´Î¶ÁÈ¡Êý¾Ý Delay(50); Return_val_1 = ADS1247_Return_read_val(ADC_CMD_NOP); Return_val_2 = ADS1247_Return_read_val(ADC_CMD_NOP); Return_val_3 = ADS1247_Return_read_val(ADC_CMD_NOP); //Return_val_4 = ADS1247_Return_read_val(ADC_CMD_NOP); ADS1247_CS_1; printf("rn Return_val_1 %x", Return_val_1);//Êä³ö16½øÖÆÎÞ·ûºÅÕûÊý printf("rn Return_val_2 %x", Return_val_2); printf("rn Return_val_3 %x", Return_val_3); //printf("rn Return_val_4 %x", Return_val_4); // Return_val_0= (Return_val_1&0x80)!=0 ? 0xFF:0x00; // printf("rn Return_val_0 %x", Return_val_0); D24 = ((Return_val_1<<16)|(Return_val_2<<8)|Return_val_3)&0x00ffffff; //D24 = Return_val_0|(Return_val_2<<8)|Return_val_3; //return D24; RTD=(D24*820)/(4*8388608); printf("rn RTD %d", RTD); // T=(RTD-100)/0.385; // printf("rn TN %d", T); } |
|
相关推荐
|
|
只有小组成员才能发言,加入小组>>
612 浏览2 评论
12634 浏览0 评论
3981 浏览7 评论
2214 浏览9 评论
2017 浏览2 评论
341浏览2评论
614浏览2评论
391浏览1评论
437浏览1评论
AD7656在没有输入信号时,测量输入端都会有几mV至几十mV的电压,怎么消除呢?
355浏览1评论
小黑屋|手机版|Archiver|德赢Vwin官网(湘ICP备2023018690号)
GMT+8, 2024-9-2 01:30, Processed in 0.650897 second(s), Total 45, Slave 39 queries .
Powered by德赢Vwin官网 网
© 2015bbs.elecfans.com
关注我们的微信
下载发烧友APP
德赢Vwin官网 观察
版权所有 © 湖南华秋数字科技有限公司
德赢Vwin官网 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号