完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
大家好,我想通过HC-05蓝牙模块发送一个电位器的值,所以,正如我看到的,一旦配对,我只需要通过模块的UART把我想要的东西发送到以前配置好的BurdRead上。问题开始了。一个模块在PIC上,另一个模块通过RS232转换器插入PC。在我的终端有一些字符,但没有一些预期,他们改变时,我改变我的电位器值显示在我的终端的CalaCutt正在改变,但仍然不是我预期的一个。
以上来自于百度翻译 以下为原文 Hi everyone, I want to send a value of a potentiometer through HC-05 bluetooth module so, as i saw, once paired, i just need to send what i want to through the uART of the module at the right baudrate previously configured. I paired both of the module, and started the communication and here is where the issue begin. One module is on a pic and the other one is plug into pc through rs232 converter. On my terminal there is some characters but not some expected and they change when i change my potentiometer value the caractere displayed on my terminal are changing but still not the one I expect. |
|
相关推荐
19个回答
|
|
也许你发送的是原始数字而不是ASCII字符,这是首选的。
以上来自于百度翻译 以下为原文 Maybe you're sending raw numbers instead of ASCII chars, which would be preferred |
|
|
|
我检查了调试器,它看起来像IM发送ASCII char…当它假设发送0000和CR它看起来像这样我的发送器代码是:我的UART设置是(我想要115200波特,1停止,0奇偶校验)
以上来自于百度翻译 以下为原文 I checked with the debugger and its seems like Im sending ascii char ... when its suppose to send 0000 and CR it look like this My sender code is : unsigned short Serial_Test_ENVOI (unsigned short Res_Test) { char test[7]; unsigned short res; int i=0; test[0]='$'; test[5]='%'; test[6]=0x0D; //Debut de la conversion HEXA TO INT ASCII //Millier if(Res_Test>0x03E8) //si Res_test > 1000 { i=0; while(Res_Test>0x03E8) { Res_Test=Res_Test-0x03E8; i++; } test[1]=i; i=0; } else { test[1]=0; } //Centaine if(Res_Test>0x0064) //si Res_Test >100 { i=0; while(Res_Test>0x0064) { Res_Test=Res_Test-0x0064; i++; } test[2]=i; i=0; } else { test[2]=0; } //Dizaine if(Res_Test>0x000A) //si Res_Test >10 { i=0; while(Res_Test>0x000A) { Res_Test=Res_Test-0x000A; i++; } test[3]=i; i=0; } else { test[3]=0; } //Unité if(Res_Test>0x000A) //si Res_Test >1 { i=0; while(Res_Test>0x0001) { Res_Test=Res_Test-0x0001; i++; } test[4]=i; i=0; } else { test[4]=0; } test[1]+=0x30; test[2]+=0x30; test[3]+=0x30; test[4]+=0x30; // TXREG = '$';//test[0]; //$ // while (!TXSTAbits.TRMT); TXREG = test[1]; //millier while (!TXSTAbits.TRMT); TXREG = test[2]; //centaine while (!TXSTAbits.TRMT); TXREG = test[3]; //dizaine while (!TXSTAbits.TRMT); TXREG = test[4]; //unité while (!TXSTAbits.TRMT); //TXREG = test[5]; //% // while (!TXSTAbits.TRMT); //TXREG = 'n'; //% while (!TXSTAbits.TRMT); //for(i=0;i<100000000000000;i++){} res=((test[1]-0x30)*1000)+((test[2]-0x30)*100)+((test[3]-0x30)*10)+((test[4]-0x30)*1); return res; } And my UART Setting is (i want 115200 baud, 1 stop, 0 parity) RCSTAbits.SPEN=1; TXSTAbits.TXEN=1; TXSTAbits.TX9=0; TXSTAbits.SYNC = 0; // ### Load TXSTA from TxConUser TXSTAbits.BRGH = 1; TXSTAbits.SENDB=1; SPBRG = 10; // ### Write baudrate to SPBRG1 9600 BAUDCONbits.BRG16 = 0; RCSTAbits.SPEN = 1; RCSTAbits.RX9=0; RCSTAbits.CREN=1; |
|
|
|
可能是波特率问题-通常归结为配置设置和振荡器配置-我们都看不到。苏珊
以上来自于百度翻译 以下为原文 Could be a BAUD rate problem - which often comes down to the CONFIG settings and the oscillator configuration - we can see neither. Susan |
|
|
|
正如苏珊所说,你首先需要检查波特率问题。您在代码中的注释表示9600波特,但是如果没有其他配置设置,我们不能检查它。希望你不会混合波特率。你的屏幕截图显示Realterm有115200波特。我不知道PC侧HC05的波特率和PIC侧HC05波特率是否应该匹配。从技术上讲,这不是必需的,但我不会以不同的设置开始测试。当然,连接到PIC的个人HC05的设置必须与PIC相匹配,并且连接到PC的一个必须匹配您的实时设置。HC-05的默认波特率为9600,您没有提到是否显式重新配置模块,或者在运行时是否执行该配置。你可能同时测试太多的东西。毕竟你还不知道这两个模块之间的蓝牙连接是否符合你的预期。所以首先,你的电位器和ASCII转换只会带来额外的问题,在这个测试阶段不需要。对于这个测试,只发送“众所周知”的VA。对UART,例如,把它放在一个合适的循环中。接下来,如果你能告诉你,你是否能看到PIC所发送的每个字符中Realterm的一个字符的确切值(1∶1)。(交替地,可能有字符丢失,或者可能有比发送更多的字符,或者当您不发送任何字符时,PC甚至可能显示接收字符)。如果是,找出接收字符的十六进制值。如果Realterm不能显示这一点,使用HyTalm。如果“否”,那么再次检查波特率和其他串行配置。如所说,知道是否可以成功地从PC上与HC05连接到PC上是很有意思的。同样,对于PIC方面,您没有告诉,您是否已经。测试您的PIC和HC05之间的UART通信是其他(本地)工作的。例如,您可能会尝试用PIC读取来自模块的响应,或者查看TX /RX线。如果需要更多帮助,您需要指定PIC并显示更多的代码和配置设置。
以上来自于百度翻译 以下为原文 As Susan said you need to check your baud rate issues first. Your comment in the code says 9600 baud, but we cannot check that without further configuration settings. Hopefully you are not mixing baud rates. Your screen shot shows Realterm with 115200 baud. I cannot tell whether the baud rate of the PC side HC05 and the baud rate of the PIC side HC05 should match. Technically it is not required, but I would not start my tests with different settings. Of course the settings for the individual HC05 attached to the PIC must match the PIC and the one attached to the PC must match your RealTerm setting. The default baud rate for the HC-05 is 9600, you did not mention whether you explicitly re-configured the modules, or whether you do that at run-time. You are possibly testing too many things at the same time. After all the you do no yet know whether the Bluetooth connection between the two modules works as you would expect it. So first, your potentiometer stuff and ASCII conversion can only introduce additional problems, it is not required at this stage of testing. For this test, only send 'well known' values to the UART, e.g. TXREG = '4'; while (!TXSTAbits.TRMT); TXREG = '2'; while (!TXSTAbits.TRMT); TXREG = 0x0d; while (!TXSTAbits.TRMT); TXREG = 0x0a; while (!TXSTAbits.TRMT); and put it into a suitable loop. Next it would help, if you can tell, whether you see exactly (1:1) one single character in Realterm for each character sent by the PIC. (alternately there may be characters dropped, or there might be more characters than sent, or the PC might even show receiving characters, when you don't send any). If yes, find out, which hex value the received characters have. If Realterm cannot show that, use e.g. HTERM. If 'no' then again check baud rate and other serial configuration. As said, it would be interesting to know whether you can successfully communicate from the PC with the HC05 attached to the PC. Same for the PIC side, you did not tell, whether you already tested that the UART communication between your PIC and the HC05 is otherwise (locally) working. E.g. you might try to read an immediate AT response from the module with the PIC, and or look at the TX/RX line. If you need more help you need to specify your PIC and show more code and configuration settings. |
|
|
|
谢谢你的回答,这里是我的设置,我实际上重新配置蓝牙模块,以两个(PC一方和PIC一方)工作与115200波特1停止1奇偶校验,我设法沟通与这两个与PC配置,但我没有尝试配置PIC一方智慧h PIC。然后我试着,正如你告诉我的,发送你著名的ASCII字符,还有我在PIC的UART输出中得到的东西(它应该发送给BT模块):ASCII:六:二进制:我希望我给你所有需要的来解决我的问题,因为我看不出它能从哪里来。
以上来自于百度翻译 以下为原文 Thanks for your answer, here are my settings #include "system.h" /** CONFIGURATION Bits **********************************************/ #pragma config PLLDIV = 6 // (24 MHz crystal) #pragma config CPUDIV = OSC1_PLL2 #pragma config USBDIV = 2 // Clock source from 96MHz PLL/2 #pragma config FOSC = HSPLL_HS #pragma config FCMEN = OFF #pragma config IESO = OFF #pragma config PWRT = OFF #pragma config BOR = ON #pragma config BORV = 3 #pragma config VREGEN = ON //USB Voltage Regulator #pragma config WDT = OFF #pragma config WDTPS = 32768 #pragma config MCLRE = ON #pragma config LPT1OSC = OFF #pragma config PBADEN = OFF //#pragma config CCP2MX = ON #pragma config STVREN = ON #pragma config LVP = OFF //#pragma config ICPRT = OFF // Dedicated In-Circuit Debug/Programming #pragma config XINST = OFF // Extended Instruction Set #pragma config CP0 = OFF #pragma config CP1 = OFF //#pragma config CP2 = OFF //#pragma config CP3 = OFF #pragma config CPB = OFF //#pragma config CPD = OFF #pragma config WRT0 = OFF #pragma config WRT1 = OFF //#pragma config WRT2 = OFF //#pragma config WRT3 = OFF #pragma config WRTB = OFF // Boot Block Write Protection #pragma config WRTC = OFF //#pragma config WRTD = OFF #pragma config EBTR0 = OFF #pragma config EBTR1 = OFF //#pragma config EBTR2 = OFF //#pragma config EBTR3 = OFF #pragma config EBTRB = OFF Then, I actually reconfigure the bluetooth modules to both (PC sided one and pic sided one ) to work with 115200 baud 1 stop 1 parity and i manage to communicate with both with the pc to configure them but I didnt try to configurate the pic sided one with the pic. Then i tried, as you told me, to send your well-known ascii characters and there is what i get in the UART output of the pic (what its should be send to the bt module): ASCII: HEXA: Binary : I hope I gave all you need in order to solve my issue because I cant see where it can come from .. |
|
|
|
我犯了一个错误,它的0奇偶校验不是1,但我不能改变我的职位…
以上来自于百度翻译 以下为原文 I made a mistake, Its 0 parity not 1 but I cant change my post ... |
|
|
|
它看起来不像一个奇偶错误,更像波特率,甚至是一个“反转信号”问题……即使我不能匹配54 49 FCTO34 32 0D 0A…
以上来自于百度翻译 以下为原文 It does not look like a parity error, more a Baud rate or even an "inverted signals" issue... Even if I can't match properly 54 49 fc to 34 32 0d 0a ... |
|
|
|
我说的是我在前一篇文章中所写的,我知道它看起来像波特率错误,但我为SPBRG做了一千次计算,而且总是那些字符。
以上来自于百度翻译 以下为原文 I was speaking about what I wrote in my previous post I know it look like a baud rate error but I made calculs a thousand time for the spbrg and its always those char |
|
|
|
我也会假设波特率问题。你有适当的GND连接为你的USB到RS232转换器与HC05?你留下了一些问题:你的照片?(你假设波特率的计算是什么?)你是否测试(在PIC侧,而不是在空中)是否可以与HC05通信?如果你有一个有线原型板,你可以先尝试从PIC到PC,而不用无线电(HC05)分离HC05,并用你的USB到RS232转换器(照顾转换器的电压,我不知道你在用什么)。如果它是一个PCB,你不能把HC05从PIC中分离出来,你仍然可以抓取PIC TX PIN并将它“线”到USB到RS232转换器。你的源代码中的注释表示9600波特,假设什么是正确的,代码或评论?你为什么不先用9600波特测试呢?对波特率误差不太敏感。
以上来自于百度翻译 以下为原文 I also would assume a baud rate problem. Do you have proper GND connection for your USB to RS232 converter with the HC05 ? You left some questions open: - your PIC ? (and what is your assumed Fcy for baud rate calculation) - did you test (on the PIC side, not over the air) whether you can communicate with the HC05 ? If you have a wired prototyping board, you could first try to communicate from PIC to PC without radio (HC05) Detach HC05 and use your USB to RS232 converter (take care of the voltages of the converter, I don't know what you are using). If it is a PCB where you cannot detach the HC05 from the PIC, you still can grab the PIC TX pin and 'wire' it to the USB to RS232 converter. The comment in your source code said 9600 baud, what is assumed to be correct, code or comment ? Why didn't you first test with 9600 baud, or did you ? Should be less sensible to baud rate errors. |
|
|
|
我的PIC是一个PIC18F2553,在SpkFun的USB比特窃听卡(HTTPS://www. SPARKFUN.COM/Studis/762)中,我假设波特率为114832波特,SPBRG为13(而不是115200)。“用开关切断”通讯线。(也许我应该做其他的事情,只要告诉我如果另一个操作会更能回答你),我就把HC05分离到最后一系列屏幕I上。我已经用9600测试过了,结果和现在差不多。
以上来自于百度翻译 以下为原文 My pic is a PIC18F2553 in the USB BIT WHACKER CARD from sparkfun (https://www.sparkfun.com/products/762) and the baud rate i assume have is 114832 baud with spbrg at 13 (instead of 115200). I assume the fact that i can communicate with the HC05 as long as it send when i send somthing and stop when I "cut" communication wire with switches.( maybe i should do anything else, just tell me if another manipulation will more answer you) and I do detach the hc05 for the last series of screen I tooked . I do have tested with 9600 and the result is almost the same than now . |
|
|
|
可以肯定的是:这个(54 49 FC)已经是直接从PIC TX引脚获得的结果了吗?你的“假设”FCy是什么?
以上来自于百度翻译 以下为原文 Just to be sure: this (54 49 fc) already is the result taken directly from the PIC TX pin ? What is your "assumed" FCy ? |
|
|
|
可以肯定的是:这个(54 49 FC)已经是直接从PIC TX引脚获得的结果了吗?你的“假设”FCy是什么?是的。有一个24兆赫的石英连接到PIC,如果它是你所要求的。
以上来自于百度翻译 以下为原文 Just to be sure: this (54 49 fc) already is the result taken directly from the PIC TX pin ? What is your "assumed" FCy ? Yes It is . There is a quartz of 24 Mhz connected to the pic, if its what you are asking |
|
|
|
对不起,当时我误解了什么。我假设:34 32 0D 0A从PIC 1进入BATT,另一端接收54个49 FC……或者是我错了吗?
以上来自于百度翻译 以下为原文 I am sorry, I misunderstood something then. I assumed:
|
|
|
|
不,它是:1。我想发送4 2 0A 0D2.54 49 FC走出PIC3。输入BT4。在另一个我收到什么模块发送(54 49 FC)
以上来自于百度翻译 以下为原文 no Its : 1. I want to to send 4 2 0a 0d 2.54 49 FC goes out the pic 3. enter BT 4. at the other I received what module Send (54 49 FC) |
|
|
|
嗯,从一开始你就应该更加冗长了……看起来BT-05“桥”现在不是你的问题。我认为你现在直接用你的USB RS232转换器直接查看TX管脚。你的PIC配置是错误的,或者你的实时配置。是错误的。请显示RealTalm的端口设置。您使用哪一个USB RS232转换器?
以上来自于百度翻译 以下为原文 Hm, you really should be more verbose from the beginning ... It looks as if the BT-05 "bridge" is currently not your problem. I take it granted that you are now directly looking at the TX pin with your USB RS232 converter and RealTerm. Either your PIC configuration is wrong, or your RealTerm configuration is wrong. Please show the port settings of RealTerm. Which USB RS232 converter do you use ? |
|
|
|
是的,正如Rodims所说的。我试着发送0x55并检查一个范围。
以上来自于百度翻译 以下为原文 Yep, as Rodims says. I'd try sending 0x55 and check with a Scope... |
|
|
|
|
|
|
|
|
|
|
|
我怀疑这13是你的BRG公式结果,如果你在公式中使用FoSC=24兆赫。我认为这是错误的,因为你在使用PLL,我猜FoSC的设置是32或16兆赫,但是我找不到合适的数据表。你应该检查一下,或者其他人知道你的PIC18能更好地验证FOsc。
以上来自于百度翻译 以下为原文 I suspect this 13 is the your BRG formula result, if you use FOsc = 24 MHz in the formula. I think that's wrong, since you are using PLL, and I guess the FOsc is either 32 or 16 MHz with your settings, but I do not find the proper datasheet. You should check that, or may be someone else knowing your PIC18 better can verify FOsc . /** CONFIGURATION Bits **********************************************/ #pragma config PLLDIV = 6 // (24 MHz crystal) #pragma config CPUDIV = OSC1_PLL2 #pragma config USBDIV = 2 // Clock source from 96MHz PLL/2 #pragma config FOSC = HSPLL_HS |
|
|
|
只有小组成员才能发言,加入小组>>
4779 浏览 9 评论
1815 浏览 8 评论
1734 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
2941 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2043 浏览 5 评论
423浏览 1评论
1101浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
345浏览 0评论
253浏览 0评论
LAN9252使用SQI通信,进行数字复位后读BYTE_TEST异常
1751浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-3-29 18:45 , Processed in 1.130771 second(s), Total 95, Slave 78 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 深圳华秋电子有限公司
电子发烧友 (电路图) 粤公网安备 44030402000349 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号