Shop OBEX P1 Docs P2 Docs Learn Events
connecting RBT001 with ATMEGA16 (easyAVR4 board) — Parallax Forums

connecting RBT001 with ATMEGA16 (easyAVR4 board)

barjaktarbarjaktar Posts: 11
edited 2011-03-09 01:13 in Robotics
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.

Comments

  • FranklinFranklin Posts: 4,747
    edited 2010-08-26 19:59
  • barjaktarbarjaktar Posts: 11
    edited 2010-08-30 01:43
    Thank you, Franklin. I have seen this, but I am not really sure if I understand how this will work. VCC, GND, RX and TX are clear to me, but RTS and CTS are not.

    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?
  • Mike GreenMike Green Posts: 23,101
    edited 2010-08-30 06:36
    RTS is a signal from the RBT001 that is true (active low) when there is buffer space in the RBT001 to receive characters from the ATMEGA16. If your program is slow enough or it never outputs more than the RBT001 can accept, you can ignore it. Similarly, CTS is a signal from the ATMEGA16 that should be true (active low) if the ATMEGA16 has buffer space available to receive characters from the RBT001. It can be tied to Vss if there's always buffer space or the ATMEGA16 program is always fast enough to accept characters from the RBT001.

    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.
  • barjaktarbarjaktar Posts: 11
    edited 2010-08-30 07:22
    Mr Green, thank you for your reply.

    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.
  • barjaktarbarjaktar Posts: 11
    edited 2010-08-30 07:30
    I found examples at:

    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...
  • Mike GreenMike Green Posts: 23,101
    edited 2010-08-30 07:35
    There are all sorts of examples available for the Basic Stamp and the Easy Bluetooth module. The links are on the webstore page for the Easy Bluetooth module which is just an RBT001 and an adapter for the Board of Education (mostly a voltage regulator).

    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.
  • barjaktarbarjaktar Posts: 11
    edited 2010-09-01 11:52
    Thank you, Mr. Green.

    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.
  • Mike GreenMike Green Posts: 23,101
    edited 2010-09-01 12:10
    I'm afraid I can't help you very much. I know that sending a command like 0x66 using Usart_Write won't work. The command has to be embedded in a packet as described on page 22 (?) of the RBT001 documentation and I can't find a description of the 0x66 command, so I have no idea when or how it's used.
  • barjaktarbarjaktar Posts: 11
    edited 2010-09-02 13:23
    #include <avr/io.h>
    #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?
  • supralovasupralova Posts: 2
    edited 2010-09-22 19:02
    barjaktar wrote: »
    #include <avr/io.h>
    #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..
  • barjaktarbarjaktar Posts: 11
    edited 2010-10-18 17:25
    Thank you, supralova, but i figured it on my own. If somebody is interested I can put up c code.

    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)
  • kasuntkasunt Posts: 1
    edited 2011-02-22 01:17
    hi barjaktar,

    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
  • barjaktarbarjaktar Posts: 11
    edited 2011-03-09 01:13
    Kasunt, what exactly interests you?
Sign In or Register to comment.