PDA

View Full Version : Help with bluetooth...



mbox
- 3rd October 2009, 00:07
Hi everyone, I got an EGBC-04 bluetooth module. When I powered the EGBC-04 my pc detects it(Bluetooth discovery). But I'm having problem communicating with it(sending data only). I place leds to test the communication setup from PC to EGBC04 to PIC16F877A but no luck. Kindly check my setup and codes in the pic....I appreciate any help.


CLEAR ;read and write hardware USART
B1 VAR BYTE ;initialize USART

TRISB = %00000000
PortB = %00000000
TRISC = %10111111 ;set TX (PORTC.6) to out, rest in
SPBRG = 25 ;set baud rate to 2400
RCSTA = %10010000 ;enable serial port and continuous receive

LOOP:
GOSUB CHARIN ;get a character from serial input, if any
IF B1 = 0 THEN LOOP ;no character yet
GOTO LOOP ;do it forever
;subroutine to get a character
;from usart receiver
CHARIN:
B1 = 0 ;preset to no character received
IF PIR1.5 = 1 THEN ;if receive flag then...
B1 = RCREG ;get received character to b1

IF B1 = 65 then
If PortB.0 = 0 then
High PortB.0
else
Low PortB.0
Endif
ENdif

ENdif
goto loop

Thanks in advance,
mbox

mackrackit
- 3rd October 2009, 18:02
I have not used an EGBC-04, but looking at the data sheet I will ask...

Did you set the EGBC-04 for the baud rate you are using? I think it defaults to 9600.
Did you set it as SLAVE? I think that is what you want.

And, I would also think an inverter chip (RS232) is needed.

mbox
- 4th October 2009, 14:42
Hi Dave, I did adjust it to 9600 and do I really need the inverter chip? As I understand I only need it if I directly connect the BT module to the PC. But instead I have a USB bluetooth attached to PC to link with th EGBC-04. Please help..

thanks,
mbox

mackrackit
- 4th October 2009, 16:27
Hi Dave, I did adjust it to 9600 and do I really need the inverter chip? As I understand I only need it if I directly connect the BT module to the PC. But instead I have a USB bluetooth attached to PC to link with th EGBC-04. Please help..

thanks,
mbox
I do not know for sure but to have a PIC communicate with a PC and using hardware serial the inverter chip is needed.

I would think that any data passing through the BT module is inverted. As a quick test you could try SERIN2/SEROUT2 and use inverted mode.

And you have your serial on the PIC set as 2400 baud. The BT is 9600???

mbox
- 5th October 2009, 03:17
Hi Dave, thanks for the replies and I really do appreciate it. Ahm...I'm a little confuse, I hope you dont mind if I'm very slow to pick it all up. But may I explaine my hardware setup to understand what I'm missing.

PC side: [Port - COM7] [Baud rate - 9600] [Byte size - 8] [Stop bit - 1]
Sends character data 'A' over COM7 as given(device discovery).

EBC-04 side: [Operates on 3.3v] [Baud rate - 9600] [Byte size - 8] [Stop bit - 1]

PIC side: [Baud rate - 2400] PortC.7-->Rx

Okay, I understand that I need to change 2400 to 9600 from PIC baud rate to communicate with EGBC. There are two option as I see, either I change the baud rate of the EGBC using AT commands by connecting to the pc with LVTTL TO RS-232 CONVERTER or change PIC's baudrate. But I dont have TTL to RS232 converter right now. So changing the Pic's baud rate is my option. I'm using 4MHZ crystal..how do I change it to 9600?

Thanks,
mbox

mackrackit
- 5th October 2009, 09:42
The easy way to figure the USART settings is to use Mister E's PicMultiCalc
http://www.picbasic.co.uk/forum/showthread.php?t=4994

It gives


RCSTA = $90 ' Enable serial port & continuous receive
TXSTA = $24 ' Enable transmit, BRGH = 1
SPBRG = 25 ' 9600 Baud @ 4MHz, 0.16%

But even changing the baud I still think you will need an inverter.

mbox
- 5th October 2009, 12:11
Okay I will be purchasing my inverter module this week..I will post my updates. I can't wait this to be solve and the same time learn in the process.:(
The inverter should be between the Bluetooth and the Pic ?

Thanks again Dave,
mbox

dhouston
- 5th October 2009, 12:21
But even changing the baud I still think you will need an inverter.The manual shows two BT module to µC examples and one BT module to PC serial port example. Only the latter uses an inverter (i.e. their RS232 module).

The PIC UART will likely have a Schmidt Trigger input - 3.3V is too low to be seen as logic high - 0.8Vdd is required. With SerIn or SerIn2 and TTL inputs, logic high is 2V.

FIG 14 & FIG 15 of this app note http://www.zbasic.net/appNotes/AN213.pdf shows how to interface to the Schmidt Trigger input.

mbox
- 6th October 2009, 04:24
Hi dhouston, I'm a beginner in electronics and seasonal pbp programmer. I hope I got this one, so in order to communicate properly I must use a Logic Translation Level between EGBC-0 and pic like the one below..:o
BTW thanks for the link...I will experiment with it and post my updates.

