根据提供的adc相关接口,我做了一些测试,但是发现采集到的数据是乱的,ADC使用的是IO5,代码如下:
#define ADC1_PORT_NUM (4)
adc_dev_t mic_adc =
{
ADC1_PORT_NUM,
{0,1000},
NULL,
};
uint8_t adc_buffer[10];
void mic_adc_cb(adc_event_t event, void *data, uint32_t size)
{
int i;
printf("evnet:%d\r\n", event);
if (NULL != data) {
for (i = 0; i < size; i++) {
printf("adc_data:%u\r\n", ((uint16_t *)data)[i]);
}
}
}
void mic_adc_task(void* p)
{
uint32_t adc_value;
while(1)
{
hal_adc_value_get(&mic_adc,&adc_value,HAL_WAIT_FOREVER);
printf("adc:%d\n",adc_value);
aos_msleep(30);
}
}
void mic_adc_init(void)
{
int ret = -1;
ret = hal_adc_init(NULL);
ret = hal_adc_init(&mic_adc);
if(ret != 0)
{
printf("adc init err\n");
}
ret = hal_adc_start(&mic_adc, adc_buffer, 1);
aos_task_new("adc_task",mic_adc_task,NULL,1024);
}
用示波器观察输入信号,ADC输入端的变化很小,结果打印日志如下
adc:746
adc:275
adc:313
adc:2514
adc:302
adc:374
adc:1578
adc:886
adc:898
adc:250
adc:414
adc:2811
adc:1347
adc:2147
adc:1595
adc:1616
adc:261
adc:263
adc:255
adc:1799
adc:1749
adc:329
adc:1318
adc:267
adc:1123
adc:977
adc:268
adc:454
adc:412
adc:1910
adc:994
adc:1565
adc:268
adc:914
adc:1962
adc:247
adc:2760
adc:459
adc:268
adc:1123
adc:3998
adc:1095
adc:2928
adc:1406
adc:257
adc:1766
adc:2557
adc:366
adc:2929
adc:356
adc:376
采用查询的方式,麻烦帮忙看看,非常感谢!