Bluetooth transmit and recieve?
Hi guys, I am making progress on my little project, as I got my LED blinking with help from here, and then got my LCD and temp sensor working. :) But I have gotten myself stuck again, and hopefully someone can point out my error. I have a PIC16F628A driving a Bluetooth breakout board and am trying to get it to transmit to my laptop and view it via RealTerm. Everything looks ok to me, but RealTerm shows nothing. Not sure why. The device is linked, but not connected (ie in Windows I can see the bluetooth transmitter and pair it).
My code is
Code:
'****************************************************************
@ __config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF & _LVP_OFF & _CP_OFF
DEFINE OSC 4
DEFINE LOADER_USED 1
DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 20h
DEFINE HSER_SPBRG 25 ' 2400 Bauds
DEFINE HSER_CLOERR 1
TRISB.2 = 0 ' Set RB2 to output
'RCSTA = 010000 ' Enable serial port and continuous receive
'TXSTA = 100000 ' Enable transmit and asynchronous mode
char Var byte ' Storage for serial character
start:
Hserout ["Hello World", 13, 10] ' Send text followed by carriage return and linefeed
mainloop:
Hserin 10000, start, [char] ' Get a char from serial port
Hserout [char] ' Send char out serial port
Goto mainloop ' Do it all over again
End
and on the RealTerm I get CTS and DSR as green lights (both show the status of the main port), I set the baud rate to 2400 and nothing displays. Also tried 9600. I have tried lots of settings on RealTerm convinced that is the issue, but now am second guessing myself. Circuit itself is pretty simple, I am hooked up to RB1&2 for TX and RX, and the breakout board with the bluetooth has those nicely labeled. I should mention, that when via RealTerm I transmit, the blue light on the breakout board dims for 3-4s, telling me it is doing something. Just not sure what. And for completeness, the blue light blinks initially until I launch RealTerm and then is just constantly on, so I have a connection.
Any suggestions on how I can debug further?
UPDATE: I was checking out the breakout board with the bluetooth, and now suspect that.
http://www.mdfly.com/index.php?main_...roducts_id=769
I cannot get it to return an AT command via their own terminal program, so I think I found my culprit. I will still post this in case someone has some advice, or maybe this will help others.
Thanks!
Patrick
Re: Bluetooth transmit and recieve?
From the docs..
Quote:
Note: The module will not accept an AT command when it is paired. A USB-TTL or
RS232-TTL converter module is required if you want to change the setting on your computer.
Do you have a MAX232 or similar?
Re: Bluetooth transmit and recieve?
Grrr... Nope! :) No Max232. I can get one, but now my question is, do I need one? I really do not care to set the password and device name. Just want to transmit "Hello world". It is late here (about 1am), so pardon my question, as I did read the data sheet, but none of my examples of circuits had one of these (that I recall)? I will look at this all again tomorrow with a fresh mind.
Thanks!
Patrick
Quote:
Originally Posted by
mackrackit
From the docs..
Do you have a MAX232 or similar?
Re: Bluetooth transmit and recieve?
Not sure if one is needed but I will guess yes... but, you could try SEROUT2 using an inverted mode for testing.
Re: Bluetooth transmit and recieve?
check the BlueTooth properties in windows, needs SPP driver stuff there.... 'serial port profile', then see what ports are added/removed as BT turned on/off and the module is paired....... set terminal to try added ports
don
Re: Bluetooth transmit and recieve?
Hi Patrick
First I would Google "HC-05 bluetooth datasheet", should be the first result, I found it very usefull.
These modules are usually set to 9600 baud, and I think you will need a faster xtal than 4mHz (8mHz gives quite accurate baud rate, works for me).
I have a project with a bluetooth master module and slave module similar to yours and the blue LED does not dim when Tx-ing or Rx-ing, I think something is wrong.
Phil
Re: Bluetooth transmit and recieve?
Re:- Blue LED dims - check your breakout board connections
Breakout board Tx pin goes to PIC Rx pin
Breakout board Rx pin goes to PIC Tx pin
If you have connected Tx to Tx and Rx to Rx it would explain why the blue LED dims
Phil
Re: Bluetooth transmit and recieve?
Phil,
You are a genius! I have no idea how you figured out my mistake. But yes, I connected the Tx to Tx and Rx to Rx. Seemed totally logical to me, and sadly still sort of does. Now that I flipped them as you suggested, it works and "Hello World" repeats over and over on the laptop. Sweet!!! I will play around with a faster xtal later and report back, and I am still looking into the Max232 as per Dave's suggestion.
More reading to do, but first have to clean the house up for New Years, although I would rather play with this.
Thanks again!
Patrick
Quote:
Originally Posted by
Sherbrook
Re:- Blue LED dims - check your breakout board connections
Breakout board Tx pin goes to PIC Rx pin
Breakout board Rx pin goes to PIC Tx pin
If you have connected Tx to Tx and Rx to Rx it would explain why the blue LED dims
Phil
Re: Bluetooth transmit and recieve?
The MAX232 is not needed now, I thougt it may have been the signal that needed inverted, not the wires. :)
Re: Bluetooth transmit and recieve?
Quote:
Originally Posted by
patrickg
I have no idea how you figured out my mistake.
Hi, that's a very common mistake. Many of us have done that before :). I want to give it a try to this module and your code. Although, my ultimate goal is to communicate with my Android smartphone using Basic for Android.
Robert
Re: Bluetooth transmit and recieve?
Hi Patrick
Glad I've got you going.
As regards to the MAX232, you will only need this if you are connecting your PIC to a computer RS232 port or a USB to RS232 serial converter. A much easier solution is to get a USB to UART TTL converter. You can connect these direct to the PIC - Tx pin to Rx pin - the one device transmits the signal out, the other receives the signal in. I can recommend the one sold on ebay by "eachdesk" made by "BAITE". Type in item 110760144325 should find it.
They make a very good bootloader that works with the MicroCode Studio Bootloader. If you cut the track from the RST pin so it no longer connects to the CP2102 chip and instead connect the RST pin to the DTR connection (J3 pin 1), it will also do an automatic reset. This is easy as the track passes close to the DTR connection.
At £1.78 each with free shipping they are cheap enough to build into your projects.
Phil