1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

USART/RS232 VB6 communication

Discussion in 'Microcontrollers' started by Mark Lazarides, Feb 8, 2004.

  1. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,181
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    hi,
    I would like to help you, but can you explain your project in more detail.:)

    You first asked for UART/VB RS232 Comms, then you said you wanted to send data from a PC to a PIC via a RN41.

    I explained that you would need a RN41 at the PC end and at the PIC end in order to communicate.

    The simple VB program I posted did enable you to get the 'CMD' response when the PC sent the "$$$" command, this means the PC and RN41 are linked OK.

    You then said you wanted to wire the PIC TX and RX directly to the PC as well as an RN41, you cannot do that.

    You now say you have a laptop with Bluetooth and that you want to communicate with a RN41 and PIC.

    You can see my problem I am not clear at all what you are trying to do, so please tell me and post a clear diagram.
     
  2. Mosaic

    Mosaic Well-Known Member

    Joined:
    Jun 3, 2010
    Messages:
    2,569
    Likes:
    128
    Location:
    Caribbean
    Not to hijack , but I have a requirement that involves this topic,
    i'd like to use VB6 to load a bmp or png format 1 bpp graphic and then xmit via rs232 to a HW 16F886 UART.
    The graphic file will be built at multiples of 8 bits wide. Eg 48 pixels or 128 pixels wide.
    The file can be of any number of rows of pixels. I'd like to use rts/cts to control the data flow as the PIC will have to do some data handling and need to limit data speeds. Perhaps a 19.2Kbaud rate will do.

    thx for any advice
     
  3. reeve333

    reeve333 New Member

    Joined:
    Apr 7, 2011
    Messages:
    41
    Likes:
    0
    O......Sorry for my bad explaination.

    Actually my project is control a spider robot through computer. Therefore, The PC should be able to communicated with the robot (mean PIC since it is the heart of robot)

    To let the PC and PIC link, I used a bluetooth device (sure, my PC got bluetooth also).

    The RN41 is build with the PIC in the PCB board, (TX of RN41 connect to pin TX of PIC, RX of RN41 connect to pin RX of PIC), I tot is already able to communicated with PIC. Is it? or I am wrong??

    Since the main board (PIC there) got RN41, so i think it able to send and received data from bluetooth le right?? Therefore I sent the data from PC via bluetooth to the PIC and control it.

    Sorry for my bad english and explaination, I make simple diagram, hope it is make you easy to undestand.
     

    Attached Files:

  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,181
    Likes:
    644
    Location:
    Ex Yorks' Hants UK

    hi,
    The RN41 datasheet says that the RN41 is compatible with Bluetooth, so you should be able to communicate between your laptop and the PIC via the RF link.
    You have already sent "$$$" to the laptops Bluetooth and got the "CMD" response, so that part is OK.

    Have you tested the PIC link to it RN41.???
    You should send "$$$" from the PIC to its RN41 and check that it sends "CMD" back to the PIC,,,, can you do that.???
     
  6. reeve333

    reeve333 New Member

    Joined:
    Apr 7, 2011
    Messages:
    41
    Likes:
    0
    Sorry for that.......

    But how do I sent the $$$ to the RN41 from PIC??
    and I do not have a screen show from the PIC, show how can know the respone from RN41??
     
  7. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,181
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    hi.
    Connect a switch and pull up resistor to an input pin on the PIC, program the PIC to read the pin.
    When the swicth is pressed the PIC sends "$$$" to the RN41 via its UART.

    Connect a resistor and LED to a PIC output pin.

    When the PIC's UART reads the RN41 reply "CMD" correctly , it lights the LED.

    OK?
     
  8. reeve333

    reeve333 New Member

    Joined:
    Apr 7, 2011
    Messages:
    41
    Likes:
    0
    Icic.......
    but the pull up resistor you mean is 1K resistor??
    and the UART mean the RX pin is it??
    so in the program i should write when the RX pin received CMD then theLED light is it??
    sorry for that........

    and really thanks for your help......
     
  9. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,181
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    hi,
    Which programming language are you using for the PIC and what is the PIC.?
     
  10. reeve333

    reeve333 New Member

    Joined:
    Apr 7, 2011
    Messages:
    41
    Likes:
    0
    I am using Micro C and I am using PIC 16F877A.................
     
  11. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,181
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    I use assembler, I dont use the 'C' program language.

    Other members who use MicroC maybe able to help.
     
  12. reeve333

    reeve333 New Member

    Joined:
    Apr 7, 2011
    Messages:
    41
    Likes:
    0
    Oic.......
    Sorry, I still testing the bluetooth and PIC now. Therefore, it mean that after PIC sent $$$ to the RN41, and get the respone "CMD" Then I sent "---" again. I will able to communicated with the PC le??
     
  13. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,181
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    Once you have confirmed that the 'wired' connection at both ends of the RF link, that is, PIC to the RN41 and Laptop to Bluetooth,,check that both the RN41 and Bluetooth are set up in the same way.
    You will have to read the datasheet for the RN41 and Bluetooth settings, to ensure that settings for both ends of the RF link are compatible.
     
  14. reeve333

    reeve333 New Member

    Joined:
    Apr 7, 2011
    Messages:
    41
    Likes:
    0
    Icic......
    Thanks you very much, I will try it first.........
    Thanks a lot..............
     
  15. reeve333

    reeve333 New Member

    Joined:
    Apr 7, 2011
    Messages:
    41
    Likes:
    0
    Hi.....

    Sorry I meet a problem again....
    I don't know how to communicated the RN41 with PIC.
    Since when i communicated the the RN41 with PC i need to use "open port" then then RN-41's Green LED will on (mean connected). But for PIC, I dun know how to do it since it already straigh away connect the pin to pin.

    Sorry for my bad explaination, do you know what i mean??IF know, do you mind tell me what should I do??
    and for the C programming part, I write somethings coding as below...

    ========================================================================================================================

    //==============================================================================================
    // TX and RX Function
    //==============================================================================================

    unsigned char a;

    void init(void) // subroutine to initialize
    {
    SPBRG=0x0A; // set baud rate as 115200 baud
    INTCON.BRGH=1;
    INTCON.TXEN=1;
    INTCON.CREN=1;
    INTCON.SPEN=1;
    TRISB = 0b00000000;
    }

    void display(unsigned char c) // subrountine to display the text on the screen
    {
    while (TXIF == 0);
    TXREG = c;
    }

    unsigned char receive(void) // subrountine to receive text from PC
    {
    while (RCIF == 0);
    a = RCREG;
    return a;
    }


    //================================================================================================
    // Main Function
    //================================================================================================
    void main(void)
    {

    trisa=1;
    porta=1;
    trisc=0x80;
    portc=0x80;
    trisb=0;
    portb=0;
    init();

    do {
    //==================================================================================
    //Senting $$$ to the RN-41, to get the respone CMD
    //==================================================================================

    if (porta.f0=1)
    {
    display('$');
    display('$');
    display('$');
    }

    while(1) // Wait for 'ok' to be entered by user
    {
    a = receive();
    if (a == 'C')
    {
    a = receive();
    if (a == 'M')
    {
    a = receive();
    if (a == 'D')
    {
    portb.f7=1;
    }
    }
    }
    }

    //==================================================================================
    //Senting --- to the RN-41, to get the respone END
    //==================================================================================

    if (porta.f1=1)
    {
    display('-');
    display('-');
    display('-');
    }

    while(1) // Wait for 'ok' to be entered by user
    {
    a = receive();
    if (a == 'E')
    {
    a = receive();
    if (a == 'N')
    {
    a = receive();
    if (a == 'D')
    {
    portb.f6=1;
    }
    }
    }
    }

    }while(1) ;

    }

    ========================================================================================================================

    Really thanks for your help......
     
  16. reeve333

    reeve333 New Member

    Joined:
    Apr 7, 2011
    Messages:
    41
    Likes:
    0
    Hi......

    Sorry, I found that i make mistake last time.......But my problem a bit difference. As I say I success to communicate with the RN41 (Bluetooth device) but notable to sent the data to PIC. I found it is because I not able to connect success to the Bluetooth.

    Because after i go into the command mode and sent "C" to it, it will respone me connected fail. May i know what happen for it??How should I fix it??
    Really sorry for my bad explanition.Really hope you can help me.
     

Share This Page