connecting RBT001 with ATMEGA16 (easyAVR4 board)
Hello.
This is the first time I use a product of Parallax. Also, I have just begun with AVR, so please have patience.
I looked into the datasheet of RBT001, but I couldn't find a scheme that would explain how to connect this device with atmega16. I also searched this forum but I couldn't find any answer to my question.
How am I to connect RBT001 physically with atmega16? Please, draw me a scheme.
My intention is to use this system (RBT001 & atmega16) for communication with other bluetooth devices.
Thank you.
This is the first time I use a product of Parallax. Also, I have just begun with AVR, so please have patience.
I looked into the datasheet of RBT001, but I couldn't find a scheme that would explain how to connect this device with atmega16. I also searched this forum but I couldn't find any answer to my question.
How am I to connect RBT001 physically with atmega16? Please, draw me a scheme.
My intention is to use this system (RBT001 & atmega16) for communication with other bluetooth devices.
Thank you.
Comments
Page 7 has the connections to the device.
On atmega16 i will declare one of the ports as serial, and then connect directly RX and TX with corresponding pins of BT module. But what am I to do with RTS and CTS of the module?
The USART in the ATMEGA16 does not handle RTS and/or CTS. It's expected that these would be managed in software and would be other I/O pins. I suspect that the standard I/O routines for the USART make no provisions for them and it's beyond the scope of this forum to advise you on how to do that.
You could attach an external UART like the Maxim MAX3100 to your ATMEGA16. The MAX3100 has a larger buffer than the built-in USART in the ATMEGA16 and automatically handles RTS and CTS. It could communicate with the ATMEGA16 using the SPI protocol which the ATMEGA16 handles.
Let's say that there is always enough buffer space and we can ignore these pins. This would be correct "physical connection".
But what about the "software conenction"?
To be exact, I am interested in the physics of this module. How exactly, in what steps, does the precess of link establishment happens? Or, in another way said, what command am I to use in my program for atmege16 to achieve a bluetooth link with my, say, cell phone.
Are there any examples? Doesn't matter which uC, I just want to see the code, so I know what must I do.
And, after the link is established, what about the dataflow? If I am correct, RBT-001 should enter transparent mode and act just like a "link holder", nothing else. Right? Then, the data would just come in one byte at a time to a serial port of atmega16, yes?
Thank you.
http://www.parallax.com/tabid/768/ProductID/550/Default.aspx
and:
http://www.mikroe.com/sr/tools/bluetooth/easybt/
after a more thorough search. But still, other questions persist...
Once the RBT001 establishes a connection and enters transparent mode there is still a need for flow control (RTS and CTS). Bluetooth, like WiFi and xBee, is a packet protocol. Data is assembled into packets which are then sent from one device to another where it is disassembled. There's a timeout involved so, if more data isn't provided within a period of time, the short packet is sent even though it's not full. Depending on the data rate on the transmit end, it's quite possible for the receive end to get a nearly full packet and disassemble it (and send it to your ATMEGA16) faster than it can be handled even though the average data rate is within the capabilities of the receiving program.
But, allow me, please, to ask a little bit more about the basic principle of RBT001 functioning.
Let us assume that I have achieved desired settings for USART on my atmega16 and connected the module correctly.
Is this correct:
This line achieves entering bluetooth mode: Usart_Write(0x66); (because ENTER_BLUETOOTH_MODE is 0x66) Correct?
Thak you.
#include <inttypes.h>
void USARTInit(uint16_t ubrr_value)
{
//Set Baud rate
UBRRL = ubrr_value;
UBRRH = (ubrr_value >> 8);
/*Set Frame Format
>> Asynchronous mode
>> No Parity
>> 1 StopBit
>> char size 8
*/
UCSRC=(1<<URSEL)|(3<<UCSZ0);
//Enable The receiver and transmitter
UCSRB=(1<<RXEN)|(1<<TXEN);
}
char USARTReadChar(void)
{
//Wait untill a data is available
while(!(UCSRA & (1<<RXC)))
{
//Do nothing
}
//Now USART has got data from host
//and is available is buffer
return UDR;
}
void USARTWriteChar(char data)
{
//Wait until the transmitter is ready
while(!(UCSRA & (1<<UDRE)))
{
//Do nothing
}
//Now write the data to USART buffer
UDR=data;
}
void commandBT(char pckType, char opCode, short dLength, char pData){
USARTWriteChar(0x02); // begin USART frame
USARTWriteChar(pckType);
USARTWriteChar(opCode);
USARTWriteChar(dLength);
USARTWriteChar(dLength >> 8);
USARTWriteChar(pData);
short checksum = pckType + opCode + dLength;
short visiBajt = checksum << 8;
char niziBajt = visiBajt >> 8;
USARTWriteChar(niziBajt);
USARTWriteChar(0x03); // end USART frame
}
int main(void){
USARTInit(51);//calculated for baud = 9600 and fosc = 8MHz
commandBT('R', 0x4E, 0x02, 0x03);//opcode = SET_EVENT_FILTER (full cable replacement)
}
This is my program, for now.
All I want to do is to detect rbt001 with my cellphone - just to know that there is something going on...
My cellphone, when searches for bluetooth devices, sees nothing.
Please, what commands are to be sent for the bt module to answer?
Check This. And Download This Code To Your AVR (i use atmega 8535) using CodeVision AVR Program. This Code Make your easy bluetooh can detected into cell phone. Security number is 0000. Good Luck
+===============================================+
#include <mega8535.h> // Included Files
#include <stdio.h>
#include <delay.h>
#include <math.h>
void main(void)
{
PORTA=0xFF; DDRA=0x00; // Port A initialization
PORTB=0x00; DDRB=0x00; // Port B initialization
PORTC=0x00; DDRC=0x00; // Port C initialization
PORTD=0xFF; DDRD=0xFF; // Port D initialization
TCCR0=0x06; TCNT0=0x00; OCR0=0x00; // Timer 0 initialization
TCCR1A=0x00; TCCR1B=0x03; TCNT1H=0x0B; // Timer 1 initialization
TCNT1L=0xDB; OCR1AH=0x00; OCR1AL=0x00; // Clock value: 62.500 kHz
OCR1BH=0x00; OCR1BL=0x00;
ASSR=0x00; TCCR2=0x00; // Timer 2 initialization
TCNT2=0x00; OCR2=0x00;
MCUCR=0x00; MCUCSR=0x00; // External Interrupt(s) initialization
TIMSK=0x04; // Timer(s) Interrupt(s) initialization
UCSRA=0x00; UCSRB=0x08; // USART initialization
UCSRC=0x86; UBRRH=0x00; // USART Baud rate: 9600
UBRRL=0x19;
ACSR=0x80; SFIOR=0x00; // Analog Comparator initialization
}
===================================+
i'm sorry my english language so bad..
What interesets me now is to change the name of rbt001. Whan I start it and do a scan, my PC reports a device name EasyBT. I want it to be called AVR. So, here is the code for changing the name. What is wrong with it?
USARTWriteChar(0x02); // Send STX (Start of Transmission)
USARTWriteChar(0x52); // Type = REQ
USARTWriteChar(0x04); // Opcode = GAP_WRITE_LOCAL_NAME
USARTWriteChar(0x05); // Length = 5 (16-bit)
USARTWriteChar(0x00);
USARTWriteChar(0x5B); // Checksum
//DATA
USARTWriteChar(0x04); // Number of characters in the name
USARTWriteChar(0x41); // ASCII -> A
USARTWriteChar(0x56); // ASCII -> V
USARTWriteChar(0x52); // ASCII -> R
USARTWriteChar(0x00); // ASCII -> NULL (ends with a NULL)
USARTWriteChar(0x03); // Send ETX (End of Transmission)
i am doing a similar project. are you able to post your code ? And also how you hooked up the 4 wire UART ? i.e. RX TX CTS RTS