首次使用nuvoton开发板,对开发板的众多外设吸引,以前使用的MCU都是小RAM,flash也很小,开发板带有如此多的外设,方便各种验证。同时伴有RT-Thread加持,开发起来是相当顺手的,不再担心驱动问题而查找很多资料,只要看明白结构,就能直接完成应用。
开发板说明:
我做的测试是使用开发板完成4G模块MC615的联网,由于组件中没有MC615的组件,我是使用AT指令进行操作,操作过程如下:
1、驱动配置
串口驱动代码配置
//uart1 init /* 查找系统中的串口设备 */ gps_serial
uart1_serial = rt_device_find(UART1_NANME);
if (!uart1_serial)
{
rt_kprintf("find %s failed!
", UART1_NANME);
return;
}
/* 以中断接收及轮询发送模式打开串口设备 */
rt_device_open(uart1_serial, RT_DEVICE_FLAG_INT_RX);
/* 设置接收回调函数 */
rt_device_set_rx_indicate(uart1_serial, uart1_input);
串口回调操作
static rt_err_t uart1_input(rt_device_t dev, rt_size_t size)
{
/* 串口接收到数据后产生中断,调用此回调函数,然后发送接收信号量 */
rt_uint8_t ch;
//rt_kprintf("dev->ref_count = %d
",dev->ref_count);
rt_device_read(uart1_serial, -1, &ch, 1);
rt_kprintf("%c",ch);
//hal_uart_clrflag(UART0_BASE, UART_FLAG_RXPND);
if(uartdef_t.RxLen > 499)
uartdef_t.RxLen = 0;
uartdef_t.RxBuf[uartdef_t.RxLen++] = ch;
return RT_EOK;
}
2、AT指令列表
/*AT命令列表*/
ATCmdBuf const ATCmdBuf_t[] = {
{AT,"AT"}, //AT命令开始
{ATI,"ATI"}, //模组型号版本
{ATE0,"ATE0"}, //关闭回显
{CPIN,"AT+CPIN?"},
{CICCID,"AT+CICCID"},//A7680
{CCID,"AT+CCID"},//other
{CGREG,"AT+CGREG?"},//
{CSQ_X,"AT+CSQ"},//
{COPS,"AT+COPS?"},//
{CIMI,"AT+CIMI"},//
/*联通运行商*/
{CHINA_UNICOM,"AT+CGDCONT=1,"IP","3GNET""},
/*移动运行商*/
{CHINA_MOBILE_IOT,"AT+CGDCONT=1,"IP","CMMTM""},
/*电信运行商*/
{CHINA_TELECOMMUNICATIONS,"AT+CGDCONT=1,"IP","CTNET""},
{CSOCKSETPN,"AT+CSOCKSETPN=1"},//TPV4设置
{CIPMODE,"AT+CIPMODE=0"}, //Select TCP/IP application mode 应用程序模式
{NETOPEN,"AT+NETOPEN"},//Open socket
//sprintf(itemp,"AT+CIPOPEN=0,"TCP","%s",%s",DomainName,m_Port);
{MIPCALL,"AT+MIPCALL?"},
{MIPCALL_1,"AT+MIPCALL=1"},
{MIPOPEN,"AT+MIPOPEN?"},
//sprintf(itemp,"AT+MIPOPEN=1,,"%s",%s,0",DomainName,m_Port);
{MIPOPEN_1,"AT+MIPOPEN=1,,"39.105.129.87",9000,0"},//端口域名
/*MC615*/
{CPWROFF,"AT+CPWROFF"},//MC615
{MIPCLOSE,"AT+MIPCLOSE=1,3"},//MC615
{QPOWD,"AT+QPOWD=0"},//MC615
};
/*AT命令列表 end*/
3、操作和打印说明 发送函数调用关系在gitee中详细查看。 下载烧录流程 打开NuWriterNuWriterReleaseNuWriter.exe,对开发板进行程序烧录。 串口打印运行结果如下:
打印结果说明:本次使用的服务端口域名指令是AT+MIPOPEN=1,,"39.105.129.87",9000,0,解析该IP返回sim卡的解析IP是+MIPCALL: 100.120.177.139
说明: 由于时间仓促,以前未使用过新唐的MCU,在调试程序配置的过程中花费很多时间,以上操作流程如有错误请及时指正,如有探讨请及时留言,谢谢。
|