采用GPADC的查询模式总是不能获得电压
-
在裸机环境按照手册的说明设置GPADC0为查询模式,但总是得不到电压值。
在设置连续转换模式之后和使能ADC之后读取GP_CTRL,发现总是默认值0x800000,和设置啥无关。
哪些帮忙看看,谢谢。
程序大致如下:
unsigned int ra;
unsigned int x, d;/* init GPADC */ /* 1. Write 0x1 to the bit[16] of GPADC_BGR_REG (Offset: 0x09EC) to dessert reset. */ PUT32(GPADC_BGR, 1 << 16); /* 2. Write 0x1 to the bit[0] of GPADC_BGR_REG (Offset: 0x09EC) to enable the GPADC clock. */ PUT32(GPADC_BGR, 1); /* 3. Write 0x2F to the bit[15:0] of GP_SR_CON (Offset: 0x0000) to set the acquiring time of ADC. 4. Write 0x1DF to the bit[31:16] of GP_SR_CON (Offset: 0x0000) to set the ADC sample frequency divider. */ PUT32(GP_SR_CON, 0x1df002f); /* 5. Write 0x2 to the bit[19:18] of GP_CTRL (Offset: 0x0004 ) to set the continuous conversion mode.*/ ra = GET32(GP_CTRL) & ~(0x03 << 18); PUT32(GP_CTRL, ra | (0x02 << 18)); /* 6. Write 0x1 to the bit[0] of GP_CS_EN (Offset: 0x0008) to enable the analog input channel. */ ra = GET32(GP_CS_EN); PUT32(GP_CS_EN, ra | 1); /* 7. Write 0x1 to the bit[16] of GP_CTRL (Offset: 0x0004) to enable the ADC function.*/ ra = GET32(GP_CTRL); ra = GET32(GP_CTRL) & ~(0x09 << 16); PUT32(GP_CTRL, ra | (0x09 << 16)); /* queue the key states */ while(1) { /* 8. Read the bit[0] of GP_DATA_INTS (Offset: 0x0038), if the bit is 1, then data conversion is complete.*/ x = GET32(GP_DATA_INTS); if(x & 1) { d = GET32(GP_CH0_DATA) & 0xfff; hexstring(d); } DELAY(0x1000000); }
Copyright © 2024 深圳全志在线有限公司 粤ICP备2021084185号 粤公网安备44030502007680号