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.
I'm designing a system that monitors an area for people carrying tags, and then tailors the area for them based on their preferences. I'm using Visual basic 6 for the user/pc interface. Being new to the joys of microcontrollers i'm slightly baffled by the USART module of the PIC 16f627 that I'm using though.

From what i've read, i've opted for the 8N1 asynchronous format. I'll have three pieces of information to send (user, area, and device) although these could just be ascii characters. what format should the data to be sent take? :roll:

Any help would be fantastic, or if anybody knows of some decent (there's a lot of rubbish out there) online tutorials I'd be most grateful.
 
You could send the data directly to the pc, but it depends how error sensitive your application is. If you want some degree of error detection then you could send the data in packets, each packet accompanied by a checksum.

Many ppl use packets in the shape as <STX><...DATA...><Checksum><ETX>

where STX is a start-of-text symbol, wich indicates a packet has begun, then the data is followed and stored until you reach a ETX end packet indicator, Then the checksum is used to check the data received was not corrupted.
Now you have the problem the values of STX and ETX cannot be sent anymore as data. Simplest way is too choose 2 codes for STX and ETX wich you won't use for data. But you could use byte stuffing also.

I'm working on a bootloader wich uses this technique, but the pc side of things is in visual C++ so it wouldn't help you
 
STX etc.

Thanks for the reply.

will the MCU will ignore the first and last bytes using the STX etc? IS this a protocl i set on start up or is it ignored by the code on the MCU? let's say for example i use £ for the start and @ for the end. can i just send these (MSComm) to the MCU directly and with my three bytes of ID data? so it'd look something like:


£ABD@?
 
You''ll have to write code for the pic to send/receive data, this code must include the detection of the packet begin and end indicators and not store them.

Normal practice would be to wait for a STX to arrive before starting to store data. If a second STX arrives before the packet was ended then everything is reset (so the data already received is cleared). When an ETX is received calculate the checksum and process the data if the checksum is correct.

you can simply send the data with MSCOMM, but you'll have to add code to detect errors. In my bootloader i let the pc send a command to the pic (in a packet) and the pic must respond to the pc (also with a packet). If anything goes wrong while receiving i make the pic go back to wait for a new STX, so it will not respond, The pc will then time-out and retry.

You should also keep track of a counter wich counts the number of received bytes to detect receive buffer overflows.
 
Now i realize everybody using similar protocol :p
In VB, it is convenient to define it as string, as in nature, the MSCOMM1 output is in string.
Furthermore, VB is not good in handling binary or hexadecimal.

If you are to use hexadecimal, remember to use the command "CHR()".
HEX() instruction converts the number into STRING in hexadecimal
for instance, 0X2A will be "2" and "A".

I am currently working on similiar thing. COmmunication between PC and microcontroller. Certain error handling should be included, as sometime there might be error in the data. If the progam is not written efficiently, the microcontroller may just halt if there is error in the packet.
 
Hi, I am doing project that use VB6.0 to sent signal to PIC 16F877A via RN41(blueetooth device)

Unfortunery, i meet a problem when i success to connect the bluetooth device to my computer( mena change red LED to Green) I unable to sent any signal or data.

Anyone know any solution please tell me.....
Really thanks for the help.......

in the VB i used

MSComm1.Output = "a"

I think it should be correct right??

If need, i will able to upload my program....Thanks.........
 
Hi, I am doing project that use VB6.0 to sent signal to PIC 16F877A via RN41(blueetooth device)

Unfortunery, i meet a problem when i success to connect the bluetooth device to my computer( mena change red LED to Green) I unable to sent any signal or data.

Anyone know any solution please tell me.....
Really thanks for the help.......

in the VB i used

MSComm1.Output = "a"

I think it should be correct right??

If need, i will able to upload my program....Thanks.........

hi,
Attach your VB program so that we can check the MSCOMM settings.
 
Thanks for reply, i uploading my vb here. It just the simple program i make.

Sorry, the correct one is 1.7kb file size dy.............Thanks
 

Attachments

  • VB program.zip
    2.2 KB · Views: 335
  • VB program.zip
    1.7 KB · Views: 353
Last edited:
hi,
Will download your program and have a look.
 
I am much appreciated for your help..........

After looking thru your program, I can see it will take me a little while to sort out, will reply with a result tomorrow.
I like a challenge.:)
 
hi,
Look at this version of your program.
I have used the binary option for the MsComm1 as you may also want to send control codes to the modem.

The program has been tested by being linked to another PC acting as a modem and it works OK.

I have set the Comport as #2, set it back to #1 for your project.

If you have any questions, please ask...:)
 

Attachments

  • AAesp02.gif
    AAesp02.gif
    5.6 KB · Views: 292
  • ModComm1.zip
    9 KB · Views: 236
  • AAesp03.gif
    AAesp03.gif
    10.7 KB · Views: 295
Last edited:
Sorry, i have a problem when i run the program you give me. The problem is when i run it, it will say method or data member nhot found for ".SelText"

May i know what i should i change it??
 
Sorry, i have a problem when i run the program you give me. The problem is when i run it, it will say method or data member nhot found for ".SelText"

May i know what i should i change it??

hi,
I changed the simple Text box into a Rich Text box, so that print out could be formatted 'better'.

Use the VB menu, Projects/Components and Add the Microsoft Rich Text box control...OK.?

If you cannot do that, use a simple text box and change all the rtb1.selxxx commands to Text1.xxxx, I would recommend the RTBox use.
 
hi,
Have changed the boxes to simple Text.
Its been tested linked to another PC and it works.

Use the modcomm2.vbp within the zip.
 

Attachments

  • ModComm2.zip
    39.5 KB · Views: 258
  • AAesp01.gif
    AAesp01.gif
    6.3 KB · Views: 312
Last edited:
Thanks so much.........I will try it now.......
you mean that this program able to sent out the data ??

hi,
If you want to 'talk' to a modem, you must have two way communication between the modem and the MCU or PC.
When then MCU initially sends the "AT" command to the Modem, it will expect "OK" as a reply.
Usually the MCU then sends 'setup' commands to the modem an awaits the required reply.

After the modem is setup data can be transferred between the MCU and modem and vice versa.

The VB program transmit data string is fixed in the program I posted, but it could easily be edited to enable it to transmit data and commands from the keyboard.

Exactly what are you trying to do.???
 
icic.........

actually my project is transmit a control signal (such as 'K') to microcontroller via bluetooth (RN-41). Then the microcontroller will do somethings ragarding to the control signal.

so it mean that in the program of my PIC, i need to sent feed back also??
cause i meet the same probelm, after i sent the signal, it such as nothings happen.
May i know, what should i do now??change my PIC program??
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top