<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[采用GPADC的查询模式总是不能获得电压]]></title><description><![CDATA[<p dir="auto">在裸机环境按照手册的说明设置GPADC0为查询模式，但总是得不到电压值。<br />
在设置连续转换模式之后和使能ADC之后读取GP_CTRL，发现总是默认值0x800000，和设置啥无关。<br />
哪些帮忙看看，谢谢。<br />
程序大致如下：<br />
unsigned int ra;<br />
unsigned int x, d;</p>
<pre><code>/* init GPADC */
/* 1. Write 0x1 to the bit[16] of GPADC_BGR_REG (Offset: 0x09EC) to dessert reset. */
PUT32(GPADC_BGR, 1 &lt;&lt; 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) &amp; ~(0x03 &lt;&lt; 18);
PUT32(GP_CTRL, ra | (0x02 &lt;&lt; 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) &amp; ~(0x09 &lt;&lt; 16);
PUT32(GP_CTRL, ra | (0x09 &lt;&lt; 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 &amp; 1)
{
   d = GET32(GP_CH0_DATA) &amp; 0xfff;
   hexstring(d);
}
    DELAY(0x1000000);
}
</code></pre>
]]></description><link>https://bbs.aw-ol.com/topic/2691/采用gpadc的查询模式总是不能获得电压</link><generator>RSS for Node</generator><lastBuildDate>Sat, 11 Apr 2026 15:01:47 GMT</lastBuildDate><atom:link href="https://bbs.aw-ol.com/topic/2691.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 04 Dec 2022 12:45:51 GMT</pubDate><ttl>60</ttl></channel></rss>