Help with RS232

This is a discussion on Help with RS232 within the C Programming forums, part of the General Programming Boards category; At first, hi everyone I'm just arriving here and I would like your help =) I have: - a PC ...

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    2

    Help with RS232

    At first, hi everyone I'm just arriving here and I would like your help =)

    I have:
    - a PC with Windows XP SP2,
    - Turbo C++,
    - DB9 serial connections,
    - MAX232 transceiver and
    - ADS7824 A/D converter.

    I know that there is a function from some library that allows parallel communication (I think outportb, inportb,...) but, how can I communicate in a serial RS232 interface?

    The thing I want to do is: take an analog signal (range 0V to 5V) and convert it serially to digital with ADS7824, then use its output through a MAX232 to inject this into the COM port of the PC. Ok, my problem is, how can I read in C this data arriving at the COM port, and how can I interpret it (just for example: 8 bits arrived -> 1 byte -> 1 character ASCII -> print it on screen)?

    Anyone can help me with some code lines/libraries? Thanks,

    Everton

  2. #2
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,424
    Switch to more updated compiler to write windows application
    read http://msdn.microsoft.com/en-us/library/ms810467.aspx
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  3. #3
    Registered User
    Join Date
    Mar 2009
    Posts
    2
    thanks vart, so I have to change my compiler...

    Is it necessary to use a windows protocol to communicate? I just want to read the bits arriving (without any kind of start bit, parity bit, etc..) if it arrives a +V level for 'x' seconds I want the C programm save this as '1', and if it arrives a 0V level for 'x' seconds, I want the C program save as '0' (of course, I will work with 12 bits, so it saves the 12 bits arrived sequentially). Suggestions?

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by evverton View Post
    thanks vart, so I have to change my compiler...

    Is it necessary to use a windows protocol to communicate? I just want to read the bits arriving (without any kind of start bit, parity bit, etc..) if it arrives a +V level for 'x' seconds I want the C programm save this as '1', and if it arrives a 0V level for 'x' seconds, I want the C program save as '0' (of course, I will work with 12 bits, so it saves the 12 bits arrived sequentially). Suggestions?
    Doesn't seem very easy. The hardware in a PC is designed to send at most 8 bits of data with a start and a stop bit at either end.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,158
    It would be far easier to do this with a parallel port instead of a serial port, as you can address each bit individually.

    The reason why you shouldn't just bang on the port with IN and OUT instructions is because the OS already provides an abstraction for this and there's no reason not to use it.

    And of course, whenever attaching a home-built circuit to a computer, be careful to ground your circuit to the PC ground (there is a pin on the parallel port for system ground), and placing some zener shunts between the pins and ground is not a bad idea either. You don't want a bug in your circuit to blow up your parallel IO controller or the whole motherboard.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple RS232 Question
    By ricky1981 in forum C++ Programming
    Replies: 11
    Last Post: 06-13-2011, 12:13 PM
  2. RS232 interface, DE2-70 board
    By duffbuster220 in forum C Programming
    Replies: 3
    Last Post: 05-02-2009, 01:22 PM
  3. Read and display signel serial mouse RS232 in C
    By zebres in forum C Programming
    Replies: 1
    Last Post: 03-22-2009, 09:09 AM
  4. rs232 with win api
    By alaturka in forum C Programming
    Replies: 14
    Last Post: 12-27-2005, 09:24 PM
  5. Replies: 5
    Last Post: 11-20-2003, 12:27 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21