rt-thread AT設備EC20參數配置

在使用AT軟件包的時候,這裏有一個電源引腳和電源狀態引腳的配置。
在這裏插入圖片描述
對應的代碼包含電兩個管腳的初始化配置和上電斷電函數。
在這裏插入圖片描述

static void ec20_power_on(struct at_device *device)
{
    struct at_device_ec20 *ec20 = RT_NULL;

    ec20 = (struct at_device_ec20 *)device->user_data;

    /* not nead to set pin configuration for ec20 device power on */
    if (ec20->power_pin == -1 || ec20->power_status_pin == -1)
    {
        return;
    }

    if (rt_pin_read(ec20->power_status_pin) == PIN_HIGH)
    {
        return;
    }
    rt_pin_write(ec20->power_pin, PIN_HIGH);

    while (rt_pin_read(ec20->power_status_pin) == PIN_LOW)
    {
        rt_thread_mdelay(10);
    }
    rt_pin_write(ec20->power_pin, PIN_LOW);
}

static void ec20_power_off(struct at_device *device)
{
    struct at_device_ec20 *ec20 = RT_NULL;

    ec20 = (struct at_device_ec20 *)device->user_data;

    /* not nead to set pin configuration for ec20 device power on */
    if (ec20->power_pin == -1 || ec20->power_status_pin == -1)
    {
        return;
    }

    if (rt_pin_read(ec20->power_status_pin) == PIN_LOW)
    {
        return;
    }
    rt_pin_write(ec20->power_pin, PIN_HIGH);

    while (rt_pin_read(ec20->power_status_pin) == PIN_HIGH)
    {
        rt_thread_mdelay(10);
    }
    rt_pin_write(ec20->power_pin, PIN_LOW);
}

那麼這裏就存在兩個問題,第一個是上電有效電平:
在這裏插入圖片描述
根據這裏的硬件設計,我是PWR_ON=0的時候,EC20的供電纔有輸出,所以這裏的有效電平需要修改。
另外一個,就是我們並沒有做額外的電源狀態power_status_pin,其實可以直接讀取power_pin的值就行了,如果我們把兩個引腳設置爲同一個,那麼這個引腳就會先被配置成輸出模式,再被配置成輸入模式,實際並沒有辦法輸出,所以這裏的順序也要修改一下。
修改之前的運行效果是這樣的:
在這裏插入圖片描述
修改完了重新下載程序,初始化成功。
在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章