Microchip
直播中

马知一

7年用户 216经验值
私信 关注
[问答]

无法使用C代码进入命令模式

我使用一个PIC32 MX795F12微控制器和一个RN42蓝牙到UART模块。我可以发送文本到UART,在115200波特没有问题。使用P腻y,我也可以输入命令$$进入命令模式并获得CMD响应。不幸的是,我无法使用C代码进入命令模式。我这样做的命令如下:“UART3WrreEnStand($$ $$)”;“函数定义为:},当我这样做时,RN42不进入命令模式。它只是在没有CMD响应的情况下输出$$。有什么想法吗?谢谢!

以上来自于百度翻译


      以下为原文

    I am using a PIC32MX795F12 microcontroller together with a RN42 bluetooth to UART module.
I can send text to the UART with no problem at 115200 baud. Using Putty I can also enter the command $$$ to enter the command mode and get the CMD response. Unfortunately I've not been able to enter the command mode using the C code. My command to do this is as follows:
"UART3WriteString("$$$");"
where the function is defined as:
void UART3WriteString(const char * str) {
while( *str ) {
U3TXREG = *str++;
while( U3STAbits.TRMT == 0 ); //wait for the transmission to be done)
}}
When I do this, the RN42 does not go into the command mode. It just outputs $$$ without the CMD response.
Any ideas?
Thanks!

回帖(2)

李麒铭

2019-3-20 11:32:20
好的,我在Microchip站点的热门话题中找到了答案。基本上我需要在发布$$ $命令之前和之后插入一个250毫秒的缓冲区。否则,RN42将不会进入命令模式。

以上来自于百度翻译


      以下为原文

    Ok, I found the answer in the hot topics part of the microchip site.
Basically I need to insert a 250 ms buffer before and after issuing the $$$ command. Otherwise the RN42 will not enter Command mode.
 
举报

王焕树

2019-3-20 11:49:00
这是一个很长的历史,回到1980调制解调器的海因斯调制解调器中,虽然他们使用了“+++”和一秒钟的延迟。http://En.维基百科…org……如果你这样做,你可能需要使你的250MS延迟更长一点,或者在调用延迟之前添加一个等待TrMT。

以上来自于百度翻译


      以下为原文

   
You got it.
This has a long history, going back to Hayes modems in the 1980's, although they used "+++" and a one second delay.
https://en.wikipedia.org/..._set#Hayes.27_solution
Note, your transmit routine is inefficient, it prevents the PIC doing anything while the UART peripheral does the transmitting.
You can make it more efficient by changing to:

void UART3WriteString(const char * str) {
    while( *str ) {
        while (U3STAbits.UTXBF);    //wait until room in transmit buffer
        U3TXREG = *str++;
    }
}
If you do this, you may need to make your 250ms delay a little longer, or add a wait for TRMT before calling the delay.
 
举报

更多回帖

发帖
×
20
完善资料,
赚取积分