使用AD7792进行模数转换,AD7792以SPI模式与
STM32连接,使用通道一进行转换,但输出结果上下波动超过10mV。已进行的错误排除:
1、使用万用表测量AD7792通道一电压稳定,排除输入电压波动错误。
2、已用串口打印正常字符串,排除串口传输错误。
3、失调寄存器与满量程寄存器输出结果正确,排除SPI传输错误。
部分代码如下所示:
[C]
纯文本查看 复制代码
void ad7792_configura
tion(void){spi_configuration();//设置SPImux_gpio_configuration();//设置4052芯片通道,由于已排除输入电压波动的可能,故忽略此处CS_L;//使能AD7792ms_delay(10);spi_send_byte(0xff);spi_send_byte(0xff);spi_send_byte(0xff);spi_send_byte(0xff);ms_delay(500);//复位AD7792gain_select(AGC_GAIN_1);//修改配置寄存器,0x1000mode_select(MODE_CONTINUE,SPEED_16_7); //修改模式寄存器,0x0001CS_H;//失能AD7792ms_delay(500);calibration();//读取失调寄存器,满量程寄存器}void calibration(void)//读取失调寄存器,满量程寄存器{uint8_t t1,t2;CS_L;/*zero internal calibration*/mode_select(MODE_ZERO_IN,SPEED_16_7); ms_delay(1000);/*full internal calibration*/while(RDY);mode_select(MODE_FULL_IN,SPEED_16_7);ms_delay(1000);/*internal GND*/GPIO_ResetBits(GPIOE,GPIO_Pin_2);bypass_select(AGC_CHAN_1,PAIRB);ms_delay(10);while(RDY);mode_select(MODE_CONTINUE,SPEED_16_7);ms_delay(1000);while(RDY);spi_send_byte(0x70);t1=spi_send_byte(0xff);t2=spi_send_byte(0xff);zero=t1;zero<<=8;zero+=t2;uart1_printf("Zero:%Xrn",zero);spi_send_byte(0x78);t1=spi_send_byte(0xff);t2=spi_send_byte(0xff);full=t1;full<<=8;full+=t2;uart1_printf("Full:%Xrn",full);CS_H;}float convert(void)//AD转换部分{uint16_t res = 0;float res1 = 0;CS_L;while(RDY);//等待可以开始转换us_delay(1000);GPIO_choice();//配置4052mode_select(MODE_CONTINUE,SPEED_16_7);//模式选择0x0001ms_delay(100);while(RDY);//等待转换结束spi_send_byte(0x58);res=(((uint16_t)spi_send_byte(0xff)) & 0x00ff)<<8;res+=(((uint16_t)spi_send_byte(0xff)) & 0x00ff);CS_H;res1 = 3.0 * ((float)(res)) / 65536.0 * 1000;ms_delay(1000);return res1;//输出电压}
输出结果如下所示(50mV为例):
Zero:8000
Full:54A7
adc_value:41.38
adc_value:48.29
adc_value:55.94
adc_value:60.10
adc_value:58.00
adc_value:51.36
adc_value:44.45
adc_value:39.28
adc_value:40.01
adc_value:46.78
adc_value:55.25
adc_value:59.74
adc_value:58.82
卡在这里好久了,求大神解答~~~