zoukankan      html  css  js  c++  java
  • ZigBee学习三 UART通信

    ZigBee学习三 UART通信

    在使用串口时,只需掌握ZigBee协议栈提供的串口操作相关的三个函数即可。

    uint8 HalUARTOpen(uint8 port,halUARTCfg_t *config);

    uint16 HalUARTRead(uint8 port,uint8 *buf,uint16 len);

    uint16 HalUARTWrite(uint8 port,uint8 *buf,uint16 len);

    本实验只对coordinator.c文件进行改动就可以实现串口的收发。

    修改coordinator.c文件

    byte GenericApp_TransID; // This is the unique message ID (counter)

    afAddrType_t GenericApp_DstAddr;

    unsigned char uartbuf[128];
    /*********************************************************************
    * LOCAL FUNCTIONS
    */
    static void GenericApp_ProcessZDOMsgs( zdoIncomingMsg_t *inMsg );
    static void GenericApp_HandleKeys( byte shift, byte keys );
    static void GenericApp_MessageMSGCB( afIncomingMSGPacket_t *pckt );
    static void GenericApp_SendTheMessage( void );

    static void rxCB(uint8 port,uint8 event);

    void GenericApp_Init( uint8 task_id )
    {
      halUARTCfg_t uartConfig;
      GenericApp_TaskID = task_id;
      GenericApp_NwkState = DEV_INIT;
      GenericApp_TransID = 0;

      ... ...

      GenericApp_epDesc.simpleDesc= (SimpleDescriptionFormat_t *)&GenericApp_SimpleDesc;
      GenericApp_epDesc.latencyReq = noLatencyReqs;

      afRegister( &GenericApp_epDesc );

      uartConfig.configured   = TRUE;
      uartConfig.baudRate    = HAL_UART_BR_115200;
      uartConfig.flowControl    = FALSE;
      uartConfig.callBackFunc  = rxCB;  //配置串口调用函数

      //对串口进行初始化
      HalUARTOpen(0,&uartConfig);  //该函数将halUARTCfg_t类型的结构体变量作为参数,而halUARTCfg_t结构体变量包含了串口初始化相关的参数。

    }

     //该函数是一个空函数。因为本实验并没有进行事件处理,所有不需要任何代码

    uint16 GenericApp_ProcessEvent( uint8 task_id, uint16 events )
    {

    }

    static void rxCB(uint8 port,uint8 event)
    {

      if (event & (HAL_UART_RX_FULL | HAL_UART_RX_ABOUT_FULL | HAL_UART_RX_TIMEOUT))  //接收到串口数据

      {
        HalUARTRead(0,uartbuf,16);  //读取数据并存放到uartbuf数组中
        if(osal_memcmp(uartbuf,"www.wlwmaker.com",16)) //使用osal_memcmp()函数判断接收到的数据是否是字符串"www.wlwmaker.com",如果是,执行{}
        {
          HalUARTWrite(0,uartbuf,16); //调用HalUARTWrite()函数将接收到的字符输出到串口
        }

      }
    }

  • 相关阅读:
    删除XML文档中某节点
    水晶报表之创建子报表
    给字符串中的每个字符加上单引号
    Failed to export using the options you specified. Please check your options and try again
    从ASP.NET传递参数给水晶报表
    两个文本框异动任何一个能即时更新计算结果
    添加节点至XML文档中去
    读取XML文档存入泛型List<T>集合中
    泛型List<T>转存为XML文档
    怎样创建XML文档
  • 原文地址:https://www.cnblogs.com/liushao/p/6351635.html
Copyright © 2011-2022 走看看