HC05 HELP

An area to discuss 8-bit PIC specific problems and examples

Moderator: Benj

siliconchip
Posts: 392
Joined: Wed Jan 05, 2011 11:24 am
Has thanked: 101 times
Been thanked: 24 times
Contact:

Re: HC05 HELP

Post by siliconchip »

Hi chipfryer

right been messing with this for ages and found that the connection was wrong if i connected my usb to serial adapter to the HC05 i found i could send text via the laptop to my phone and vice versa with the baud set at 38400, i then tried the same thing with the baud set to 9600 through the cool term terminal program on my laptop but got garbage come up, i then changed the UART baud from 9600 on the chip to 38400 and reprogrammed and now with typing upper case LED i can now make the led go on and off as intended so although it works im now thrown by the 38400 baud rate which i thought you only used while in AT command mode ??

bob

chipfryer27
Valued Contributor
Valued Contributor
Posts: 617
Joined: Fri Jun 06, 2014 3:53 pm
Has thanked: 184 times
Been thanked: 195 times
Contact:

Re: HC05 HELP

Post by chipfryer27 »

Hi

Great to hear that you can now interact. Now you can delve deeper.

With my modules, and from what I see on the Web, most modules run in Command Mode at 38400, transmission at 9600, but clearly you have the exception.. :) Good to know for future reference. Guess your vendor did things differently, which isn't that unusual.

You can reconfigure the module to run at any speed, but as you can now interact you might not want to. If you want to reconfigure baud I can give you the appropriate AT command but not till later in the week as I am travelling just now.

Switching on/off by toggling via the CB is just an example and the CB is a great component which allows multiple options to be found, including variables, by parsing.

Let me know how you get on.

Regards

chipfryer27
Valued Contributor
Valued Contributor
Posts: 617
Joined: Fri Jun 06, 2014 3:53 pm
Has thanked: 184 times
Been thanked: 195 times
Contact:

Re: HC05 HELP

Post by chipfryer27 »

Hi

In the attached I send three PWM values over the HC05 link to control the brightness of three LEDs.

The 1825 has four PWM channels but as channel 1 uses the same pin as the Rx I used channels 2, 3 and 4.

I connected LEDs to the pins and set the PWM for a frequency of approx 60Hz which equates to a Period of 32. This is the maximum value for the Duty Cycle so a DC of 16 would be a 50/50 wave.

The PWMs are referenced by name (PWM1 / PWM2 / PWM3) and to control the brightness of the LEDs we alter the Duty Cycle of the respective PWM.

We will send the name, duty cycle value and a End of Transmission character. I have used the exclamation mark "!" as EOT (decimal 31) but it can be anything you wish. Decimal 4 is the actual ASCII EOT but as it may not be displayed I used the exclamation mark to illustrate the principle.

As before, when we receive a character over the link we store it in the circular buffer. The main loop just loops around looking for the EOT and if it finds it, it then parses the buffer to establish which PWM we are addressing and the value. If at any time we get unexpected data we start the search all over again. This helps to ensure only valid data is actioned.

As the RxINT doesn't simulate I added a Macro Call (CB) after enabling the Rx interrupt. In the Macro (CB) we populate the CB with data including some carriage returns . If you view 2D Panel and Console and step through the chart you should be able to follow the simulation.

Hope this helps.

Regards
Attachments
HC05_Test_1825_PWM.fcfx
(32.32 KiB) Downloaded 77 times

siliconchip
Posts: 392
Joined: Wed Jan 05, 2011 11:24 am
Has thanked: 101 times
Been thanked: 24 times
Contact:

Re: HC05 HELP

Post by siliconchip »

hi chipfryer

big thanks for doing this i will try to break it down to understand how it works

cheers bob

chipfryer27
Valued Contributor
Valued Contributor
Posts: 617
Joined: Fri Jun 06, 2014 3:53 pm
Has thanked: 184 times
Been thanked: 195 times
Contact:

Re: HC05 HELP

Post by chipfryer27 »

Hi

Your welcome.

As mentioned, if you step through with the console open you should see the CB populate (in reality we would only get one message with EOT in the buffer due to immediately processing once it appears).

Once we enter the Main loop it then looks for our EOT and if found parses the buffer looking for our message and depending on such, actions.

You could alter the contents of the CB Macro to experiment and "see" what happens.

If you have any questions just shout.

Regards

Post Reply