這一節繼續繼承之前幀過濾部分,首先補充一下關於幀過濾部分,如果將目標地址設置為0xFFFF,則同一個網絡(物理頻道與PANID 都相同),所有節點都應該收到這條信息,這個信息為廣播信息,0xFFFF為廣播地址。
廣播信息在測距定位中很有用,標簽廣播一個消息,所有周圍的基站收到廣播信息回復即可,標簽不同和各個基站單聊了。
補充完上面的知識,接着說自動應答,自動應答的作用是收到信息后,通過幀過濾后,如果本條信息是發給我的,我就會自動回復一條應答,這個回復行為是硬件實現的,這個應答時間非常快,在有應答的網絡通信中,利用應答可以保證數據正確傳輸。當然,我的目標是用來測距的,利用幀過濾和自動應答可以實現非常快的測距,雖然還沒有具體概念,后面慢慢實現。
先上一段關於自動應答的說明,直接上英文,沒空翻譯了
• Frame filtering must be enabled and the received data or MAC command frame must be correctly
addressed and pass through the receive frame filtering, (see section 5.2 - Frame filteringfor
details of frame filtering configuration). • The ACK request bit in the frame control field of the received frame must be set. • Auto-acknowledgement must be enabled by the AUTOACK configuration in Register file: 0x04
– System Configuration.
大概意思 1 必須使能幀過濾 2 收到的信息必須有應答請求 3系統必須使能自動應答
在上一例中已經實現了幀過濾,只需要在發送端增加“應答請求”,在接收端使能“自動應答“
發送端主要代碼修改
msg_f.frameCtrl[0] = 0x1 /*frame type 0x1 == data*/ | 0x40 /*PID comp*/|0x20/* ACK request*/;
接收端使能自動應答
dwt_enableautoack(1);
其中參數為turnaround 時間,接收到信息多久發出自動應答,這個很重要,以后會用。關於這個函數,我略做修改。
void dwt_enableautoack(uint8 responseDelayTime) { uint8 temp = 0; temp |= (uint8)(SYS_CTRL_TXSTRT | SYS_CTRL_TRXOFF) ; dwt_writetodevice(SYS_CTRL_ID,0,1,&temp) ; // Set auto ACK reply delay dwt_write16bitoffsetreg(ACK_RESP_T_ID, 0x2, (responseDelayTime << 8) ) ; //in symbols // Enable auto ACK dw1000local.sysCFGreg |= SYS_CFG_AUTOACK; dwt_write32bitreg(SYS_CFG_ID,dw1000local.sysCFGreg) ; }
增加了對SYS_CTRL_TXSTRT和SYS_CTRL_TRXOFF寫操作,因為在DM1000 手冊上有如下描述
The most efficient way to ensure the SFD sequence is correctly initialised is to simultaneously initiate and abort a transmission thereby forcing the SFD initialisation. This can be done by writing to the the system control register Register file: 0x0D – System Control Register with both the transmission startbit TXSTRT and the transceiver off bit TRXOFF set at the same time
大概意思是初始化SFD,可以通過寫SYS_CTRL_TXSTRT和SYS_CTRL_TRXOFF 非常有效快速的完成。
上面就是修改的主要代碼了。 關於自動應答實驗的方法。
1 TX端發送信息,在RX端看是否有ATT標識,並且是否有TXFRS,ATT標識表明收到一條有應答請求的消息,而TXFRS表明接收端已經發送了一條應答。
2 在TX端增加接收代碼,打印自動應答消息
打印結果如圖,每次回打印5個字節,下面是多次打印
DM1000手冊描述,自動應答為5個字節,與收到的信息一致。
下面是IEEE 關於MAC應答幀的描述,兩張圖自己看,確實符合規范!
還有一點,MAC 應答幀,幀過濾不了,直接送到上層!
最后,老規矩,源碼放到bphero.com.cn 論壇了,有需要學習的可以下載