View previous topic :: View next topic |
Author |
Message |
bestbuylvr
Joined: 31 Jan 2007 Posts: 27 Location: Pittsburgh, PA
|
Using Bluetooth adapters for serial connection |
Posted: Wed Jan 31, 2007 9:04 am |
|
|
I am using this device with a simple calculator program, ie. EX 10, to test a serial connection using a serial Bluetooth adapter at the end of the serial cable coming from the PIC. I have a USB bluetooth adapter hooked to the computer and have a virtual Bluetooth serial port set up. When I power up the unit while watching the serial port monitor, the "Enter the first Number" displays, suggesting data is being recieved from the device. When I try to type in a number to send back, it does not acknowledge it. If you have any suggestions, please post them. Thank you. |
|
|
Jimmy5000 Guest
|
Details |
Posted: Wed Jan 31, 2007 10:52 am |
|
|
We need more details then that. Show your code. How are you receiving the data on the computer?
Jimmy |
|
|
bestbuylvr
Joined: 31 Jan 2007 Posts: 27 Location: Pittsburgh, PA
|
|
Posted: Thu Feb 01, 2007 8:16 am |
|
|
The code I used is as follows:
#include <protoalone.h>
#include <utility.c>
#include <stdlib.h>
#include <input.c>
main () {
long a,b,result;
char opr;
setup_timer_0 (RTCC_INTERNAL);
while (TRUE) {
printf("\r\nEnter the first number: ");
a=get_long();
do {
printf("\r\nEnter the operator (+-*/): ");
opr=getc();
} while (!isamong(opr, "+-*/"));
printf("\r\nEnter the second number: ");
b=get_long();
switch (opr) {
case '+' : result=a+b; break;
case '-' : result=a-b; break;
case '*' : result=a*b; break;
case '/' : result=a/b; break;
}
printf("\r\nThe result is %lu ", result);
}
}
I am using the Bluetooth adapters to communicate with the computer as opposed to directly connecting the serial output to the computer. Simply put, I am using the device to test the ability to send and recieve data over this bluetooth connction. I am using a Socket Serial Bluetooth adapter at the card's (PIC 18F452) output and a Linksys BLuetooth adapter at the computer. I am using the CCS C Compiler program's Serial Port monitor to view the output and try to send the responses back to the card. When I run the program, the screen displays, "Enter the first number: ." When I try to enter the number, absolutely nothing happens, which leads me to believe that the data is not being sent over the bluetooth connection, because the program runs flawlessly when I physically connect it to the serial port on the computer. I have the adapters set to the program serial settings (COM6 8N1 9600). COM 5 is the virtual serial port created by the linksys bluetooth software. I cannot figure out why the data is recieved by the computer and not sent back to the PIC. If you need any more info, please let me know. |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1909
|
|
Posted: Thu Feb 01, 2007 10:36 am |
|
|
bestbuylvr wrote: | When I try to enter the number, absolutely nothing happens, which leads me to believe that the data is not being sent over the bluetooth connection, because the program runs flawlessly when I physically connect it to the serial port on the computer. I have the adapters set to the program serial settings (COM6 8N1 9600). COM 5 is the virtual serial port created by the linksys bluetooth software. I cannot figure out why the data is recieved by the computer and not sent back to the PIC. If you need any more info, please let me know. |
I'm wondering about COM5. The CCS serial port monitor program can only connect to COM1 or COM2. At least the version that I'm using. Can you confirm that the CCS program can connect to COM5? |
|
|
bestbuylvr
Joined: 31 Jan 2007 Posts: 27 Location: Pittsburgh, PA
|
COM 5 |
Posted: Thu Feb 01, 2007 12:28 pm |
|
|
The program does indeed connect to COM 5 after you install the bluetooth software that creates COM 5 as a virtual Serial Port. I have the program displaying the "Enter the first number: ," but it won't send anything when I enter a number. |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1909
|
|
Posted: Thu Feb 01, 2007 12:43 pm |
|
|
The only possibility is that the link from PC to PIC is broken, as it's obvious that the PIC is able to transmit to the PC. Can you easily add an LED or something to the PIC board and flash it when a certain do...while loop is entered or when it receives characters? This will help to determine if it is receiving absolutely nothing, or is receiving something and it's getting garbled somehow. |
|
|
bestbuylvr
Joined: 31 Jan 2007 Posts: 27 Location: Pittsburgh, PA
|
|
Posted: Thu Feb 01, 2007 1:30 pm |
|
|
OK, I tried to program a simple program to ask for a number and display the binary on LED's. The program displays "Enter a low number count: ," but it won't take any input when connected through the bluetooth. Apparently something is not connected properly with the Bluetooth software, perhaps a pin mixup. Do you know what pins are supposed to send and recieve from the PIC, and is the data signal long or strong enough to pic up with an analog voltmeter? THat is my last guess as to why this isnt recieving anything. If you have any other ideas, please inform me. Thanks for your help so far. Here is the code I used this time, pretty simple:
#include <protoalone.h>
#include <utility.c>
#include <stdlib.h>
#include <input.c>
main() {
int count;
while (TRUE) {
printf("\r\nEnter a low number count: ");
count=get_int();
show_binary_on_leds(count);
wait_for_one_press();
count++;
}
} |
|
|
bestbuylvr
Joined: 31 Jan 2007 Posts: 27 Location: Pittsburgh, PA
|
Oops |
Posted: Thu Feb 01, 2007 1:32 pm |
|
|
without the "count++;", by the way. Sorry, i gave you the version before i saved, not that it would even effect the thing. |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1909
|
|
Posted: Thu Feb 01, 2007 1:45 pm |
|
|
I doubt that you have the pins wrong as you said that your program worked when you connected PIC to PC without the wireless link. That said, C7 is receive (PC -> PIC), C6 is transmit (PIC -> PC).
If you don't have an oscilloscope or logic analyzer you really won't be able to "see" anything using a multimeter. However, you can check the idle state of the pins - they should idle high. Again, I don't think this is the problem as the PIC is able to get a message to the PC - it's just the reverse that is screwed up.
Make an even simpler test program. Just toggle an LED if the PIC receives ANY character at all. This will help to narrow down where the problem lies - in hardware or in the firmware. |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Thu Feb 01, 2007 2:06 pm |
|
|
Pls post the complete preprocessor directive related to the UART used.
#use RS232(........)
Humberto |
|
|
bestbuylvr
Joined: 31 Jan 2007 Posts: 27 Location: Pittsburgh, PA
|
|
Posted: Thu Feb 01, 2007 2:23 pm |
|
|
#include utility.c contains:
light_one_led(char led) {
output_high(GREEN_LED);
output_high(YELLOW_LED);
output_high(RED_LED);
switch(led) {
case GREEN_LED : output_low(GREEN_LED); break;
case YELLOW_LED : output_low(YELLOW_LED); break;
case RED_LED : output_low(RED_LED); break;
}
}
wait_for_one_press() {
while (input(PUSH_BUTTON)) ;
delay_ms (100);
while (!input(PUSH_BUTTON)) ;
}
show_binary_on_leds(int n) {
output_high(GREEN_LED);
output_high(YELLOW_LED);
output_high(RED_LED);
if (bit_test(n,0) )
output_low(GREEN_LED);
if (bit_test(n,1) )
output_low(YELLOW_LED);
if (bit_test(n,2) )
output_low(RED_LED);
}
#include input.c contains:
///////////////////////////////////////////////////////////////////////////
//// (C) Copyright 1996,2003 Custom Computer Services ////
//// This source code may only be used by licensed users of the CCS C ////
//// compiler. This source code may only be distributed to other ////
//// licensed users of the CCS C compiler. No other use, reproduction ////
//// or distribution is permitted without written permission. ////
//// Derivative programs created using this software in object code ////
//// form are not restricted in any way. ////
///////////////////////////////////////////////////////////////////////////
#include ctype.h
BYTE gethex1() {
char digit;
digit = getc();
putc(digit);
if(digit<='9')
return(digit-'0');
else
return((toupper(digit)-'A')+10);
}
BYTE gethex() {
int lo,hi;
hi = gethex1();
lo = gethex1();
if(lo==0xdd)
return(hi);
else
return( hi*16+lo );
}
void get_string(char* s, int max) {
int len;
char c;
--max;
len=0;
do {
c=getc();
if(c==8) { // Backspace
if(len>0) {
len--;
putc(c);
putc(' ');
putc(c);
}
} else if ((c>=' ')&&(c<='~'))
if(len<max) {
s[len++]=c;
putc(c);
}
} while(c!=13);
s[len]=0;
}
// stdlib.h is required for the ato_ conversions
// in the following functions
#ifdef _STDLIB
signed int get_int() {
char s[5];
signed int i;
get_string(s, 5);
i=atoi(s);
return(i);
}
signed long get_long() {
char s[7];
signed long l;
get_string(s, 7);
l=atol(s);
return(l);
}
float get_float() {
char s[20];
float f;
get_string(s, 20);
f = atof(s);
return(f);
}
#endif
[/b][/i]
Last edited by bestbuylvr on Thu Feb 01, 2007 2:58 pm; edited 1 time in total |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Feb 01, 2007 2:40 pm |
|
|
What is the purpose of posting tons of CCS .H files that we all have
on our systems anyway ? The forum rules say that CCS doesn't
want us to post their .H files on this forum.
In addition to that, you need to read Humberto's post at top of the
forum which says to disable HTML when you post code. If HTML
is enabled, the code will be garbled (as it is in your post).
Please edit your post and delete all the CCS .H files code. |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1909
|
|
Posted: Thu Feb 01, 2007 2:41 pm |
|
|
PCM programmer wrote: | What is the purpose of posting tons of CCS .H files that we all have
on our systems anyway ? The forum rules say that CCS doesn't
want us to post their .H files on this forum.
In addition to that, you need to read Humberto's post at top of the
forum which says to disable HTML when you post code. If HTML
is enabled, the code will be garbled (as it is in your post).
Please edit your post and delete all the CCS .H files code. |
And use the Code button too. |
|
|
bestbuylvr
Joined: 31 Jan 2007 Posts: 27 Location: Pittsburgh, PA
|
Sorry |
Posted: Thu Feb 01, 2007 3:04 pm |
|
|
Sorry guys, I'm new to this. You asked for the code, so I gave it to you. I'll be more cautious next time. Anyway, I tried to use a simple light one led program, and the PIC is not recieving anything through the bluetooth connection. I dont know if anybody has tried using bluetooth devices for this purpose, but if you have, let me in on any secrets. I have it set up to create a virtual serial port with the connection coming from the serial bluetooth adapter. I have the baud rate and all other settings set to match those of the serial port monitor along with the PIC. I'm drawing a blank here, I hope somebody has played with this before or has an idea why the bluetooth is not communicating properly. |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1909
|
|
Posted: Thu Feb 01, 2007 3:25 pm |
|
|
Can you try to transmit from one serial port on your PC to one bluetooth adapter, and receive on the other adapter which is connected to a different serial port on your PC?
This will allow you to see if the bluetooth connection is part of the problem or not. Right now there are too many unknowns. |
|
|
|