天天看點

U1 NB IOT 實作序列槽接收資料

此部分内容建立在U1 阿裡雲Coap接入例程的基礎上。

使用必讀:

按本文的做法,序列槽必須選擇U1,選擇其他序列槽編譯可以過,但會報CPU運作錯誤,原因不明。

上雲資料不能選擇太多,選太多了會報push error錯誤,多了會頻繁掉線,原因不明。

AT PARSER的方法使用序列槽可以編譯成功,但運作會報oob建立失敗錯誤,原因不明。

USART1序列槽波特率必須是921600.

序列槽初始化部分

代碼如下:

aos_dev_t* usart_handle; //序列槽句柄,全局變量
int main(void)
{
  board_yoc_init();

    drv_pinmux_config(GP07, GP07_FUNC_U1TXD);
    drv_pinmux_config(GP08, GP08_FUNC_U1RXD);
    int32_t err;
    usart_handle = csi_usart_initialize(1, handler);
    err=csi_usart_config_baudrate(usart_handle, 921600);
    csi_usart_config_mode(usart_handle, USART_MODE_ASYNCHRONOUS);
    csi_usart_config_databits(usart_handle, USART_DATA_BITS_8);
    csi_usart_config_stopbits(usart_handle, USART_STOP_BITS_1);
    csi_usart_config_parity(usart_handle, USART_PARITY_NONE);
    csi_usart_config_flowctrl(usart_handle,USART_FLOWCTRL_NONE);
    csi_usart_control_tx(usart_handle, 1);
    csi_usart_control_tx(usart_handle, 1);
    csi_usart_set_interrupt(usart_handle, USART_INTR_READ, 1);
    LOGI(TAG, "USART INIT %d",err);
}           

注意,序列槽設定必須在 board_yoc_init(); 函數後,這樣的作用是禁用CLI,否則序列槽發來資料會被當做指令,然後報錯。

序列槽回調函數

代碼如下,這是上面代碼usart_handle = csi_usart_initialize(1, handler);中handler的具體實作。

void handler(int32_t idx, usart_event_e event){
    if(idx==1){
        if(event==USART_EVENT_RECEIVED){
            uint8_t ch;
            csi_usart_getchar(usart_handle, &ch);
            // ch就是擷取到序列槽發來的資料,可以接入自己的實作處理
        }
    }
}           

總結

使用上面兩部配置設定置,U1闆子的usart1序列槽就可以用來與其他硬體通信接收資料,但是無法使用CLI,不過LOG仍然可以正常使用。上傳效果如下

U1 NB IOT 實作序列槽接收資料

文章來源:晶片開放社群

原文連結:

https://occ.t-head.cn/community/post/detail?spm=a2cl5.14300636.0.0.1b87180flNT4Fc&id=3805394150393262080

繼續閱讀