1楼已经重新编辑过,看1楼即可,2、3、4楼是调试过程中的一些信息,忽略吧,暂时保留先
求高人给点思路,问题有可能出在什么地方或者还有什么方法可以查找问题点
LMP90100电路按照官网上开发板设计,测量芯片电源正常、参考电压正常,测量芯片输入通道模拟电压(0)与实际符合
LMP90100+LPC1115(ARM Cortex-M0),LMP90100的D6做DRDYB,接到LPC1115的GPIO上,只扫描通道0,通道0用的是VIN0和VIN1,已经短接
代码根据官网上下的软件包移植而来(官网上控制器用的是MSP430)
程序大致流程:中断后置位标志位,while(1)循环检测标志位,如标志位置位,则读ADC采集结果
读ADC采集结果,测试过controlledstream、直读寄存器和normalstream三种方式,每次除三个转换结果寄存器外,还会读其他寄存器验证,主要是验证ADC状态(active、standby、poweroff)、ADC数据是否可用、当前通道号、CRC,验证用的寄存器每次不会全用到
三种工作方式下,目前验证的结果:1、通过串口输出的频率验证,ODR基本正确;2、通过外围LED显示结果,GPIO寄存器设定正确;3、以上两点,初步推断SPI接口基本正常;4、LMP90100工作不正常,通道号和采样结果有较大几率异常
LPC1115中断代码
void PIOINT0_IRQHandler(void)
{
if(((LPC_GPIO0->MIS) & (1u<<1))==(1u<<1))
{
LMP_ADCDataReady[0]=1;// set flag
LPC_GPIO0->IC |=(1u<<1);
}
。。。
}//中断程序经过多种方式验证:示波器、设其他标志位等,验证结果OK
第一种直接读寄存器
prev_URA = LMP90100_URA_END;
while(1)
{
if (LMP_ADCDataReady[0])
{
LMP_ADCDataReady[0] = 0;//clear flag
for(i=0;i<5;i++)
{
TI_LMP90100_SPIWriteReg(TI_LMP90100_GPIO_DAT_REG, i, &prev_URA);//GPIO测试,外接LED灯,验证结果OK
readtestbuf[i]=TI_LMP90100_SPIReadReg(0x19+i,&prev_URA);//读ADC,包括状态、数据、CRC,验证结果fail,读到的数据(通道和结果)乱七八糟
}
…
}
第二种是通过controlledstreamread,验证结果同直读寄存器,读到的通道号和结果乱七八糟
prev_URA = LMP90100_URA_END; while(1) { if (LMP_ADCDataReady[0]) { LMP_ADCDataReady[0] = 0; // clear flag TI_LMP90100_SPIControlledStreamReadADC(addr, read_buf, 5, &prev_URA); // read status, adc output & CRC into read_buf ch_status = read_buf[0]; // Get Channel Status byte ch_num = ch_status & LMP90100_CH_NUM_MASK; // Extract Channel Number adc_data = ((uint32_t) read_buf[1] << 16) | ((uint16_t) read_buf[2] << 8) | read_buf[3]; // form raw adc output data crc_test = TI_LMP90100_SPICRCCheck(read_buf, 4); // test if CRC read from device matches computed ... }
第三种:normalstream,连续采样50次,其中通道号正确和数值合理(高、中字节是0x00,低字节忽略)的只有32个
count=4; addr = TI_LMP90100_SENDIAG_FLAGS_REG; while(1) { if (LMP_ADCDataReady[0]) { LMP_ADCDataReady[0] = 0; // clear flag TI_LMP90100_SPINormalStreamReadADC(addr, read_buf, count, &prev_URA); for(i=0;i<4;i++) { UART0_Send(read_buf[i]); } ....
下面是normalstram方式下寄存器的设定值
#define TI_LMP90100_RESETCN_REG_VALUE(0xC3)/* Register and Conversion Reset */ #define TI_LMP90100_SPI_HANDSHAKECN_REG_VALUE(0x01)/* SPI SDO High Z Delayed */ #define TI_LMP90100_SPI_STREAMCN_REG_VALUE(0x00)/* SPI Normal Streaming mode */ #define TI_LMP90100_PWRCN_REG_VALUE(0x00)/* Active Mode */ #define TI_LMP90100_ADC_RESTART_REG_VALUE(0x00)/* Disable restart Conversion */ #define TI_LMP90100_GPIO_DIRCN_REG_VALUE(0x47)//D6 D0-D3 output/*(0x40) D6 output, D0-D5 inputs */ #define TI_LMP90100_GPIO_DAT_REG_VALUE(0x47)// D6 D0-D3 high/* (0x40)Set D6 high, others ignore */ #define TI_LMP90100_BGCALCN_REG_VALUE(0x00)/* Background Calibration OFF */ #define TI_LMP90100_SPI_DRDYBCN_REG_VALUE(0x83)/* Enable DRDYB on D6, bits 0 & 1 must be 1, others default */ #define TI_LMP90100_ADC_AUXCN_REG_VALUE(0x20)/* bypass external clock detection, internal clock, select 0uA RTD current */ #define TI_LMP90100_SPI_CRC_CN_REG_VALUE(0x00)/* disable CRC, Bit 3 must be 0, DRDYB is deasserted after ADC_DOUTL is read */ #define TI_LMP90100_SENDIAG_THLDH_REG_VALUE(0x00)/* Sensor Diagnostic Threshold High */ #define TI_LMP90100_SENDIAG_THLDL_REG_VALUE(0x00)/* Sensor Diagnostic Threshold Low */ #define TI_LMP90100_SCALCN_REG_VALUE(0x00)/* System Calibration Control Normal Mode */ #define TI_LMP90100_ADC_DONE_REG_VALUE(0xFF)/* ADC Data unAvailable */ #define TI_LMP90100_SENDIAG_FLAGS_REG_VALUE(0x00)/* Sensor Diagnostic Flags - status output */ #define TI_LMP90100_ADC_DOUT2_REG_VALUE(0x00)/* ADC Conversion Data 2 */ #define TI_LMP90100_ADC_DOUT1_REG_VALUE(0x00)/* ADC Conversion Data 1 */ #define TI_LMP90100_ADC_DOUT0_REG_VALUE(0x00)/* ADC Conversion Data 0 */ #define TI_LMP90100_SPI_CRC_DAT_REG_VALUE(0xFF)/* Reset CRC Data */ #define TI_LMP90100_CH_STS_REG_VALUE(0x00)/* Channel Status */ #define TI_LMP90100_CH_SCAN_REG_VALUE(0x00)/* Single Channel Continuous Scan: Channel 0*/ #define TI_LMP90100_CH0_INPUTCN_REG_VALUE(0x01)/* diable sensor diagnostics, default ref, vinp 0 vinn 1 */ #define TI_LMP90100_CH0_CONFIG_REG_VALUE(0x40)/* CH0 Configuratio: 26.83SPS, FGA off, buffer in signal path*/ #define TI_LMP90100_CH1_INPUTCN_REG_VALUE(0x13)/* disable sensor diagnostics, default ref, vinp 2 vinn 3 */ #define TI_LMP90100_CH1_CONFIG_REG_VALUE(0x40)/* CH1 config: 26.835SPS, FGA off, buffer in signal path */ #define TI_LMP90100_CH2_INPUTCN_REG_VALUE(0x25)/* disable sensor diagnostics, default ref, vinp 4 vinn 5 */ #define TI_LMP90100_CH2_CONFIG_REG_VALUE(0x70)/* 214.65SPS, FGA off, buffer in signal path */ #define TI_LMP90100_CH3_INPUTCN_REG_VALUE(0x37)/* disable sensor diagnostics, default ref, vinp 6 vinn 7 */ #define TI_LMP90100_CH3_CONFIG_REG_VALUE(0x70)/* 214.65SPS, FGA off, buffer in signal path */ #define TI_LMP90100_CH4_INPUTCN_REG_VALUE(0x01)/* disable sensor diagnostics, default ref, vinp 2 vinn 3 */ #define TI_LMP90100_CH4_CONFIG_REG_VALUE(0x70)/* 214.65SPS, FGA off, buffer in signal path */ #define TI_LMP90100_CH5_INPUTCN_REG_VALUE(0x13)/* disable sensor diagnostics, default ref, vinp 4 vinn 5 */ #define TI_LMP90100_CH5_CONFIG_REG_VALUE(0x70)/* 214.65SPS, FGA off, buffer in signal path */ #define TI_LMP90100_CH6_INPUTCN_REG_VALUE(0x25)/* disable sensor diagnostics, default ref, vinp 6 vinn 7 */ #define TI_LMP90100_CH6_CONFIG_REG_VALUE(0x70)/* 214.65SPS, FGA off, buffer in signal path */ #define TI_LMP90100_CH0_SCAL_OFFSET2_REG_VALUE(0x00)/* CH0 System Calibration Offset Coefficient [23:16] */ #define TI_LMP90100_CH0_SCAL_OFFSET1_REG_VALUE(0x00)/* CH0 System Calibration Offset Coefficient [15:8] */ #define TI_LMP90100_CH0_SCAL_OFFSET0_REG_VALUE(0x00)/* CH0 System Calibration Offset Coefficient [7:0] */ #define TI_LMP90100_CH0_SCAL_GAIN2_REG_VALUE(0x80)/* CH0 System Calibration Gain Coefficient [23:16] */ #define TI_LMP90100_CH0_SCAL_GAIN1_REG_VALUE(0x00)/* CH0 System Calibration Gain Coefficient [15:8] */ #define TI_LMP90100_CH0_SCAL_GAIN0_REG_VALUE(0x00)/* CH0 System Calibration Gain Coefficient [7:0] */ #define TI_LMP90100_CH0_SCAL_SCALING_REG_VALUE(0x00)/* CH0 System Calibration Scaling Coefficient */ #define TI_LMP90100_CH0_SCAL_BITS_SELECTOR_REG_VALUE(0x00)/* CH0 System Calibration Bits Selector */ #define TI_LMP90100_CH1_SCAL_OFFSET2_REG_VALUE(0x00)/* CH1 System Calibration Offset Coefficient [23:16] */ #define TI_LMP90100_CH1_SCAL_OFFSET1_REG_VALUE(0x00)/* CH1 System Calibration Offset Coefficient [15:8] */ #define TI_LMP90100_CH1_SCAL_OFFSET0_REG_VALUE(0x00)/* CH1 System Calibration Offset Coefficient [7:0] */ #define TI_LMP90100_CH1_SCAL_GAIN2_REG_VALUE(0x80)/* CH1 System Calibration Gain Coefficient [23:16] */ #define TI_LMP90100_CH1_SCAL_GAIN1_REG_VALUE(0x00)/* CH1 System Calibration Gain Coefficient [15:8] */ #define TI_LMP90100_CH1_SCAL_GAIN0_REG_VALUE(0x00)/* CH1 System Calibration Gain Coefficient [7:0] */ #define TI_LMP90100_CH1_SCAL_SCALING_REG_VALUE(0x00)/* CH1 System Calibration Scaling Coefficient */ #define TI_LMP90100_CH1_SCAL_BITS_SELECTOR_REG_VALUE(0x00)/* CH1 System Calibration Bits Selector */ #define TI_LMP90100_CH2_SCAL_OFFSET2_REG_VALUE(0x00)/* CH2 System Calibration Offset Coefficient [23:16] */ #define TI_LMP90100_CH2_SCAL_OFFSET1_REG_VALUE(0x00)/* CH2 System Calibration Offset Coefficient [15:8] */ #define TI_LMP90100_CH2_SCAL_OFFSET0_REG_VALUE(0x00)/* CH2 System Calibration Offset Coefficient [7:0] */ #define TI_LMP90100_CH2_SCAL_GAIN2_REG_VALUE(0x80)/* CH2 System Calibration Gain Coefficient [23:16] */ #define TI_LMP90100_CH2_SCAL_GAIN1_REG_VALUE(0x00)/* CH2 System Calibration Gain Coefficient [15:8] */ #define TI_LMP90100_CH2_SCAL_GAIN0_REG_VALUE(0x00)/* CH2 System Calibration Gain Coefficient [7:0] */ #define TI_LMP90100_CH2_SCAL_SCALING_REG_VALUE(0x00)/* CH2 System Calibration Scaling Coefficient */ #define TI_LMP90100_CH2_SCAL_BITS_SELECTOR_REG_VALUE(0x00)/* CH2 System Calibration Bits Selector */ #define TI_LMP90100_CH3_SCAL_OFFSET2_REG_VALUE(0x00)/* CH3 System Calibration Offset Coefficient [23:16] */ #define TI_LMP90100_CH3_SCAL_OFFSET1_REG_VALUE(0x00)/* CH3 System Calibration Offset Coefficient [15:8] */ #define TI_LMP90100_CH3_SCAL_OFFSET0_REG_VALUE(0x00)/* CH3 System Calibration Offset Coefficient [7:0] */ #define TI_LMP90100_CH3_SCAL_GAIN2_REG_VALUE(0x80)/* CH3 System Calibration Gain Coefficient [23:16] */ #define TI_LMP90100_CH3_SCAL_GAIN1_REG_VALUE(0x00)/* CH3 System Calibration Gain Coefficient [15:8] */ #define TI_LMP90100_CH3_SCAL_GAIN0_REG_VALUE(0x00)/* CH3 System Calibration Gain Coefficient [7:0] */ #define TI_LMP90100_CH3_SCAL_SCALING_REG_VALUE(0x00)/* CH3 System Calibration Scaling Coefficient */ #define TI_LMP90100_CH3_SCAL_BITS_SELECTOR_REG_VALUE(0x00)/* CH3 System Calibration Bits Selector */
lorne Jiang:
为方便调试,主循环稍作修改
while(1) { UART0_Send(0xaa); if (LMP_ADCDataReady[0]) //DRDYB有效,GPIO中断置位该标志 { LMP_ADCDataReady[0] = 0;
ch_status=TI_LMP90100_SPIReadReg(0x08,&prev_URA); //0x08 PWRCN寄存器,低2位:0-actvie,1-powerdown,3-standby UART0_Send('2'); UART0_Send(ch_status); if(ch_status==0x00) { ch_status=TI_LMP90100_SPIReadReg(0x18,&prev_URA);//0x18 ADC_DONE寄存器,0xff-not available 0-0xfe available UART0_Send('3'); UART0_Send(ch_status); if(ch_status<0xff) { UART0_Send('4'); for(i=0;i<5;i++) {
readtestbuf[i]=TI_LMP90100_SPIReadReg(0x19+i,&prev_URA);//0x19 SENDIAG_FLAGS,低三位指示通道号,0x1a 0x1b 0x1c ADC数据,0x1d CRC UART0_Send(readtestbuf[i]); }
}
}
}
}
串口实际收到的数据(16进制)
AA 32 00 33 00 34 00 FF FF FF FF AA AA AA AA AA AA AA A
从最后一个FF后每隔一段时间(差不多固定个数的AA)固定出现32 FF
lorne Jiang:
回复 lorne Jiang:
计算了一下,32 FF之间间隔570个AA,串口波特率9600,折算一下接近1.67的ODR,从中断频率上来讲,与参数设定的ODR匹配。
问题是,程序能走到输出32 FF这里,证明中断已经发生,也即ADC完成转换,为什么0x08寄存器读到的数不是0x00而是0xff?
lorne Jiang:
回复 lorne Jiang:
补充一下:
把前面测试程序的IF都去掉,程序第一次执行时,LMP90100的0x08寄存器数值为0x00,后续为0xff;LMP90100的0x18寄存器,首次执行时为0x00,后续为0xff;LMP90100的0x19寄存器,首次为0x00,后续为0xff;LMP90100的0x1a-0x1c寄存器,首次都是0xff,后续也是0xff;LMP90100的0x1d寄存器,首次是0xff,后续也是0xff。
有点迷茫了,哪位高人给个思路、方向什么的呗。。。
lorne Jiang:
编辑完,自己在顶一顶,希望有高人能看到。。。