Problem in connecting Bluetooth starter kit with pic18f4520

Bluetooth, XBee, RF......

Problem in connecting Bluetooth starter kit with pic18f4520

Postby nick_lamkh » Thu Mar 18, 2010 12:29 am

Hello hope this will help me understand better.I bought a Bluetooth starter kit with kc-21 on it. i read the manual prepared by cytron and the pr6a. i use the starter kit to integrate with a pic18f4520 and use the same way to initialized the program other than the pic18 related commands. since pic18f4520 has the almost similar pin as pic16f877a there is not much diff i have to make in the setting. i did change the output to controlling decoder. The main problem is that i with the source code provided by cytron and example circuits i found out that i cant really establish an connection with the bluetooth module wirelessly.can u recomend me some solution and thing that i have too check to.

to make it easier to understand i include the source code. part of it
i did connect the connection to rx-tx and tx - rx

CODE: SELECT_ALL_CODE
//Include files
#include <p18f4520.h>
#include <delays.h>

//Configuratio
//_CONFIG(0x3F32);       // would like to know know what am i suppose to include for this part?

//Define
#define   D   PORTDbits.RD0   //define port d 0 as DATA In pin
#define   A0   PORTDbits.RD3   //define port d 3 as selector pin 0
#define   A1   PORTDbits.RD4   //define port d 4 as selector pin 1     
#define   A2   PORTDbits.RD5   //define port d 5 as selector pin 2
#define   LE   PORTDbits.RD1   //define port d   1 as active low enable pin
#define BRGH TXSTAbits.BRGH
#define TXEN TXSTAbits.TXEN
#define CREN RCSTAbits.CREN
#define SPEN RCSTAbits.SPEN
#define TXIF PIR1bits.TXIF
#define RCIF PIR1bits.RCIF
#define TX9  TXSTAbits.TX9
#define SYNC TXSTAbits.SYNC
//Function Prototype
void   init   (void);
void   display   (unsigned char c);
unsigned char receive (void);
void    string   (rom char *ptr);

unsigned char a;

rom char *msg1 = "        Wellcome";
rom char *msg2 = "Bluetooth Control Panel Board";
rom char *msg3 = "       Control Menu";
rom char *msg4 = "     1/2 : Lighting";
rom char *msg5 = "     3/4 : Fan";
rom char *msg6 = "     5/6 : Output 1";
rom char *msg7 = "     7/8 : Output 2";
rom char *msg8 = "     on/off";
rom char *mag9 = "Please insert your option";

void    string   (rom char *ptr) //display string
{
   while(*ptr)
   {
   display(*ptr);
   ptr++;
   }
}

void   init   (void) //initialize sub routine
{
   TX9=0;   //setting to 8 bit transmission
   SYNC=0;   //asynchronous mode
   SPBRG=10;   //setting baud rate as 115200 baud
   BRGH=1;   //High speed baud rate select
   TXEN=1;   //Transmit enabled
   CREN=1;   //Enables continuous receive
   SPEN=1;   //Serial port enabled (configures RC7 and RC6 pins as serial port pins)
    TRISD=0;   //define ports as output
//   TRISCbits.TRISC6=1; //output to KC21
//   TRISCbits.TRISC7=1;   //input from KC21
//   TXSTA=0b00100100;
//   RCSTA=0b10010000;
//   SPBRG=10;
}
void display (unsigned char c)   //subroutine to display text on screen

{
   //TXSTA=0x24;
   //SPBRG=10;
   //TXEN=1;
   //SPEN=1;
   while (!TXIF);
   TXREG=c;
}
unsigned char receive (void)   //subroutine to receive command from pc

{   
   //RCSTA=0x90;
   //SPBRG=10;
   while (!RCIF);
   a=RCREG;
   return a;
}

//Main Function

void main (void)
{
   init();
   while(1)//wait for "ok" to be entered
   {
      a=receive();
      if (a=='o')
         {
            a = receive();
            if(a=='k')
            break;
         }
   }

//Text will be display on Hyperterminal after 'ok' is entered
   string(msg1);
   display(0x0a); //next line
   display(0x0d);
   string(msg2);
   display(0x0a);
   display(0x0d);   
   string(msg3);
   display(0x0a);
   display(0x0d);
   string(msg4);
   display(0x0a);
   display(0x0d);
   string(msg5);
   display(0x0a);
   display(0x0d);
   string(msg6);
   display(0x0a);
   display(0x0d);
nick_lamkh
Greenhorn
 
Posts: 3
Joined: Wed Mar 17, 2010 7:04 pm

Re: Problem in connecting Bluetooth starter kit with pic18f4520

Postby nick_lamkh » Thu Mar 18, 2010 2:37 am

Helo just wan to include that do we need any other ways to begain the kc21 receiving and transmitting bytes. this is cause as i send the value "ok" the kc21 would not reply. i conclude so cos there is no response from the kc21 as bites are send.the blue soliel software shows to be connected but wen in hyperterminal or kctoolkit it would not reply as suggested by cyton.as u can see i have writen the coding according to cytron pr6a
nick_lamkh
Greenhorn
 
Posts: 3
Joined: Wed Mar 17, 2010 7:04 pm

Re: Problem in connecting Bluetooth starter kit with pic18f4520

Postby ober » Thu Mar 18, 2010 9:46 am

please share your source code properly.

verify your source code on PIC18F by connecting it to computer directly. use HyperTerminal to key in 'ok', if it does not reply, it might be something wrong with your source code, or hardware setup. If it reply correct message, then check the connection between PIC18F with KC21.
Ober Choo
Cytron Technologies Sdn Bhd
www.cytron.com.my
User avatar
ober
Moderator
 
Posts: 1486
Joined: Wed Apr 15, 2009 1:03 pm

Re: Problem in connecting Bluetooth starter kit with pic18f4520

Postby nick_lamkh » Thu Mar 18, 2010 11:58 am

I have check my code and followed the steps but it wont connect?what did i miss?
CODE: SELECT_ALL_CODE
rom char *com1 = "AT+ZV Version";
rom char *com2 = "AT+ZV Discovery";
rom char *com4 = "AT+ZV SPPConnect 111111111111";
rom char *com3 = "AT+ZV Bond 111111111111 1234";
rom char *com5 = "AT+ZV RemoteCommand e";

do i need to include this?
if yes what part please...do u have any specific source that i can refer too.
nick_lamkh
Greenhorn
 
Posts: 3
Joined: Wed Mar 17, 2010 7:04 pm

Re: Problem in connecting Bluetooth starter kit with pic18f4520

Postby ober » Sat Mar 20, 2010 2:03 pm

So you are trying to establish connection to laptop/computer Bluetooth from KC21? I am assuming that.

The easier way to verify whether you are sending correct command and will the KC21 make connection after receive these command are to use computer again.

Computer 1 ----- KC21 Computer 2 with Bluetooth dongle

So send those commands from HyperTerminal (at computer 1) after you have connect KC21 to computer 1(If you have SKKCA, just through USB). Looking at the response at HyperTerminal. If it cannot create connection, you have send wrong command, play with it until you get connection.

If this is done, verify your microcontroller is sending correct command to computer, try to use computer as KC21 and look at the command send by microcotroller.
Ober Choo
Cytron Technologies Sdn Bhd
www.cytron.com.my
User avatar
ober
Moderator
 
Posts: 1486
Joined: Wed Apr 15, 2009 1:03 pm


Return to Wireless Device

Who is online

Users browsing this forum: No registered users and 32 guests

cron