Pingtouge RVB2601 board-ADC acquisition and CSI
[Copy link]
According to limited information, CH2601 has an internal ADC, but the pins are connected through the "ARDUINO" interface.
The ADC driver of CH2601 is the CSI interface provided in the YOC development kit. CSI is for embedded systems and defines the unified software interface specifications of the CPU core porting interface and the peripheral device operation interface to eliminate the differences between different chips, simplify the use of software and improve the portability of software. Through the CSI interface specification, the chip can be quickly connected to the YoC platform. There are two types of CSI, CSI1 and CSI2. The function of CSI2 is higher than that of CSI1 in code density, and the abstraction of CSI2 is better.
The ADC of CH2601 can provide "support single conversion and continuous conversion". This test is a single acquisition test. The code is based on the routine of yoc.
The main steps of the procedure are as follows:
1. Enable the pin function csi_pin_set_mux(EXAMPLE_ADC_CHANNEL0_PIN, EXAMPLE_ADC_CHANNEL0_PIN_FUNC);
2. ADC initialization, ret = csi_adc_init(&adc, 0);
3. Set the ADC working sampling frequency ret = csi_adc_freq_div(&adc, 128);
4. Set the sampling period, ret = csi_adc_sampling_time(&adc, 2);
5. Enable ADC channel, ret = csi_adc_channel_enable(&adc, 0, true);
6. Start sampling, ret = csi_adc_start(&adc);
7. Read the sampled data, data = csi_adc_read(&adc);
Steps 6 and 7 can be repeated. The complete procedure is as follows:
#include <drv/adc.h>
#include <drv/tick.h>
#include <board_config.h>
//#include <board_init.h>
#define ADC_CHECK_RETURN(ret) \
do { \
if (ret != CSI_OK) { \
return -1; \
} \
} while(0);
static csi_adc_t adc;
int main(void)
{
int ret;
uint32_t data;
board_yoc_init();
csi_pin_set_mux(EXAMPLE_ADC_CHANNEL0_PIN, EXAMPLE_ADC_CHANNEL0_PIN_FUNC);
ret = csi_adc_init(&adc, 0);
ADC_CHECK_RETURN(ret);
ret = csi_adc_freq_div(&adc, 128);
if(ret == 0){
return -1;
}
/* Configure sampling time */
ret = csi_adc_sampling_time(&adc, 2);
ADC_CHECK_RETURN(ret);
/* Enable channel */
ret = csi_adc_channel_enable(&adc, 0, true);
ADC_CHECK_RETURN(ret);
/* Trigger new conversion */
ret = csi_adc_start(&adc);
ADC_CHECK_RETURN(ret);
/* Read result */
data = csi_adc_read(&adc);
printf("get adc result: %d\n", data);
/* Uninit adc */
csi_adc_uninit(&adc);
LOGD(TAG, "%s\n", aos_get_app_version());
oled_init();
while (1) {
LOGD(TAG, "Hello world! YoC");
aos_msleep(1000);
}
return 0;
}
csi_adc_uninit(&adc); This step is optional. The test results are as follows:
|