平头哥RVB2601测评:ADC轮询单通道与DMA多通道采集
<hr /><p style="text-align:justify"><strong><span style="font-size:20px;"><span style="font-family:Calibri"><span style="font-family:宋体"><font face="宋体">前阵子因为住院还有养伤耽误了测评太久了,拖更了一个多月。实在不好意思。。。</font></span></span></span></strong></p>
<p style="text-align:justify"><strong><span style="font-size:20px;"><span style="font-family:Calibri"><span style="font-family:宋体"><font face="宋体">想想当时是在测评</font>ADC<font face="宋体">的,然后因为</font><font face="Calibri">ADC</font><font face="宋体">的</font><font face="Calibri">DMA</font><font face="宋体">采样有了疑问就去阿里云提交工单 ,然后就没有然后了。。</font></span></span></span></strong></p>
<p style="text-align:justify"> </p>
<p style="text-align:justify"><strong><span style="font-size:20px;"><span style="font-family:Calibri"><span style="font-family:宋体"><font face="宋体">。</font></span></span></span></strong></p>
<p style="text-indent:21.0000pt; text-align:justify"><strong><span style="font-size:20px;"><span style="font-family:Calibri"><span style="font-family:宋体"><font face="宋体"> 由于</font>ADC<font face="宋体">没有文档介绍也没有历程所以就只能靠着他所给的</font><font face="Calibri">API</font><font face="宋体">来用,对照着</font><font face="Calibri">PW</font>M<font face="宋体">一步一步的来,</font></span></span></span></strong></p>
<p style="text-indent:21.0000pt; text-align:justify"><strong><span style="font-size:20px;"><span style="font-family:Calibri"><span style="font-family:宋体"><font face="宋体">最后还是调通了。也总结了不少技巧,比如他所提供的</font>API<font face="宋体">前面有</font><font face="Calibri">static</font><font face="宋体">的就是他文件内部是函数,</font></span></span></span></strong></p>
<p style="text-indent:21.0000pt; text-align:justify"><strong><span style="font-size:20px;"><span style="font-family:Calibri"><span style="font-family:宋体"><font face="宋体">给自己调用的,到最后就剩下了几个。比如初始化的,</font><font face="Calibri">adc</font><font face="宋体">通道配置的,</font><font face="Calibri">adc</font><font face="宋体">开始停止的,</font></span></span></span></strong></p>
<p style="text-indent:21.0000pt; text-align:justify"><strong><span style="font-size:20px;"><span style="font-family:Calibri"><span style="font-family:宋体"><font face="Calibri">adc</font><font face="宋体">模式的函数,还有给</font><font face="Calibri">DMA</font><font face="宋体">用的缓冲区还有他相应的配置函数等等。</font></span></span></span></strong></p>
<p style="text-indent:21.0000pt; text-align:justify"> </p>
<p style="text-align:justify"><strong><span style="font-size:20px;"><span style="font-family:Calibri"><span style="font-family:宋体">1.<font face="宋体">内部盗用的</font><font face="Calibri">API</font><font face="宋体">,可以不用管他,刚开始还研究了好久。</font></span></span></span></strong></p>
<p style="text-align:justify"><strong><span style="font-size:20px;"><span style="font-family:Calibri"><span style="font-family:宋体">static void wj_adc_channel_conv_end_irq(csi_adc_t *adc)</span></span></span></strong></p>
<p style="text-align:justify"><strong><span style="font-size:20px;"><span style="font-family:Calibri"><span style="font-family:宋体">static void wj_adc_irqhandler(void *args)</span></span></span></strong></p>
<p style="text-align:justify"><strong><span style="font-size:20px;"><span style="font-family:Calibri"><span style="font-family:宋体">static csi_error_t wj_adc_start_intr(csi_adc_t *adc)</span></span></span></strong></p>
<p style="text-align:justify"><strong><span style="font-size:20px;"><span style="font-family:Calibri"><span style="font-family:宋体">static csi_error_t wj_adc_start_dma(csi_adc_t *adc)</span></span></span></strong></p>
<p style="text-align:justify"><strong><span style="font-size:20px;"><span style="font-family:Calibri"><span style="font-family:宋体">static csi_error_t wj_adc_stop_intr(csi_adc_t *adc)</span></span></span></strong></p>
<p style="text-align:justify"><strong><span style="font-size:20px;"><span style="font-family:Calibri"><span style="font-family:宋体">static csi_error_t wj_adc_stop_dma(csi_adc_t *adc)</span></span></span></strong></p>
<p style="text-align:justify"><strong><span style="font-size:20px;"><span style="font-family:Calibri"><span style="font-family:宋体">static int adc_channel_delete(uint8_t *channels, uint8_t nums, uint8_t channel)</span></span></span></strong></p>
<p style="text-align:justify"> </p>
<p style="text-align:justify"><strong><span style="font-size:20px;"><span style="font-family:Calibri"><span style="font-family:宋体">2.ADC<font face="宋体">初始化,开始停止,通道配置,采样频率、时间,回调函数,</font><font face="Calibri">ADC</font><font face="宋体">读取值等等</font></span></span></span></strong></p>
<p style="text-align:justify"> </p>
<p style="text-align:justify"><strong><span style="font-size:20px;"><span style="font-family:Calibri"><span style="font-family:宋体">csi_error_t csi_adc_init(csi_adc_t *adc, uint32_t idx)</span></span></span></strong></p>
<p style="text-align:justify"><strong><span style="font-size:20px;"><span style="font-family:Calibri"><span style="font-family:宋体">void csi_adc_uninit(csi_adc_t *adc)</span></span></span></strong></p>
<p style="text-align:justify"><strong><span style="font-size:20px;"><span style="font-family:Calibri"><span style="font-family:宋体">csi_error_t csi_adc_start(csi_adc_t *adc)</span></span></span></strong></p>
<p style="text-align:justify"><strong><span style="font-size:20px;"><span style="font-family:Calibri"><span style="font-family:宋体">csi_error_t csi_adc_stop(csi_adc_t *adc)</span></span></span></strong></p>
<p style="text-align:justify"><strong><span style="font-size:20px;"><span style="font-family:Calibri"><span style="font-family:宋体">csi_error_t csi_adc_channel_enable(csi_adc_t *adc, uint8_t ch_id, bool is_enable)</span></span></span></strong></p>
<p style="text-align:justify"><strong><span style="font-size:20px;"><span style="font-family:Calibri"><span style="font-family:宋体">csi_error_t csi_adc_channel_sampling_time(csi_adc_t *adc, uint8_t ch_id, uint16_t clock_num)</span></span></span></strong></p>
<p style="text-align:justify"><strong><span style="font-size:20px;"><span style="font-family:Calibri"><span style="font-family:宋体">csi_error_t csi_adc_sampling_time(csi_adc_t *adc, uint16_t clock_num)</span></span></span></strong></p>
<p style="text-align:justify"><strong><span style="font-size:20px;"><span style="font-family:Calibri"><span style="font-family:宋体">uint32_t csi_adc_freq_div(csi_adc_t *adc, uint32_t div)</span></span></span></strong></p>
<p style="text-align:justify"><strong><span style="font-size:20px;"><span style="font-family:Calibri"><span style="font-family:宋体">int32_t csi_adc_read(csi_adc_t *adc)</span></span></span></strong></p>
<p style="text-align:justify"><strong><span style="font-size:20px;"><span style="font-family:Calibri"><span style="font-family:宋体">csi_error_t csi_adc_get_state(csi_adc_t *adc, csi_state_t *state)</span></span></span></strong></p>
<p style="text-align:justify"><strong><span style="font-size:20px;"><span style="font-family:Calibri"><span style="font-family:宋体">uint32_t csi_adc_get_freq(csi_adc_t *adc)</span></span></span></strong></p>
<p style="text-align:justify"><strong><span style="font-size:20px;"><span style="font-family:Calibri"><span style="font-family:宋体">csi_error_t csi_adc_attach_callback(csi_adc_t *adc, void *callback, void *arg)</span></span></span></strong></p>
<p style="text-align:justify"><strong><span style="font-size:20px;"><span style="font-family:Calibri"><span style="font-family:宋体">void csi_adc_detach_callback(csi_adc_t *adc)</span></span></span></strong></p>
<p style="text-align:justify"><strong><span style="font-size:20px;"><span style="font-family:Calibri"><span style="font-family:宋体">csi_error_t csi_adc_start_async(csi_adc_t *adc)</span></span></span></strong></p>
<p style="text-align:justify"><strong><span style="font-size:20px;"><span style="font-family:Calibri"><span style="font-family:宋体">csi_error_t csi_adc_stop_async(csi_adc_t *adc)</span></span></span></strong></p>
<p style="text-align:justify"><strong><span style="font-size:20px;"><span style="font-family:Calibri"><span style="font-family:宋体">csi_error_t csi_adc_continue_mode(csi_adc_t *adc, bool is_enable)</span></span></span></strong></p>
<p style="text-align:justify"> </p>
<p style="text-align:justify"><strong><span style="font-size:20px;"><span style="font-family:Calibri"><span style="font-family:宋体">3.ADC DMA<font face="宋体">相关配置函数:</font></span></span></span></strong></p>
<p style="text-align:justify"><strong><span style="font-size:20px;"><span style="font-family:Calibri"><span style="font-family:宋体">void wj_adc_dma_event_cb(csi_dma_ch_t *dma, csi_dma_event_t event, void *arg)</span></span></span></strong></p>
<p style="text-align:justify"><strong><span style="font-size:20px;"><span style="font-family:Calibri"><span style="font-family:宋体">csi_error_t csi_adc_set_buffer(csi_adc_t *adc, uint32_t *data, uint32_t num)</span></span></span></strong></p>
<p style="text-align:justify"><strong><span style="font-size:20px;"><span style="font-family:Calibri"><span style="font-family:宋体">csi_error_t csi_adc_link_dma(csi_adc_t *adc, csi_dma_ch_t *dma)</span></span></span></strong></p>
<p style="text-align:justify"> </p>
<p style="text-align:justify"><strong><span style="font-size:20px;"><span style="font-family:Calibri"><span style="font-family:宋体"><font face="宋体">一、先来说说用查询的方法对</font>adc<font face="宋体">单通道采样的:</font></span></span></span></strong></p>
<p style="text-align:justify"><strong><span style="font-size:20px;"><span style="font-family:Calibri"><span style="font-family:宋体"><font face="宋体">创建一个</font>ADC<font face="宋体">任务</font></span></span></span></strong></p>
<pre>
<code>static void adc_task(void *arg)
{
csi_pin_set_mux(EXAMPLE_ADC_CH0, PA3_ADC_A1);
csi_adc_init(&adc1, 0);
uint32_t freq_value = csi_adc_freq_div(&adc1, 128);
printf("get freq_value: %d\n", freq_value);
csi_adc_sampling_time(&adc1, 2);
csi_adc_continue_mode(&adc1, 1);//这句是连续采样,不使能只能采样一次
csi_adc_channel_enable(&adc1, 0, true);
/*******************/
while(1)
{
lv_task_handler();
aos_msleep(400);
lv_tick_inc(1);
i = csi_adc_read(&adc1);
printf("adc1:%d ", i);
}
}</code></pre>
<p class="imagemiddle" style="text-align: center;"></p>
<p style="text-align:justify"><strong><span style="font-size:20px;"> </span></strong></p>
<p style="text-align:justify"><strong><span style="font-size:20px;"><span style="font-family:Calibri"><span style="font-family:宋体"><font face="宋体"> 二、那怎么用查询的方法对多通道采样呢?这个问题开始也是想了很久,因为读取</font>adc<font face="宋体">函数就只有一个</font><font face="Calibri">adc</font><font face="宋体">的句柄,这个句柄是初始化函数过来得到的,没有包含通道的相关操作,这我就联想到了</font><font face="Calibri">atm32sac</font><font face="宋体">的几种模式,就是扫描模式,多通道读取完一个自动对下一个进行读取,然后我就按照这个</font></span></span></span></strong></p>
<p class="imagemiddle" style="text-align: center;"></p>
<p style="text-align:justify"><strong><span style="font-size:20px;"> </span></strong></p>
<pre>
<code> csi_adc_channel_enable(&adc1, 0, true);
csi_adc_channel_enable(&adc1, 1, true);
csi_adc_channel_enable(&adc1, 2, true);
// 注册了几个端口,连续读取三次果然是三个端口的值:
i = csi_adc_read(&adc1);
printf("adc1:%d ", i);
i = csi_adc_read(&adc1);
printf("adc1:%d ", i);
i = csi_adc_read(&adc1);
printf("adc1:%d ", i);</code></pre>
<p style="text-align:justify"> </p>
<p style="text-align:justify"><strong><span style="font-size:20px;"><span style="font-family:Calibri"><span style="font-family:宋体"><font face="宋体"> 结果就是依次读取那个</font>PA3-5<font face="宋体">的</font><font face="Calibri">adc</font><font face="宋体">值。</font></span></span></span></strong></p>
<p class="imagemiddle" style="text-align: center;"></p>
<p style="text-align:justify"><strong><span style="font-size:20px;"> </span></strong></p>
<p style="text-align:justify"><strong><span style="font-size:20px;"><span style="font-family:Calibri"><span style="font-family:宋体"><font face="宋体"> 三、实际上我们比较多用</font>DMA<font face="宋体">采样多通道的</font><font face="Calibri">adc</font><font face="宋体">值,这样可以释放</font><font face="Calibri">cpu</font><font face="宋体">也可以很好的随时读取:</font></span></span></span></strong></p>
<p style="text-align:justify"><strong><span style="font-size:20px;"><span style="font-family:Calibri"><span style="font-family:宋体"><font face="宋体">我们加上</font>DMA<font face="宋体">的配置代码</font></span></span></span></strong></p>
<pre>
<code>csi_adc_set_buffer(&adc1, buff0, 3);
csi_adc_link_dma( &adc1, &dma1);
csi_adc_channel_enable(&adc1, 0, true);
csi_adc_channel_enable(&adc1, 1, true);
csi_adc_channel_enable(&adc1, 2, true);
csi_adc_start_async(&adc1);
while(1)
{
lv_task_handler();
aos_msleep(400);
lv_tick_inc(1);
i=buff0;
printf("adc1:%d ", i);
printf("adc1:%d mv\r\n", i * 3300 / 4095);
i=buff0;
printf("adc1:%d ", i);
printf("adc1:%d mv\r\n", i * 3300 / 4095);
i=buff0;
printf("adc1:%d ", i);
printf("adc1:%d mv\r\n", i * 3300 / 4095);
}</code></pre>
<p class="imagemiddle" style="text-align: center;"></p>
<p class="imagemiddle" style="text-align: center;"> </p>
<p class="imagemiddle">还可以用摇杆配合舵机来操控哈哈</p>
<p class="imagemiddle" style="text-align: center;"> </p>
<p class="imagemiddle" style="text-align: center;"> </p>
<p class="imagemiddle" style="text-align: center;"> </p>
<p style="text-align:justify"><strong><span style="font-size:20px;"> </span></strong></p>
<p style="text-align:justify"> </p>
<p>不错,[大母指]</p>
<p>平头哥的问题,正常阿里云会受理吗?</p>
littleshrimp 发表于 2021-8-31 22:32
不错,[大母指]
平头哥的问题,正常阿里云会受理吗?
<p>会的,周末不上班,应该两天的样子,还可以,就是没有群交流谈论方便</p>
<p>stm32 adc有一处写错了<img height="48" src="https://bbs.eeworld.com.cn/static/editor/plugins/hkemoji/sticker/facebook/wanwan34.gif" width="48" /></p>
<p>辛苦,注意休息注意身体。</p>
页:
[1]