I'm having a bit of a nightmare doing serial port communication between a computer and a 16f84. The pic is sending data at 19200 baud to the computer. I have been using a c program based on craig peacock's at http://www.beyondlogic.org/serial/termpoll.c . But unfortunately I am losing significant amounts of data. I think this is because the code needs to be interrupt driven but I can't get the interrupt driven version (http://www.beyondlogic.org/serial/buff1024.c )to work... My compiler does not like the weird pointer-to-function or whatever it is stuff going on with the interrupt function and I cant get my head around what its supposed to be doing either... I'm using microsoft visual c++ 5.0 and have already had to make several adjustments such as changing all the inportb()s to _inp()s... does anyone know what I need to do to make this work, or does anyone have any simple to understand and working microsoft visual c++ 5.0 code for doing interrupt driven serial comms?? I know this is slightly off topic but I am at my wits end!!
SW
Unfortunately I think your probably attacking this from the wrong way if
you're running this under Windows 95/99/ME/NT/2000 (Win32). Code the
directly access registers and interrupts is doomed to fail.
Basically Windows protects direct access to interrupts and IO ports so that
multiple programs will play together nicely. You need to use the windows
provided serial functions.
Look at the SetCommState() function to setup the serial port, CreateFile()
to open a serial port (Name is "COM1" or something like that from memory).
VC++ should have help on these.. if not look on http://msdn.microsoft.com.
You then use WriteFile() and ReadFile() to send and read data, and you can
configure "Event" (kind of like interrupts) using SetCommMask(). You may be
able to find examples in the MSDN site for all this stuff.
The event driven stuff is tricky to get your head around in windows if you
haven't played with it before.
If you don't need to know EXACTLY when a new character arrives, or the state
of the CTS/DSR lines etc change, then it is not too difficult.
You can open the serial port with CreateFile("COM1", .....), use
GetCommState() to retrieve the current settings (speed etc) and
SetCommState() to alter them to be what you need, then you can sit in a loop
using ReadFile() to read incoming data. If you need to send data to the
device, use WriteFile(). Then CloseHandle() when your finished.
If you're writing a WIN application, you probably want to look at
CreateFile, ReadFile() and WriteFile() instead of _inp(). VC++ has
documentation on these. Contrary to what it says, you do not need to write a
threaded application; i wrote a serial port programmer for an ADuC812 using
these functions and polling at 9600 baud. I can send you code snippets for
opening the file, reading, and writing if you want. That will give you
something to base your stuff on.
Reply To: "Simon Redwood" <.....spredwoodKILLspam@spam@sri-net.demon.co.uk>
X-Mailer: ELM [version 2.4ME+ PL60 (25)]
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
I too am having a bit of an nightmare trying to use the seral and paralle
ports for a programmer under Windows.
Dos/Unix works great, but Win9x is a real mare.
If you could possibly also send me those snippets, I would be most grateful.
Thanks in advance,
Simon
> If you're writing a WIN application, you probably want to look at
> CreateFile, ReadFile() and WriteFile() instead of _inp(). VC++ has
> documentation on these. Contrary to what it says, you do not need to write a
> threaded application; i wrote a serial port programmer for an ADuC812 using
> these functions and polling at 9600 baud. I can send you code snippets for
> opening the file, reading, and writing if you want. That will give you
> something to base your stuff on.
>
>
> > {Original Message removed}
I've responded privately to code requests to avoid attachments. Anyone think
this should be in some sort of FAQ? Plenty of stuff for DOS, but little for
windows that I have seen. Is there something out there already, or is there
a need to create it?
I have tried this myself with VC++ and found it a bit of a nightmare. In the end I opted for using VB ver 6, with the module MSCOMM. There are some very good examples. You could use one of the ONCOMM events to detect for a TX.
I managed to write my modest program in about 4 hrs after reading this. Some of the documentation is a bit hard to find but it its there. http://support.microsoft.com/support/kb/articles/Q262/8/83.ASP
Regards
Gary
sam woolf wrote:
> I'm having a bit of a nightmare doing serial port communication between a computer and a 16f84. The pic is sending data at 19200 baud to the computer. I have been using a c program based on craig peacock's at http://www.beyondlogic.org/serial/termpoll.c . But unfortunately I am losing significant amounts of data. I think this is because the code needs to be interrupt driven but I can't get the interrupt driven version (http://www.beyondlogic.org/serial/buff1024.c )to work... My compiler does not like the weird pointer-to-function or whatever it is stuff going on with the interrupt function and I cant get my head around what its supposed to be doing either... I'm using microsoft visual c++ 5.0 and have already had to make several adjustments such as changing all the inportb()s to _inp()s... does anyone know what I need to do to make this work, or does anyone have any simple to understand and working microsoft visual c++ 5.0 code for doing interrupt driven serial comms?? I know this is slightly off topic but I am at my wits end!!
> SW
>
> --
> http://www.piclist.com hint: To leave the PICList
> piclist-unsubscribe-requestKILLspammitvma.mit.edu
--
Information in this communication and any attachments are confidential,
and may not be copied or used by anyone other than the addressee, nor
disclosed to any third party without our permission. If you have received
this communication in error, please notify the sender immediately and then
destroy any copies of it. There is no intention to create any legally
binding contract or other commitment through the use of this email.
-- http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads
I use an ActiveX control to do serial comm on VC++6. This control is
called CommX and is from GreenLeaf Software. It basically does the
hardware handling on the PC and gives You methods, properties and
events instead.
which is a MFC class to wrap access to the Win32 APIs dealing with
serial ports. I havn't tried this myself, though.
I have also been told that in the free software section at http://www.taltech.com there should be a C/C++ code example of a terminal
program. Have not checked this myself either.
> I'm having a bit of a nightmare doing serial port communication
> between a computer and a 16f84. The pic is sending data at 19200
baud
> to the computer. I have been using a c program based on craig
> peacock's at http://www.beyondlogic.org/serial/termpoll.c . But
unfortunately
> I am losing significant amounts of data. I think this is because the
> code needs to be interrupt driven but I can't get the interrupt
driven
> version (http://www.beyondlogic.org/serial/buff1024.c )to work... My
compiler
> does not like the weird pointer-to-function or whatever it is stuff
> going on with the interrupt function and I cant get my head around
> what its supposed to be doing either... I'm using microsoft visual
c++
> 5.0 and have already had to make several adjustments such as
changing
> all the inportb()s to _inp()s... does anyone know what I need to do
to {Quote hidden}
> make this work, or does anyone have any simple to understand and
> working microsoft visual c++ 5.0 code for doing interrupt driven
> serial comms?? I know this is slightly off topic but I am at my wits
> end!! SW
>
> --
> http://www.piclist.com hint: To leave the PICList
> @spam@piclist-unsubscribe-requestKILLspammitvma.mit.edu
>
==============================
Ruben Jvnsson
AB Liros Elektronik
Box 9124, 200 39 Malmv, Sweden
TEL INT +46 40142078
FAX INT +46 40947388 KILLspamrubenKILLspampp.sbbs.se
==============================
-- http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads