View previous topic :: View next topic |
Author |
Message |
franciscoloramecatronica
Joined: 10 Dec 2012 Posts: 1
|
bluetooth hc-06 and hc-05 |
Posted: Mon Dec 10, 2012 7:58 pm |
|
|
hi, I tried operating a Bluetooth module, but I have not been successful, the Bluetooth module are HC-06 and HC-05, attempt Smarth communicate with Android 2.3, but I get absolute rubbish
Code: |
//Archivos de cabecera:
#include "18F45k22.h"
#FUSES NOWDT,INTRC,NOMCLR
#use delay(clock=4000000)
#include "flex_lcd.h"
/* configure and enable uart, use first hardware UART on PIC */
#use rs232(uart1, baud=9600)
char dato_recibido[16]; /// aqui va a ir los datos recibidos por rs232
#int_rda
void rd_isr(void)// datos USART
{
gets(dato_recibido);
}
void main()
{
lcd_init();
enable_interrupts(global);//Habilito interrupcion global
enable_interrupts(int_rda); //Habilito interrupción USART
//printf("AT+BAUD4");
delay_ms(20);
//printf("AT+PN");
while(1){
lcd_gotoxy(1,1);
printf("AT+VERSION");
printf("\n");
delay_ms(2000);
printf(lcd_putc,"%s",dato_recibido);
// lcd_putc("%s",dato_recibido);
// dato_recibido="";
delay_ms(2000);
}
} |
|
|
|
WingNut
Joined: 04 Nov 2012 Posts: 6 Location: NC
|
|
Posted: Mon Dec 10, 2012 8:27 pm |
|
|
First, you didn't say what version of compiler you are using.
Test things one at a time:-
1) Get 1Hz LED flasher going, to confirm PIC is OK.
2) Get the RS232 to work. Note : add ERRORS to the #USE RS232
2) Get LCD to work
3) Then add Bluetooth. |
|
|
Douglas Kennedy
Joined: 07 Sep 2003 Posts: 755 Location: Florida
|
|
Posted: Tue Dec 11, 2012 7:37 am |
|
|
It often helps to understand what a specific interrupt does in hardware before writing code. An example is the RDA interrupt. The hardware receives characters and interrupts for each and every character. This means the code in the RDA isr must also just accept a single char and exit after having done the bare minimum of other things like place the single char into a RAM buffer increment a pointer etc. The code must always be as lean and mean as is possible especially with RDA since the next character needs to be accepted without much delay. The use of gets (usually accepts a string of n chars ) breaks the rule of understanding the hardware before coding. |
|
|
|