【已解决】关于axyu模组的adc使用

Wi-Fi 设备、Wi-Fi 低功耗设备、Wi-Fi BLE 双模设备、Ethernet设备、Ethernet+Wi-Fi设备等
Post Reply
a93749
Posts: 10

求助我该如何初始化axyu模组的adc脚,具体是哪个adc的通道几。我使用的是下面这个来初始化和读取数据 显示报错 -4不支持。

Code: Select all

#define ADC_CHANNEL             1


STATIC TUYA_ADC_BASE_CFG_T sg_adc_cfg = {
        .ch_list.data = 1 << ADC_CHANNEL,
        .ch_nums = 1, // adc Number of channel lists
        .width = 12,
        .mode = TUYA_ADC_CONTINUOUS,
        .type = TUYA_ADC_EXTERNAL_SAMPLE_VOL,
        .conv_cnt = 1,
    };
    STATIC VOID_T app_bat_task(VOID_T *args)
{
    OPERATE_RET rt = OPRT_OK;
    INT32_T adc_value = 0;

/* ADC 0 channel 2 init */
   
while(1){
    tal_system_sleep(2000);
    TUYA_CALL_ERR_LOG(tkl_adc_read_single_channel(TUYA_ADC_NUM_0, ADC_CHANNEL, &adc_value));
    TAL_PR_DEBUG("ADC%d value = %d", TUYA_ADC_NUM_0, adc_value);}
}

VOID_T app_bat_init(TUYA_GPIO_NUM_E pin_id)
{
    // sg_bat_pin_id=pin_id;
    OPERATE_RET rt = OPRT_OK;

/* init bat gpio 
TUYA_GPIO_BASE_CFG_T key_cfg = {
    .mode = TUYA_GPIO_PULLUP,
    .direct = TUYA_GPIO_INPUT,
    .level = TUYA_GPIO_LEVEL_HIGH};
TUYA_CALL_ERR_LOG(tkl_gpio_init(pin_id, &key_cfg));
sg_bat_pin_id = pin_id;*/

   
TUYA_CALL_ERR_LOG( tkl_adc_init(TUYA_ADC_NUM_0, &sg_adc_cfg));

THREAD_HANDLE bat_task_handle;
THREAD_CFG_T thread_cfg = {
    .thrdname = "bat_task",
    .priority = THREAD_PRIO_6,
    .stackDepth = 2048
};

TUYA_CALL_ERR_LOG(tal_thread_create_and_start(&bat_task_handle, NULL, NULL, app_bat_task, NULL, &thread_cfg));

}
Last edited by a93749 on 2023年 Jul 23日 13:26, edited 1 time in total.

Tags:
a93749
Posts: 10

Re: 求助,关于axyu模组的adc使用

解决了 找到了一个adc_find_port_ch函数和一个adc_pin_map数组完美解决上述问题,读取adc数据要用tkl_adc_read_data()。

Post Reply