ADC128S022数据采集问题
整个系统的连接关系图如下所示:
(MG2455/51单片机-12MHz晶振) <--(模拟SPI)--> (ADC128S022)
问题:
(1) 当使用第8路数据的时候,数据能正常读出;
(2) 当使用第第7路数据的时候,数据能正常读出;
(3) 当配置为其他路数据的时候,数据不能正常读出;特别是当设置为0x00时,应读取第一路数据,但从读取的数据来看,没有读取到任何数据;
模拟程序如下:
void Reading_ADC_Data(unsigned char serial_number, unsigned short *adc_data)
{
//function's relative variable define
unsigned char lvuc_adc_input = 0x00;
unsigned char lvuc_adc_cnt = 0x00;
unsigned short lvus_adc_data = 0x0000;
unsigned char lvuc_adc_numbytes = 0x00;
//Initial the function's relative variable according to ADC's datasheet
lvuc_adc_numbytes = 16;
lvus_adc_data = 0;
ADC_CSN = 1;
ADC_SCK = 1;
ADCDelay(2);
ADC_CSN = 0;
//The main processing for the processing of Reading ADC
//step 1: according to the input's serial number and confirm the adc's input
switch(serial_number)
{
case 0: lvuc_adc_input = ADC_INPUT0; break;
case 1: lvuc_adc_input = ADC_INPUT1; break;
case 2: lvuc_adc_input = ADC_INPUT2; break;
case 3: lvuc_adc_input = ADC_INPUT3; break;
case 4: lvuc_adc_input = ADC_INPUT4; break;
case 5: lvuc_adc_input = ADC_INPUT5; break;
case 6: lvuc_adc_input = ADC_INPUT6; break;
case 7: lvuc_adc_input = ADC_INPUT7; break; default: break; }
#if 1 //debug the AD with all bit setting '1'
lvuc_adc_input = 0xe1;
#endif
//Step2: sending the controller register and reading the convert data
for(lvuc_adc_cnt = 0; lvuc_adc_cnt < lvuc_adc_numbytes; lvuc_adc_cnt++)
{
//Step 2A: drop-down the SclK signal to low period
ADCDelay(4);
ADC_SCK = 0;
//Step 2a: sending the ADC's input address into the ADC registers
if(lvuc_adc_cnt < 5) {
//setting the SPI output interference signal
if(lvuc_adc_input&0x80) { ADC_DOU = 1; } else { ADC_DOU = 0; }
//left moving the sending byte
lvuc_adc_input <<= 1; }
else { ADC_DOU = 0; }
//Step 2B: reading the data from the ADC
ADCDelay(5); ADC_SCK = 1; ADCDelay(1);
//recording the data reading from ADC
if(lvuc_adc_cnt >= 4 )
{ //recording the history data
lvus_adc_data <<= 1; //setting the SPI output interference signal
if(ADC_DIN) { lvus_adc_data |= 0x0001; } else { lvus_adc_data &= 0xfffe; } } else { ; } }
//Step 4: letting the ADC going to deep-sleeping modeling ADC_CSN = 1; ADC_SCK = 1;
//getting the ADC values *adc_data = lvus_adc_data;
return; }
Hi Xiaoyong
最好能有原理图4线SPI的波形截图,帮助分析。
所指的没有任何数据是,Dout上恒为低吗?
测试时候通道输入端是怎样连接的?
芯片默认如果不配置就是IN0, 试下,如果不配置通道,是否有Dout?
你好,我也正在做adc128s022的5路采集,,没有思路能把你的程序该我参考一下吗