MCU:STM32f407
ADC:ADC128S102
异常现场:
扫描读取ch0~ch7 8通道模拟输入电压信号,其中ch5读出值不正确,其它7个通道都能正常读出,ch5读出值为ch4通道的输入值;
排查措施:
1、测量AD芯片ch5通道 模拟信号正常,未与ch4通道短路;
2、单独只采集ch5通道,也读不出ch5引脚的电压,读到的是ch4引脚的电压;
3、用io模拟SPI时序控制,严格按datasheet时序上升沿输出,下降沿输入控制,现象一样,还是ch5通道读不出来;
模拟SPI时序如下:
void Scan_Right_AD_Channel(unsigned short *data)
{
unsigned char ch,i,j;
unsigned short si_data,so_data;
ADC128_SCK = 1;
ADC128_R_CS = 1;
Delay_us(1);
ADC128_R_CS = 0;
Delay_us(1);
for(j=1;j<=8;j++)
{
so_data = 0x0000;
ch =(j<8) ? j : 0;
si_data = ADC128S_Channel_ADRR[ch];
for(i=0;i<16;i++)
{
ADC128_SCK = 0;
Delay_6ns(1);
if(ADC128_MISO)
{
so_data |=0x01;
}
ADC128_MOSI = (si_data & 0x8000) ? 1 :0;
Delay_6ns(1);
ADC128_SCK = 1;
Delay_6ns(2);
si_data<<=1;
if(i<15)
so_data <<=1;
}
*data++ = so_data;
}
ADC128_R_CS = 1;
ADC128_SCK = 1;
}
|