zoukankan      html  css  js  c++  java
  • 2430实验点对点通信实验 皇星客栈

    1,先说主函数,直接进re_test.c 了。主要是:选定RX TX,设定本地,远端地址,初始化发射部分,再就是发送或接受程序了。

      #ifdef RX

       {

        myAddr = ADDRESS_0;

        remoteAddr = ADDRESS_1;

        initRfTest();

                receiveMode();

       }

       #else

       {

        myAddr = ADDRESS_1;

        remoteAddr = ADDRESS_0;

        initRfTest();

                contionuousMode();

       }

       #endif

    }

     

    2,void initRfTest(void)

     {

       UINT32 frequency = 2405000;   //选定频段

       INIT_GLED();

       INIT_YLED();

       radioInit(frequency, myAddr);

     }

    对于radioInit()  其原型是:

    void radioInit(UINT32 frequency, BYTE localAddress)

    {

       sppInit(frequency,localAddress);

       return;

    }

    里面又调用sppInit(),这个函数可就复杂了,也算重点研究对象吧。

    BOOL sppInit(UINT32 frequency, BYTE address)主要功能是:

    初始化简单的数据包装协议Simple Packet Protocol (SPP),从 DMA 管理器申请两个 DMA 通道,用于分别从 Rx FIFO 和 Tx FIFO 传输数据。定时器4管理器同样被设置,这个单元用于在数据包发送后接收器在一定时间内没有返回应答时产生中断。无线部分配置为发送,工作在特定的频率,在发送时自动计算和插入和检查CRC值。

    代码看了很久感觉自己说不好,就不说了,以后再多多体会。

     

    3,再说发射、接受程序,要发射的内容必须放入sendBuffer里面,

    黄灯闪烁表示工作状态,已经进入发射子程序,只有res=true红灯闪烁,才是真正已经发射出去内容了。

      4,发送,接受数据包的程序:

    BOOL radioSend(BYTE* transmitData, WORD dataLength, BYTE remoteAddress, 

                                                                 BYTE doAck);

     Description:

        This function sends data of a given length either to a specified recipient (may be broadcast)   using the radio. If the number of bytes to be transferred is larger than the size of the TX FIFO,  the data is split over an adequate number of packets. The function uses the SPP library. If the  radio is busy, or the packet is sent but not ACK'ed, the transmission is retried. If the retires fails, the function returns FALSE. If the packet is ACK'ed correctly by the receiver.

         BYTE* transmitData------------Pointer to the data to be sent.

          WORD dataLenght------------- The number of bytes to be transferred.

       BYTE remoteAddress------The address of the node to receive the packet. 0 is broadcast address  (BROADCAST_ADDRESS).

    BYTE doAck--------Set to DO_ACK if the packet is to be ACK'ed and DO_NOT_ACK otherwise.

     Return value---BOOL---TRUE if the sent packet is acked by the recipient and false otherwise.

     

     

     

    BOOL radioReceive(BYTE** receiveData, BYTE* length, WORD timeout, BYTE* sender);

     

    Description:           This function turns on the radio receiver and waits until either a correctly addressed packet  is received or the unit has been waiting for a specified time period. The function employsthe SPP library for radio access.

     BYTE** receiveData-------------Double pointer to the received data. This way of reference                  

                                reduces the RAM requirement.

     BYTE* lenght---------------------Pointer to the length of the received data.

     WORD timeout----------------Value indicating how long the receiver will wait for a packet in ms. If no packet is received  within this timeout period, false is returned.  If timeout is set to 0, the function will not return before a packet is received.

    BYTE* sender-----------------The function will fill in the packets source address at this location.

     

    5,打包过程

     

    BYTE sppSend(SPP_TX_STRUCT* pPacketPointer) 

    {                        // Writing the total packet length, addresses and flags to Tx FiFo.

                            // Transferring the payload if any.RFD RF Data

    RFD = (pPacketPointer->payloadLength + SPP_HEADER_AND_FOOTER_LENGTH); 

                                            //加载包长

        RFD = pPacketPointer->destAddress;      //加载目标地址

        RFD = myAddress; //插入源地址(TX结构体中没有)

    RFD = pPacketPointer->flags; //标志

    }

     

    6, 在spp.c中其他重要函数一览:

     

    void sppSetRxCallBackFunction(FUNCTION* callBackFunction)

                      改变正确接收数据包后的动作。callBackFunction 用户指定的函数

     

    void sendAck(SPP_RX_STRUCT* receivedPacket)      //发送应答

     

    void rxCallBack(void)               //在Rx DAM  通道完成数据传输后由中断程序调用。检查接收包掉的目的地址,如果地址不是这个节点的,或CRC值是错误的,包装将被擦除。如果数据包被告知将发送一个应答。一个用户定义的回调函数可以运行如果定义了的话。

     

    void ackTimeout(void)            //如果没有收到接收器返回的应答,将重新发送数据包

     

    void sppSetAddress(BYTE address)

     

    void waitForAck(void)

     

    BOOL ackReceived(BYTE sourceAddress)      //收到一个应答时调用。如果应答是期望的节         

                                             点, 将取消数据包重发。

    __interrupt void spp_rf_IRQ(void)

     

    void sppReceive(SPP_RX_STRUCT* pReceiveData)

     

    __interrupt static void rf_error_IRQ(void)

     

     

  • 相关阅读:
    vue实例讲解之axios的使用
    实例讲解webpack的基本使用第四篇
    实例讲解webpack的基本使用第三篇
    实例讲解webpack的基本使用第二篇
    写好一篇技术博客的正确姿势是什么
    实例讲解js正则表达式的使用
    一个综合实例讲解vue的基础知识点。
    vue实例讲解之vue-router的使用
    .NET 串口通信
    textarea赋值时换行符无效的解决方法
  • 原文地址:https://www.cnblogs.com/huangxingkezhan/p/2958193.html
Copyright © 2011-2022 走看看