I can not interface hc-05 Bluetooth module with pic 18f2550. I require help. Please write me a sample code and corresponding circuit connection. Here is the picture of the module that i use. I am using tera term software to see the values coming from com port.

Last edited by srikrishna on Wed Oct 11, 2017 3:57 am; edited 1 time in total

Ttelmah

Joined: 11 Mar 2010Posts: 14603

Posted: Wed Oct 11, 2017 2:21 am

You won't.....

Problem is the HC-05, is a 3.3v module. Though it can be powered off 5v, it only gives a 3.3v output.
To connect it to the 2550, you need level conversion hardware.

The TX line out of the PIC needs a voltage divider (simple resistive divider say 1K8 to the PIC TX line, then a 3K3 to ground, and feed the junction to the RXD pin on the HC05) - otherwise you risk damaging the HC05 with the overvoltage on this line.
The TXD line needs a level shifter. Something like a 74ACT125D, or a similar chip that accepts a TTL level 'in' and gives a near 5v 'out'.

Problem here is the PIC RXD needs the signal to go up to 4v to be seen as a logic '1'. The 3.3v HC05 can't do this.

srikrishna

Joined: 06 Sep 2017Posts: 74

Posted: Wed Oct 11, 2017 3:58 am

The model i have using has TTL outputs. Here is the specifications:

temtronic

Joined: 01 Jul 2010Posts: 6805Location: Greensville,Ontario

Posted: Wed Oct 11, 2017 4:49 am

As Mt T points out the device in your picture is a 3 volt unit and nothing in the specs you post say what the MCU interface logic levels are. There's no power supply data to read.

As a general rule, all peripheral devices (gps,mem,rtc,etc) these days ARE 3 volt devices.Very few are 5 volt. Some, mounted on PCBs, aka 'modules' _may_ have logic level shifters on board.

There are two way to solve this 5V PIC vs 3V device problem.

#1. Use a 3 volt PIC. Most PIC families have an 'L' version,which is 3 volt rated. Some PICs, like th 18F46K22 WILL run at 3 or 5 volts. Using a PIC designed to run at 3 volts means NO logic level conversion necessary, simpler PCB design, faster R&D time !

#2. Design and install proper logic level conversion. This can consist of transistors, ICs or even 'modules'. Downfall is cost, space and potential mis-wiring.

As a BTW, I've found the HC-12 version to be a better device. Easier to use, similar price. Beware though all these devices require a LOT of power for xmt...it's in the specs...so be sure your PSU is good for it !

Jay

Ttelmah

Joined: 11 Mar 2010Posts: 14603

Posted: Wed Oct 11, 2017 6:52 am

srikrishna wrote:

The model i have using has TTL outputs. Here is the specifications:

The outputs will drive conventional TTL. Problem is the inputs of the PIC (for serial), are Schottky, not conventional TTL. This is why you can use a TTL input gate as a buffer to the PIC.

Jay has given a lot more info.

guy

Joined: 21 Oct 2005Posts: 280

Posted: Thu Oct 12, 2017 2:24 am

namaskar srikrishna.
With low baud rates (slow communication, less than 115,200) you can also build a level converter with a transistor:
https://cdn.sparkfun.com/assets/f/3/3/4/4/526842ae757b7f1b128b456f.png
you can also replace the transistor with a fast NPN trans. such as 2N3904.
Let me know if you need a more detailed schematic & explanation or you're good with this.
Also I suggest you read all of the manual - there are a few things to look out for with the HC-05. https://www.itead.cc/wiki/Serial_Port_Bluetooth_Module_(Master/Slave)_:_HC-05
See Ttelmah's answer on how to divide the voltage of the PIC TX line from 5V to 3.3V .

As for code, check the compiler's example on #USE RS232, output a string to the HC-05 every second and see if you receive it on the computer.

srikrishna

Joined: 06 Sep 2017Posts: 74

Posted: Wed Nov 15, 2017 2:07 am

Ttelmah wrote:

You won't.....
.

But Ttelmah some of my friends also interfaced bluetooth with pic. They interfaced Hc-05 as well as Hc-06 module. Here is the code. Although they used mplab xc8 compiler for coding.

And used hyperterminal to see the result. But my question is, is this possible in ccs c??

Ttelmah

Joined: 11 Mar 2010Posts: 14603

Posted: Wed Nov 15, 2017 2:37 am

Seriously, they have either just been very lucky, or they have modules that have 3.3v to 5v conversion built in.

We are not talking something software changes, but _hardware_ differences. I've used these modules. To get reliable connection with the PIC (using assembler, Microchip C, or CCS C), there _has_ to be circuitry to raise the output voltage to match the PIC's input requirement, _or_ the PIC can be run at a lower voltage to give the same effect (for some PIC's).

The 452, they could be running at 40MHz down to 4.2v. At 4.2v, the module would (just) work.

temtronic

Joined: 01 Jul 2010Posts: 6805Location: Greensville,Ontario

Posted: Wed Nov 15, 2017 6:07 am

As Mr. T points out, you need to change the Hardware not the software (code).
You've got a 2550 , your friend has a 452. Yes, they are PICs but NOT of the same family, so it is very possible the actual PIC, the 'die' is physically different and the 452 just happens to work, actually 'out of spec'. While it might work 'on the bench' change the temperature and it'll probably stop working. In order to get reliable operation you must supply VDD within the spec at the operating frequency. Typically, charts show the lower the VDD, the slower the PIC can operate. One of them 'physics' details we never learned at school..
Also be sure to have a high current power supply ! Wireless modules tend to need 1 amp (or more) during transmit. While a short duration of time, drawing that much current can drop VDD below the PICs proper operating requirement and it will not function correctly.

Bottom line.. NO amount of code will fix incorrect hardware.

Jay

srikrishna

Joined: 06 Sep 2017Posts: 74

Posted: Tue Dec 05, 2017 5:17 pm

Ttelmah wrote:

I've used these modules. To get reliable connection with the PIC (using assembler, Microchip C, or CCS C), there _has_ to be circuitry to raise the output voltage to match the PIC's input requirement

That PIC is NOT rated for 3 volt operation. As such will NOT directly interface( connect) to the HC-05 module.
You have options
1) add logic level conversion between the 5 V PIC and the 3V HC-05

2) use the PIC18LF2550, the 3 V rated PIC of that family.

I'd choose #2 as it's fewer parts and less chance for a wiring or connection error. Also be sure to use a power supply rated for at least 2 Amps. All wireless devices require a LOT of power during transmit mode.

Jay

Ttelmah

Joined: 11 Mar 2010Posts: 14603

Posted: Tue Dec 05, 2017 11:57 pm

I've used a 74125 for the conversion from 3v to 5v.

For a little board:
<https://www.sparkfun.com/products/12009>

This is the most basic FET circuit, that works well:
<http://www.hobbytronics.co.uk/mosfet-voltage-level-converter>

Some of the breakout boards supplied with HC05 modules have this circuit built onto the board which is why the friends of the original poster may have been OK, but the standard modules don't, since it is not needed to drive the inputs of chips like the Arduino.

srikrishna

Joined: 06 Sep 2017Posts: 74

Posted: Thu Dec 21, 2017 2:59 am

Ttelmah wrote:

This is the most basic FET circuit, that works well:
<http://www.hobbytronics.co.uk/mosfet-voltage-level-converter>