![]() | ![]() | ![]() |
| | |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
| | LinkBack | Thread Tools | Display Modes |
| | (permalink) |
| 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. | |
| |
| | (permalink) |
| 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 | |
| |
| | (permalink) |
| 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@? | |
| |
| | (permalink) |
| 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. | |
| |
| | (permalink) |
| Thanks for the advice exo, very much appreciated. | |
| |
| | (permalink) |
| 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. | |
| |