记WinCE下调试SIM900 GSM module
記WinCE下調試SIM900 GSM module
近幾天在調試sim900,把遇到的一些問題總結下吧。
一、一些引腳的說說明。
Sim900有幾個引腳需要了解下。
1.? CTS、RTS 由于使用了流控制,來提高傳輸效率。首先要清楚幾個概念。
?????? 什么是CTS、RTS:在sim900模塊中,
?????? RTS是模塊的輸入端,用于MCU通知模塊,MCU是否準備好,模塊是否可向MCU發送信息,RTS的有效電平為低。
CTS是模塊的輸出端,用于模塊通知MCU,模塊是否準備好,MCU是否可向模塊發送信息,CTS的有效電平為低
而在我們的MCU上面,一般RTS為輸出端,CTS為輸入端,所以,DCE(數據通信端)的RTS、CTS直連CTE(數據終端)的RTS、CTS。
AFC:自動流控制,在我用的2450中視這樣描述的,
UART 0, UART 1 and UART 2 support auto flow control with nRTS and nCTS signals.? In AFC, nCTS signals
control the operation of the transmitter, and nRTS depends on the condition of the receiver.
The UART's transmitter transfers the data in FIFO only when nCTS signals are activated(Low) (In AFC, nCTS
means that other UART's FIFO is ready to receive data or not).?
Before the UART receives data, nRTS signal has to be activated(Low) when its receive FIFO has a spare space more than 32-byte(FIFO contains less than 32-byte). And nRTS signal has to be inactivated(High) when its receive FIFO has a spare under 32-byte(FIFO contains equal or more than 32-byte) in case of RTS trigger level is 32byte. (In AFC, nRTS means that its own receive FIFO is ready to receive data or not).
??????
大意是在自動流控(AFC)模式下nRTS取決于接收端的狀態,而nCTS控制了發送端的操作。具體地說:只有當nCTS有效(低電平)時(表明接收方的FIFO已經準備就緒來接收資料了),UART才會將FIFO中的資料發送出去。在UART接收資料之前,只要當接收FIFO有至少32-byte空余的時候,nRTS就會被置為有效。
?
?????? 同樣的,我們在串口初始化的時候需要配置寄存器以開啟MCU的AFC自動流控制功能。
?
2.??? DTR: 當設置AT+CSCLK=1 開啟Sleep后(默認是關閉的)
When DTR is in high level and there is no on air and hardware interrupt (such as GPIO interrupt or data on serial port), SIM900 will enter SLEEP mode automatically.
?
當DTR為非激活狀態(高電平),且沒有硬件中斷和串口數據時,sim900會自動進入sleep,所以當你不想進入Sleep時,需要保持激活DTR,即保持低電平。
其次可能你的串口驅動并沒有實現DTR引腳,或者引腳對不上,因為在某些芯片上并沒有像CTS、RTS一樣的標準復用GPIO。
即在串口驅動的PDD層中重寫這個MDD層的純虛函數virtual void??? SetDTR(BOOL bSet) = 0;
這樣你就可以通過調用API EscapeCommFunction(),設置參數CLRDTR 和 SETDTR來控制DTR。
?
3.??? RI: 在sim900中,RI在待機中保持高電平,當有語音呼入,或者短信接入的時候會發生跳變,應此,我們可以將它接MCU的EINT 外部中斷引腳,以便當系統進入Sleep時,當有短信來電時,可以喚醒系統。
4.??? NRESET:通過外部引腳可以使模塊復位,低電平有效。
?
二、關于初始化。
1.Sim900默認是自動識別主機端波特率的,但是波特率必須小于115200bps,而為了使用多路復用,要設置到115200bps,關于為什么,后面會提到。
2.因為初始化應在sim900上電一段時間后進行,為了不影響系統的啟動速度,我們可以將初始化和多路復用驅動加載的動作放到線程中,這樣會在NK起來以后,線程還會對sim900進行初始化、并加載多路復用。這樣開機啟動時間就不會受到影響了。
?
初始化部分代碼如下,模塊上電后,我便會打開串口,來檢測sim900是不是首次被初始化,因為sim900被設置為非自動識別波特率后,上電會往主機端發送“RDY”字符串。下面是一些src..比較散亂。
[cpp]?view plaincopy
?
?
?
?
三、關于多路復用驅動。
廠家給了2個文件,mux_sim900.reg和mux_sim900.dll
我的mux_sim900.reg 設置如下:
; COM1 for underlying GSM 07.10
[HKEY_LOCAL_MACHINE/Software/Microsoft/GSM07_10]
??????? "ComPort"="COM1:"????????????????????? ;對應你連接sim900的物理UART
??????? "DefaultBaudRate"=dword:1C200???????? ; 115200?? ;這2處的波特率只能為115200,原因請往下看。
??????? "BaudRate"=dword:1C200????????????? ; 115200?
??????? "FrameOption"=dword:0?????????????? ; 1 - Advanced; 0 -Basic
??????? "FrameSize"=dword:0000007F????????? ; max data size
???????
?
[HKEY_LOCAL_MACHINE/Drivers/BuiltIn/GSM0710_1/Unimodem]
??????? "Tsp"="Unimodem.dll"
??????? "FriendlyName"="SIM900 MUX Modem"
??????? "DeviceType"=dword:1
???
[HKEY_LOCAL_MACHINE/Drivers/BuiltIn/GSM0710_1/Unimodem/Init]
??????? "1"="AT<cr>"
??????? "2"="ATE0V1&C1&D2<cr>"
?
[HKEY_LOCAL_MACHINE/Drivers/BuiltIn/GSM0710_1/Unimodem/Settings]
??????? "Prefix"="AT"
??????? "Terminator"="<cr>"
??????? "DialPrefix"="D"
??????? "DialSuffix"=";"
??????? "Pulse"="P"
??????? "Tone"="T"
??????? "Blind_Off"="X4"
??????? "Blind_On"="X3"
??????? "CallSetupFailTimeout"="ATS7=<#><cr>"
??????? "Reset"="AT<cr>"???
??????? "EscapeDelay"=dword:3E8
??????? "EscapeWait"=dword:3E8
?
[HKEY_LOCAL_MACHINE/Drivers/GSM0710_1]
??????? "Prefix"="COM"
??????? "Dll"="mux_sim900.dll"
??????? "FriendlyName"="SIM900 MUX Port on COM3:"
??????? "DeviceArrayIndex"=dword:1
??????? "Index"=dword:3
??????? "Order"=dword:2
??????? ; power manager enabled device driver
??????? "IClass"="{A32942B7-920C-486b-B0E6-92A702A99B35}"??
??????? ; GSM 07.10 specific
??????? "GSM_0710_DLCI"=dword:1???? ; Rem: Dlci also define priority (lowest => low prio)
??????? "GSM_0710_TYPE"=dword:1???? ; boolean: 1 (true) => AT cmd, 0 (false) => Data???
??????? ; monitor channel activity
??????? "GSM_0710_ACTIVITY_TIMEOUT"=dword:2710????? ; time-out on channel activity in ms
??????????????????????????????????????????????????? ; remark:
??????????????????????????????????????????????????? ; the Mux driver will notify the device
??????????????????????????????????????????????????? ; when this time-out expire
??????????????????????????????????????????????????? ; if there is no activity???????
?
[HKEY_LOCAL_MACHINE/Drivers/GSM0710_2]
??????? "Prefix"="COM"
??????? "Dll"="mux_sim900.dll"
??????? "DeviceArrayIndex"=dword:1
??????? "Index"=dword:4
??????? "FriendlyName"="SIM900 MUX Port on COM4:"
??????? "Order"=dword:3
??????? ; power manager enabled device driver
??????? "IClass"="{A32942B7-920C-486b-B0E6-92A702A99B35}"??
??????? ; GSM 07.10 specific
??????? "GSM_0710_DLCI"=dword:2???? ; Rem: Dlci also define priority (lowest => low prio)
??????? "GSM_0710_TYPE"=dword:1???? ; boolean: 1 (true) => AT cmd, 0 (false) => Data
??????? ; monitor channel activity
??????? "GSM_0710_ACTIVITY_TIMEOUT"=dword:4E20????? ; time-out on channel activity in ms
??????????????????????????????????????????????????? ; remark:
??????????????????????????????????????????????????? ; the Mux driver will notify the device
??????????????????????????????????????????????????? ; when this time-out expire
??????????????????????????????????????????????????? ; if there is no activity
?
[HKEY_LOCAL_MACHINE/Drivers/GSM0710_3]
??????? "Prefix"="COM"
??????? "Dll"="mux_sim900.dll"
??????? "DeviceArrayIndex"=dword:1
??????? "Index"=dword:5
??????? "FriendlyName"="SIM900 MUX Port on COM5:"
??????? "Order"=dword:4
??????? ; power manager enabled device driver
??????? "IClass"="{A32942B7-920C-486b-B0E6-92A702A99B35}"??
??????? ; GSM 07.10 specific
??????? "GSM_0710_DLCI"=dword:3???? ; Rem: Dlci also define priority (lowest => low prio)
??????? "GSM_0710_TYPE"=dword:1???? ; boolean: 1 (true) => AT cmd, 0 (false) => Data
??????? ; monitor channel activity
??????? "GSM_0710_ACTIVITY_TIMEOUT"=dword:7530?? ; time-out on channel activity in ms
??????????????????????????????????????????????????? ; remark:
??????????????????????????????????????????????????? ; the Mux driver will notify the device
??????????????????????????????????????????????????? ; when this time-out expire
??????????????????????????????????????????????????? ; if there is no activity
?
?
?
以上,我復用了3個端口,COM3,COM4,COM5,其中COM3 用于GPRS撥號,
把他們放到Drivers/下而不是Drivers/BuiltIn下的原因是,因為我會在上面的線程中手動加載,這樣便于我靈活的控制sim900模塊,而且大大提高了wince啟動速度。
?
?
四、關于波特率。
之前設置的波特率為19200,發現多路復用起來以后,并不能正常工作,現象比較搞笑,我發什么數據復用端口就返回什么數據。
后來把串口驅動的收發數據全部打印了出來,對照sim900的多路復用協議,看出了一些蹊蹺,發現我發出的AT指令,接受數據中包含了正常數據。后來發現多路復用驅動在初始化建立通道的時候會發送AT+CMUX,并把多路通道的波特率鎖死到了115200bps,而不是根據注冊表的那2個值。
經過一番折騰之后,sim900的多路復用終于正常工作了。
總結
以上是生活随笔為你收集整理的记WinCE下调试SIM900 GSM module的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: winec7初体验
- 下一篇: 将SVN与BUG跟踪管理集成