dhouston
- 6th October 2009, 05:13
@mbox

The simplest solution would be to use SerIn or SerIn2 on a pin that has a TTL buffer. Read the I/O Ports section of the datasheet for the 16F877a as well as the Electrical Characteristics section. Ports A & B have TTL buffers on the pins and only need 2.0V for logic high.

If you must use the hardware UART, I suggest using the circuit in FIG 15 of the app note. If you use FIG 14, the diode forward voltage drop may be marginal for the logic low input voltage (1.0V) unless you use a germanium diode. Read the explanation in the app note.

EDIT: Also, if you use the diode, use the attached circuit.

mbox
- 6th October 2009, 08:32
Hi to all, I change the codes and Port pin setup, at this time I used the SERIN and SEROUT...


include "modedefs.bas"
B2 var byte
pause 500

start:

serin 0,T9600,B2 ''''''''''''''''''''''''''' PortB.0 as my recieve pin from bluetooth Tx
Serout PORTC.6, T9600, [#B2,10,13] '''''''''''''''''''''''PortC.6 as Transmit pin to pc com1

IF B2 = 65 then
If PortB.1 = 0 then
High PortB.1
else
Low PortB.1
Endif
else

ENdif
goto start

I noticed that it is generating random numbers pls see the attach...anybody knows what's the reason?

Thanks in advance
mbox

mackrackit
- 6th October 2009, 13:00
Are you sending somthing from the PC and the random numbers are the echo?

dhouston
- 6th October 2009, 14:39
SerOut to the PC serial port needs to be inverted - use N9600.

mbox
- 7th October 2009, 02:26
Hi everyone,


mackrackit: Are you sending somthing from the PC and the random numbers are the echo?
It suppose to lit a LED on PortB.1 when "A" is pressed. Connecting the EGBC TX--> PIC Rx causes the random generation number.


dhouston: SerOut to the PC serial port needs to be inverted - use N9600.
I tried that but it gives character sysmbols..pls see the attachment.

dhouston
- 7th October 2009, 05:38
I tried that but it gives character sysmbols..pls see the attachment.I'm confused. Your code example comment says "PortC.6 as Transmit pin to pc com1" but your latest schematic appears to indicate another wireless connection to the PC.

A wired RS232 connection needs N9600 for SerOut while a wireless connection may use T9600. A wireless connection may also be noisy, leading to the random data of your first example.

mbox
- 7th October 2009, 09:06
Hi, sorry if it is confusing. I forgot to tell you that I'm using my mobile to send data to the bluetooth module and hopefully have it echoed to the Pc. My code for my phone is tested, it can send letter 'A' from phone to Pc thru bluetooth communication. And hoping it will the same way to pic with a bluetooth module. So this noise is normal? How can I prevent it from generating. I tried to observe while sending from my phone to pic if 65 is recieved, unfortunately it is not.

IF B2 = 65 then ' waits for "A"
If PortB.1 = 0 then
High PortB.1
else
Low PortB.1
Endif

else

Endif

dhouston
- 7th October 2009, 13:04
It may just be that your schematic is what confused me. I'm not familiar with Bluetooth serial adapters but would expect them to handle the noise suppression automatically.

Try this:
start: SerIn PortB.0,T9600,["A"] 'wait for "A" on PortB.0
If PortB.1 = 0 Then
SerOut PORTC.6,N9600,["HIGH",13,10]
High PortB.1
Else
Serout PORTC.6,N9600,["LOW",13,10]
Low PortB.1
Endif
GoTo start

mbox
- 7th October 2009, 13:51
I tried using the code but I got character symbols coming out.
I tried to make them all T9600 and I got High and Low display...and I'm not even sending any data yet to the module..

dhouston
- 7th October 2009, 15:47
Try
SerIn PortB.0,T9600,["ABC"]

mbox
- 8th October 2009, 00:03
Hi there,

SerIn PortB.0,T9600,["ABC"]
No random generation, I then try to send "ABC" but nothing happen.
I think somethings wrong with my bluetoooth and pic setup.
I checked the supply its getting only 2.9 instead of 3.3v. I'm going to get IC regulator 3.3v and try to redo the setup...and let you know what happen.

dhouston
- 8th October 2009, 01:44
It would be helpful to know whether the output from the BT module is noisy. If you do not have an oscilloscope, you can record it as a .WAV file using the LineIn of your soundcard.

mbox
- 8th October 2009, 02:30
Okay..I will do that sometime later today... I'm getting frustrated...do you know of any bluetooth module that you tried and tested in pic with pbp?:(

dhouston
- 8th October 2009, 03:15
No, I haven't used Bluetooth.

mackrackit
- 8th October 2009, 04:30
Can you try bypassing the PIC and connect the TX from the Bluetooth module directly to the PC com port?

mbox
- 8th October 2009, 07:16
Hi,

mackrackit: Can you try bypassing the PIC and connect the TX from the Bluetooth module directly to the PC com port?
I can not do that right now. I dont have any Max232 chip.