what is the V+ and V- for the amplifier
ah - sorry - wrong window .. i was replying another thread when reading yours
.. cool .. u already have the communication tested working ..
from what i read in your post - the echo worked .. and stopped when pic was held in reset - thus confirming that your code was doing the echoing
and now when u want to transfer from pic to bluetooth(phone) - it stopped working ?
should be some minor bug in code
i would suggest to use the same routine you use to receive character ( and echo it ) .. since it was tested before
but instead of echo send the new data you want ..
the variable type depends on the way your compiler handles it ..
if your data is 8 - bits long (assuming that) you could also define it as int8 . or byte .. depends on what your compiler supports
hello
I don't know what is your bluetooth device.
I am using bluetooth-click device
in the technical document i saw, something interessting to wake up the device by receiving a BREAK
Trigger Master Mode (SM,2)
In this mode, the device will automatically connect to the pre configured remote slave address when
a character (or characters) are received on the local UART. Connection will remain open until a
configurable idle timer (1 to 255 seconds) expires with no data being received, or a configurable
BREAK character is seen.
but in this case PIC side is MASTER !
the data type may not be a problem .. but u can try unsigned char to be sure you are using 8 bits of data
you first need to get it working in the echo mode ..
i doubt that you are not using the same baud on both ends .. that's when USART communication causes errors like you mentioned
can u cross check this and see if it works
// Program to depict the configuration of EUSART in PIC18F4550
// This code receives and then transmits the same data back to the phone .. // ..
#include "p18f4550.h" // Always include the header file
#include "delays.h"
#include "string.h"
#include "usart.h"
// Configuration bits
/* _CPUDIV_OSC1_PLL2_1L, // Divide clock by 2
_FOSC_HS_1H, // Select High Speed (HS) oscillator
_WDT_OFF_2H, // Watchdog Timer off
MCLRE_ON_3H // Master Clear on
*/
#pragma config FOSC = HSPLL_HS // Using 20 MHz crystal with PLL
#pragma config PLLDIV = 5 // Divide by 5 to provide the 96 MHz PLL with 4 MHz input
#pragma config CPUDIV = OSC1_PLL2 // Divide 96 MHz PLL output by 2 to get 48 MHz system clock
#pragma config USBDIV = 2 // USB clock comes from 96 MHz PLL output / 2
#pragma config FCMEN = OFF // Disable Fail-Safe Clock Monitor
#pragma config IESO = OFF // Disable Oscillator Switchover mode
#pragma config PWRT = OFF // Disable Power-up timer
#pragma config BOR = OFF // Disable Brown-out reset
#pragma config VREGEN = ON // Use internal USB 3.3V voltage regulator
#pragma config WDT = OFF // Disable Watchdog timer
#pragma config MCLRE = ON // Enable MCLR Enable
#pragma config LVP = OFF // Disable low voltage ICSP
#pragma config ICPRT = OFF // Disable dedicated programming port (44-pin devices)
#pragma config CP0 = OFF // Disable code protection
void tx_data(unsigned char);
unsigned char rx_data(void);
unsigned char serial_data;
unsigned int i=0;
#define FREQ 20000000 // Frequency = 20MHz
#define baud 9600
#define spbrg_value (((FREQ/64)/baud)-1) // Refer to the formula for Baud rate calculation in Description tab
void main()
{
SPBRG=spbrg_value; // Fill the SPBRG register to set the Baud Rate
RCSTAbits.SPEN=1; // To activate Serial port (TX and RX pins)
TXSTAbits.TXEN=1; // To enable transmission
RCSTAbits.CREN=1; // To enable continuous reception
while(1)
{
serial_data=rx_data(); // Receive data from PC
tx_data(serial_data); // Transmit the same data back to PC
}
}
void tx_data(unsigned char data1)
{
TXREG=data1; // Store data in Transmit register
while(PIR1bits.TXIF==0); // Wait until TXIF gets low
}
unsigned char rx_data(void)
{
while(PIR1bits.RCIF==0); // Wait until RCIF gets low
return RCREG; // Retrieve data from reception register
}
and this is the change I made to transmit directly from the code..
while(1)
{
[COLOR="#FF0000"] //serial_data=rx_data(); [/COLOR] // Receive data from PC
tx_data(); // Transmit the same data back to PC
Delay1KTCYx(100);
}
}
void tx_data(void)
{
[COLOR="#FF0000"]TXREG='f'; [/COLOR] // Store data in Transmit register
while(PIR1bits.TXIF==0); // Wait until TXIF gets low
}
unsigned char rx_data(void)
{
while(PIR1bits.RCIF==0); // Wait until RCIF gets low
return RCREG; // Retrieve data from reception register
}
meaning that it automatically adjusts the baud rate.
Atleast that's what the datasheet mentioned.
Nevertheless I assigned a baud rate in my code
void Init_BT_direct()
{
OUT_RS232
dummy=PutStrR_RS("$$$"); // Enter command mode
Put_RS(13);
OUT_LCD
LCD_Erase_Ligne(1); LCD_PutRomString(" 1 init mode CMD");
LCD_Erase_Ligne(2); LCD_PutRomString("$$$ ");
Tempo(100000);
OUT_RS232
dummy=PutStrR_RS("+"); // Security pin code (mikroe)
Put_RS(13);
OUT_LCD // CR
LCD_Erase_Ligne(1);LCD_PutRomString("active Echo ");
LCD_Erase_Ligne(2);
Tempo(100000);
OUT_RS232
dummy=PutStrR_RS("SN,MyBT-DB49"); // Name of device
Put_RS(13);
OUT_LCD
LCD_Erase_Ligne(1); LCD_PutRomString(" 2 Name ");
LCD_Erase_Ligne(2); LCD_PutRomString("SN,MyBT-DB49 ");
Tempo(100000);
dummy=PutStrR_RS("SO,CONN"); // Extended status string
Put_RS(13);
LCD_Erase_Ligne(1);LCD_PutRomString(" 3 ");
LCD_Erase_Ligne(2); LCD_PutRomString("SO,CONN ");
Tempo(100000);
OUT_RS232
dummy=PutStrR_RS("SM,0");
// Set mode (0 = slave, 1 = master, 2 = trigger, 3 =auto, 4 = DTR, 5 = ANY)
Put_RS(13);
OUT_LCD
LCD_Erase_Ligne(1);LCD_PutRomString(" 4 mode Slave ");
LCD_Erase_Ligne(2);LCD_PutRomString("SM,0 ");
Tempo(100000);
OUT_RS232
dummy=PutStrR_RS("SA,1"); // Authentication (1 to enable, 0 to disable)
Put_RS(13);
OUT_LCD
LCD_Erase_Ligne(1);LCD_PutRomString(" 5 Authentifie .");
LCD_Erase_Ligne(2);LCD_PutRomString("SA,1 ");
Tempo(100000);
OUT_RS232
dummy=PutStrR_RS("SP,1234"); // Security pin code (mikroe)
Put_RS(13);
OUT_LCD
LCD_Erase_Ligne(1);LCD_PutRomString(" 6 Security Pin.");
LCD_Erase_Ligne(2);LCD_PutRomString("SP,1234 ");
Tempo(100000);
OUT_RS232
dummy=PutStrR_RS("SU,38.4"); // Speed uart defined with 4 caracteres
// dummy=PutStrR_RS("SU,9600"); // Speed uart
Put_RS(13);
OUT_LCD
LCD_Erase_Ligne(1);LCD_PutRomString("7 New Uart Speed");
LCD_Erase_Ligne(2);LCD_PutRomString("SU,38.4 ");
Tempo(100000);
OUT_RS232
dummy=PutStrR_RS("---"); // Security pin code (mikroe)
Put_RS(13);
OUT_LCD // CR
LCD_Erase_Ligne(1);LCD_PutRomString(" 8/8 mode Cde ");
LCD_Erase_Ligne(2);LCD_PutRomString("--- fin init ");
Tempo(100000);
LCD_Erase_Ligne(2);
LCD_Erase_Ligne(1);
}
At this init, i set my speed to 38400 bauds !
and i am using SLAVE mode in my application..
hello
but in your code you have
#define FREQ 20000000 // Frequency = 20MHz
#define baud 9600
#define spbrg_value (((FREQ/64)/baud)-1) // Refer to the formula for Baud rate calculation in Description tab
My bluetooth device had a default Uart speed of 115200 bds or 9600bds by using extra input.
I configured my PIC UART at 38400 bds AND ALSO my Bluetooth device at the same speed..
so i can test it with PC terminal with same speed on virtual COMx port.
did you successfull get a dialogue between your BT device (PIC side) and PC terminal with virtual port on bluetooth
its more easy to have this first test before to do trials with a phone ....
this is my init sequence for my device..
do you have specsheet data for your device ? to see details for init.
Code:void Init_BT_direct() { OUT_RS232 dummy=PutStrR_RS("$$$"); // Enter command mode Put_RS(13); OUT_LCD LCD_Erase_Ligne(1); LCD_PutRomString(" 1 init mode CMD"); LCD_Erase_Ligne(2); LCD_PutRomString("$$$ "); Tempo(100000); OUT_RS232 dummy=PutStrR_RS("+"); // Security pin code (mikroe) Put_RS(13); OUT_LCD // CR LCD_Erase_Ligne(1);LCD_PutRomString("active Echo "); LCD_Erase_Ligne(2); Tempo(100000); OUT_RS232 dummy=PutStrR_RS("SN,MyBT-DB49"); // Name of device Put_RS(13); OUT_LCD LCD_Erase_Ligne(1); LCD_PutRomString(" 2 Name "); LCD_Erase_Ligne(2); LCD_PutRomString("SN,MyBT-DB49 "); Tempo(100000); dummy=PutStrR_RS("SO,CONN"); // Extended status string Put_RS(13); LCD_Erase_Ligne(1);LCD_PutRomString(" 3 "); LCD_Erase_Ligne(2); LCD_PutRomString("SO,CONN "); Tempo(100000); OUT_RS232 dummy=PutStrR_RS("SM,0"); // Set mode (0 = slave, 1 = master, 2 = trigger, 3 =auto, 4 = DTR, 5 = ANY) Put_RS(13); OUT_LCD LCD_Erase_Ligne(1);LCD_PutRomString(" 4 mode Slave "); LCD_Erase_Ligne(2);LCD_PutRomString("SM,0 "); Tempo(100000); OUT_RS232 dummy=PutStrR_RS("SA,1"); // Authentication (1 to enable, 0 to disable) Put_RS(13); OUT_LCD LCD_Erase_Ligne(1);LCD_PutRomString(" 5 Authentifie ."); LCD_Erase_Ligne(2);LCD_PutRomString("SA,1 "); Tempo(100000); OUT_RS232 dummy=PutStrR_RS("SP,1234"); // Security pin code (mikroe) Put_RS(13); OUT_LCD LCD_Erase_Ligne(1);LCD_PutRomString(" 6 Security Pin."); LCD_Erase_Ligne(2);LCD_PutRomString("SP,1234 "); Tempo(100000); OUT_RS232 dummy=PutStrR_RS("SU,38.4"); // Speed uart defined with 4 caracteres // dummy=PutStrR_RS("SU,9600"); // Speed uart Put_RS(13); OUT_LCD LCD_Erase_Ligne(1);LCD_PutRomString("7 New Uart Speed"); LCD_Erase_Ligne(2);LCD_PutRomString("SU,38.4 "); Tempo(100000); OUT_RS232 dummy=PutStrR_RS("---"); // Security pin code (mikroe) Put_RS(13); OUT_LCD // CR LCD_Erase_Ligne(1);LCD_PutRomString(" 8/8 mode Cde "); LCD_Erase_Ligne(2);LCD_PutRomString("--- fin init "); Tempo(100000); LCD_Erase_Ligne(2); LCD_Erase_Ligne(1); } At this init, i set my speed to 38400 bauds ! and i am using SLAVE mode in my application..
By the way, I dont understand how to test it with a PC terminal. Do I need any extra equipment, or will a bluetooth capable laptop suffice
Hi,
Try sending the ASCII number from your pic; for example, to receive an "A' on your Blueterm, send 65 (decimal) from your pic to the BT module.
Let us know if that works for you.
Regards,
Anand Dhuru
"I tried using unsigned char, to send a single character 'f', but on receiving the phone was displaying 'u'"
see if the UART uses NRZI encoding to send/receive data
I couldn't find the option to change the encoding type in the PIC datasheet.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?