Continue to Site

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.

  • 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.

USART/RS232 VB6 communication

Status
Not open for further replies.
Would like to make sense to you, so you easy find out what i make mistake i attach my C program here as well.

Really thanks for your help...............
 

Attachments

  • test blutooth.zip
    7.8 KB · Views: 201
Would like to make sense to you, so you easy find out what i make mistake i attach my C program here as well.

Really thanks for your help...............

hi,
I dont use the 'C' programming language..I use assembler.

If I understand your post #20, all you want to do is send control characters from the PC [using VB] to a MCU using a RN41 link.??

If the RN41 is one way only, ie: transmit from the PC to the MCU, then you cannot expect a reply to the PC from the MCU.

I assumed that you had two radio link ie: transmit from the PC and also transmit from the MCU via the RN41, because in your VB program you had an On CommEvent which looped waiting for the MCU to send the 'OK' back.??

Question: is the radio link via the RN41 one way or two way.???


EDIT:
Will you post a diagram showing how you expect the project to work.?
 
Last edited:
RN41 is a bluetooth module which can received and transmit in a same module, so i will able to sent or receive signal between PC and PIC. I think it should be consider 2 ways.

so what i understand now is, i need to sent back a signal from PIC after I received a signal from PC is it??

I draw a simple flowchart here, hope you understand what i mean. Really sorry for my poor explaintion.

and i will upload the RN41 user manual as well.

Really thanks for your help.......
 

Attachments

  • RN-41.pdf
    248.5 KB · Views: 198
  • simple diagram.zip
    8.2 KB · Views: 172
hi,
Looked at your diagram, I understand that the PC has a RN41 connected to its Serial port and that the MCU also has a RN41, so the system is able to communicate in both directions.

The VB program I posted is able to Send and Receive data, so it should work as you are wanting, all you have to do is to add the 'commands' to the VB program that you want to send to the MCU.
It would be advisable to program the MCU to Send back the to the PC the command it has received in order to check the validity of the command.

If you need help in modifying the VB program, post to the Forum the commands or data that you want to use.:)

Thanks for the manual, but I have lots of information on the RN41...
 
O.......Really thanks for your help.......
I will try to do it now.......
but may i know one command line from your VB??
Text1.SelText = "K" & vbCrLf
What is this line for??

and in the PIC, i just need to write when it received "K" then sent back signal right??
 
O.......Really thanks for your help.......
I will try to do it now.......
but may i know one command line from your VB??
Text1.SelText = "K" & vbCrLf
What is this line for??

and in the PIC, i just need to write when it received "K" then sent back signal right??

hi,
Thats a procedure from your original program, the 'K', I left it in thinking that you had some use for it.???
Code:
your original code.
Private Sub cmdK1_Click()
If MSComm1.PortOpen = True Then
MSComm1.Output = "K"
Text1.Text = "K" & vbCrLf
End If
End Sub
EDIT:
I did notice in your original code that you have a Do....While... Loop, which waits for the 'OK' reply... what IF the OK never arrives.??

Place a DoEvents within any 'closed' loop so that User can escape from the program, else he has to use Ctl-Alt-Del.....
 
Last edited:
Sorry for that, but i can't get what you mean.you say that there are a "DO....While...Loop" in my command, but i din found it. you mean if statement??

And how to place DoEvents in the close loop??and which are the close loop you mean??

Really sorry for my poor VB skills.

hi,
Thats a procedure from your original program, the 'K', I left it in thinking that you had some use for it.???
Code:
your original code.
Private Sub cmdK1_Click()
If MSComm1.PortOpen = True Then
MSComm1.Output = "K"
Text1.Text = "K" & vbCrLf
End If
End Sub
EDIT:
I did notice in your original code that you have a Do....While... Loop, which waits for the 'OK' reply... what IF the OK never arrives.??

Place a DoEvents within any 'closed' loop so that User can escape from the program, else he has to use Ctl-Alt-Del.....
 
