int BT_Configure(void);
void Init_BT_direct(void);
char BT_Get_Response(void);
void Test_BT_Answer(void);
int BT_Configure()
{
dummy=PutStrR_RS("---"); // Exit mode command mode
Put_RS(13);
Tempo(200000L);
dummy=PutStrR_RS("---"); // to be sure !
Put_RS(13);
Tempo(100000L);
State=0;
do
{
dummy=PutStrR_RS("$$$"); // Enter command mode, attend CMD
Put_RS(13);
Tempo(200000L);
//signed char memcmppgm2ram(const void * buf1,const rom void * buf2,sizeram_t memsize );
} while ((memcmppgm2ram(pBuff,"CMD",3)!=0)&& (Elapsed==0));
Test_BT_Answer();
if (State!=1)return(0);
do {
dummy=PutStrR_RS("SN,MyBT-DB49"); //Name of the device, 20 characters maximum
Put_RS(13);
Tempo(150000L);
} while ((memcmppgm2ram(pBuff,"AOK",3)!=0)&& (Elapsed==0));
Test_BT_Answer();
if (State!=2)return (0);
do {
dummy=PutStrR_RS("SU,19.2"); // Vitesse en bauds
Put_RS(13);
Tempo(150000L);
} while ((memcmppgm2ram(pBuff,"AOK",3)!=0)&& (Elapsed==0));
Test_BT_Answer();
if (State!=3)return(0);
do {
dummy=PutStrR_RS("SO,13"); //break caractere
Put_RS(13);
Tempo(150000L);
} while ((memcmppgm2ram(pBuff,"AOK",3)!=0)&& (Elapsed==0));
Test_BT_Answer();
if (State!=4)return (0);
do {
dummy=PutStrR_RS("SM,0");
// Set mode (0 = slave, 1 = master, 2 = trigger, 3 =auto, 4 = DTR, 5 = ANY)
Put_RS(13);
Tempo(150000L);
} while ((memcmppgm2ram(pBuff,"AOK",3)!=0)&& (Elapsed==0));
Test_BT_Answer();
if (State!=5)return (0);
do {
dummy=PutStrR_RS("SA,1"); // Authentication (1 to enable, 0 to disable)
Put_RS(13);
Tempo(150000L);
} while ((memcmppgm2ram(pBuff,"AOK",3)!=0)&& (Elapsed==0));
Test_BT_Answer();
if (State!=6)return (0);
do {
dummy=PutStrR_RS("SP,1234"); // Security pin code (mikroe)
Put_RS(13);
Tempo(150000L);
} while ((memcmppgm2ram(pBuff,"AOK",3)!=0)&& (Elapsed==0));
Test_BT_Answer();
if (State!=7)return (0);
do {
dummy=PutStrR_RS("---"); // fin mode config
Put_RS(13); // CR
Tempo(150000L);
} while ((memcmppgm2ram(pBuff,"END",3)!=0)&& (Elapsed==0));
Test_BT_Answer();
if (State!=8)return (0);
return(State); // si link OK on doit avoir State=8
}
void Test_BT_Answer()
{
if (Elapsed==0)
{
State++;
Erase_Ligne(2);
LCD_PutRamString(pBuff);
Arme_Elapsed_Timer3();
}
else
{
State=0;
}
}
******************************************
//use inside the main program
// and choose the correct slave to connect to Android App
// init partielle du RN41
Init_BT_RN41_direct() ;
Nokia_Erase_Ligne(7);
Nokia_Erase_Ligne(5);
if(Client_BT==1) // RB5==1 ?
{
// Adresse ARchos par defaut
dummy=PutStrR_RS("SR,D8952F3FF710");
Put_RS(13);
Nokia_PutRomString("SR,D8952F3FF710");
Delay_mS(100);
dummy=PutStrR_RS("C,D8952F3FF710"); // Connection forcee
Put_RS(13);
}
else
{
// Adresse PC cle USP APM
dummy=PutStrR_RS("SR,0015832B6D87");
Put_RS(13);
Nokia_PutRomString("SR,0015832B6D87");
Delay_mS(100);
dummy=PutStrR_RS("C,0015832B6D87");
Put_RS(13);
// Adresse HC05-7D69-B bleu as slave
// dummy=PutStrR_RS("SR,98D331B17D69");
// Put_RS(13);
// Nokia_PutRomString("SR,98D331B17D69");
// dummy=PutStrR_RS("C,98D331B17D69"); // Connection forcee
// Adresse HC06-1122-V Vert as slave
// dummy=PutStrR_RS("SR,201301241122");
// Put_RS(13);
// Nokia_PutRomString("SR,201301241122");
// Adresse HC06-2187-J as slave
// dummy=PutStrR_RS("SR,201308072187");
// Put_RS(13);
// Nokia_PutRomString("SR,201308072187");
}