完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
朋友们好 ,我最近在做 ads1247 这个芯片 我的SPI通讯是正常的 能够正确都出我写入的寄存器的值,但是读的书不正确 附上我的电路图 和 测试波形 请问 这种情况 是怎么回事 啊 我测了差分输入和电压基准输入都没问题的 我的电阻计算公式是 RTD=(D24*820)/(Gain*8388608);
#include "ADS1247FUNCtiON.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); } |
|
相关推荐
|
|
只有小组成员才能发言,加入小组>>
2018个成员聚集在这个小组
加入小组969 浏览 2 评论
12866 浏览 0 评论
4150 浏览 7 评论
2360 浏览 9 评论
2196 浏览 2 评论
482浏览 2评论
850浏览 2评论
970浏览 2评论
435浏览 1评论
668浏览 1评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-31 04:53 , Processed in 0.692127 second(s), Total 41, Slave 36 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号