hi,
I see what happened, I used your first zip file that you posted, which has this Do Loop in.
In your corrected zip this section is not included, no problem
You would add a DoEvents as shown below.
The DoEvents allows the PC and your program to respond to User inputs,
eg: The EXIT button or clicking on the 'X' on the top right of the program window, so that it can be closed....OK.?
Code:
        ' Wait for the data to come back to the serial port.

        Do
            Buffer = Buffer & MSComm1.Input
        [B]DoEvents[/B]
        Loop Until InStr(Buffer, "OK" & vbCrLf)

        ' Read the "OK" response data in the serial port.
        ' Close the serial port.
 
Hi Eric,

Thanks for what you teach me. But now i face another problem. I found a file, it say that RN41 need to send somethings special command to go into the command mode before i able to send and received data.such as "$$$".

I used your program and modify a bit to let me able to sent the command the device need, but now i just able to reach the first part. After i sent "$$$" and received CMD feedback (mean into the confg time). I not able to do the other steps the device need. The device will not respone to me or sent back "!" to me. DO you know what shoud i do??

Sorry for my poor english and explaination.Really thanks for your help..........................
 

Attachments

  • RN_BlueportII-ref-guide.pdf
    2.3 MB · Views: 329
Hi Eric,

Thanks for what you teach me. But now i face another problem. I found a file, it say that RN41 need to send somethings special command to go into the command mode before i able to send and received data.such as "$$$".

I used your program and modify a bit to let me able to sent the command the device need, but now i just able to reach the first part. After i sent "$$$" and received CMD feedback (mean into the confg time). I not able to do the other steps the device need. The device will not respone to me or sent back "!" to me. DO you know what shoud i do??

Sorry for my poor english and explaination.Really thanks for your help..........................

hi,
So you say you are now able to communicate between the PC and PIC via the RN41's..ok???

The data sheet says you must respond within a limited time period. ie 60seconds.

Tell me what commands you want to send, also post your modified VB program and I will try to add the setup codes that you tell me.

Dont fuss about your English, its just fine..:)

Do this RESET when you restart...look at this image
 

Attachments

  • AAesp02.gif
    AAesp02.gif
    9.6 KB · Views: 186
hi,
Confirmation Check.

When you send from the PC to the RN41 the string "$$$" you should get the "CMD" response [ which I understand you do]

If you get the "CMD" this means that the PC to RN41 is OK.

You then send any other COMMANDS you need to make to the RN41, after each COMMAND sent you should get the "AOK" reply. [ else "ERR" if a problem]

To EXIT COMMAND mode send "---" & vbcrlf

Remember you have only 60 seconds before the COMMAND mode times out.

EDIT:
You do understand that in order to communicate with the PIC end of the link, that the PIC program has to confirm with its own RN41 the "$$$" ,,, "CMD" commands that its own serial connection is "AOK".

If you have not programmed the PIC, I would suggest you borrow another PC/Laptop and install a VB program that can control a RN41 and then use the two PC's to practice the setup command procedure and confirm that the RN41s are working OK.
 
Last edited:
Hi,

Not that fully success to connect, but it will respone me (CMD) when I sent out "$$$".

I would like to sent data like "A" , "B", "C" (character), so when the PIC received A , B, C, it will do what I need.

Sorry, i dun really get what it mean from the image. It is i should add some resistor in the RN-41 pin??If yes, do you know which pin and value of resistor i should add??

Really really thanks for your help.......



hi,
So you say you are now able to communicate between the PC and PIC via the RN41's..ok???

The data sheet says you must respond within a limited time period. ie 60seconds.

Tell me what commands you want to send, also post your modified VB program and I will try to add the setup codes that you tell me.

Dont fuss about your English, its just fine..:)

Do this RESET when you restart...look at this image
 

Attachments

  • ModComm2.zip
    77 KB · Views: 150
HI,

actually my problem is, i not able to get the AOK fedback after i sent command after $$$.Is it mean that I need to programer the PIC first only cna get that respone??I try to follow the example come from the PDF file i sent you in page 21 but i just able to do until the first step.

And you suggest that I should borrow another laptop to practice the setup command procedure and confirm that the RN41s are working OK, May i know how should i do??The bluetooth should not be able to connect 2 PC in a same times is it??

Sorry for so many question??I am really poor in that area. And really thanks you...........








hi,
Confirmation Check.

When you send from the PC to the RN41 the string "$$$" you should get the "CMD" response [ which I understand you do]

If you get the "CMD" this means that the PC to RN41 is OK.

You then send any other COMMANDS you need to make to the RN41, after each COMMAND sent you should get the "AOK" reply. [ else "ERR" if a problem]

To EXIT COMMAND mode send "---" & vbcrlf

Remember you have only 60 seconds before the COMMAND mode times out.

EDIT:
You do understand that in order to communicate with the PIC end of the link, that the PIC program has to confirm with its own RN41 the "$$$" ,,, "CMD" commands that its own serial connection is "AOK".

If you have not programmed the PIC, I would suggest you borrow another PC/Laptop and install a VB program that can control a RN41 and then use the two PC's to practice the setup command procedure and confirm that the RN41s are working OK.
 
hi,
The RN41 is getting a good connection to the PC, because when you send "$$$", its sending "CMD" back to the PC.

When are you sending "---" & vbcrlf to tell the RN41 to exit the Command mode..??

You must not be in the Command mode if you want to send data.

For the Laptop test, plug one RN41 into the laptop and the other RN41 into your PC, in that way you dont have to keep programming the PIC as you test and learn the RN41 operation.

I will look at your zip.

EDIT.
Try this program, it works OK with another PC as RN41
 

Attachments

  • ModComm3.zip
    18.2 KB · Views: 154
Last edited:
you mean that I need to sent data after "---" ??

I tot i should sent during the command mode?

SO at the end, i should go in to command mode first (sent $$$")

then out from command mode (sent "---")

After that only sent the data i want such as K ??
 
you mean that I need to sent data after "---" ??

I tot i should sent during the command mode?

SO at the end, i should go in to command mode first (sent $$$")

then out from command mode (sent "---")

After that only sent the data i want such as K ??

hi,
When you first switch ON, send the $$$ to the RN41, it should reply with CMD, which means that it is the Command mode and is receiving the PC commands OK.

If you do not want to write commands to the RN41, send --- & vbcrlf, that will set the RN41 into data transfer mode, send the 'K'.

I have put buttons on the VB program so that you can do these commands.

Can you post your PIC program, so that we can check that the PIC's RN41 is being programmed correctly.??
 
Erm......sorry, so at the end i should sent the command "K" during command mode or data mode?IS data mode right??

Sure, I will attach my C program here and I am using PIC16F877A.

Really thanks so much for your helping..............
 

Attachments

  • test blutooth.zip
    9.2 KB · Views: 147
Erm......sorry, so at the end i should sent the command "K" during command mode or data mode?IS data mode right??

Sure, I will attach my C program here and I am using PIC16F877A.

Really thanks so much for your helping..............

hi,
When the RN41 is in COMMAND mode, you would send from the PC to the RN41 any set up commands, example, if you wanted to change the Baud rate.
To EXIT the COMMAND mode you send --- & vbcrlf, after you have done that you are data transfer mode, send the K or any other data you need to send.

EDIT:
I do not use the 'C' language, so I have posted your *.c file so someone else can check it out.
Code:
//==============================================================================================
// 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;
    TRISD = 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)
{
    init();

  do  {

               a = receive();
                  if (a == 'K')
                      {
                   portb.f7=1;
                   display("X");
                   
                       }

          a = receive();
              if(a == 'A')
                {
                   portb.f6=1;
                   display("Y");
                }

        }while(1) ;

}
 
Last edited:
hi,
Do you understand that the Factory defaults are 115,200 Baud and that the PC should be set to the same Baud rate.

I see that the PIC end RN41 is set for 115,200Baud, change the VB program to the same settings.

Read this image.
 

Attachments

  • AAesp01.gif
    AAesp01.gif
    44.2 KB · Views: 183
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top