serial communication

This is a discussion on serial communication within the C Programming forums, part of the General Programming Boards category; Hi guys I have a problem using serialcommunication. I have a atmel 32A chip, I use to controll temperature and ...

  1. #1
    Registered User
    Join Date
    Feb 2011
    Location
    Oslo, Norway
    Posts
    5

    Cool serial communication

    Hi guys
    I have a problem using serialcommunication.

    I have a atmel 32A chip, I use to controll temperature and light in my home.
    I wanna make a win software controlling the system.

    Then I need to learn more of serialcommunication. Since I have several different input sensors and output signals, I need to send the address with the value I want to send with the serial print.

    How could I do this?

    One example:
    In my living room, I need comfort. So I want to have 22īc. So I put in my compuret form 22īc.
    Then the computer sends the data to the chip. The chip reads the data, and handles it as it should. The chip reads from sensor itīs 19īc, so it needs more heat. Then the chip sends 5v to a relay controlling the power to the electrical heater.
    When its 22īc, the chip stops the relay.

    How could I send the serial data?
    I cant use HEX or BIN. I think i need to send in CHAR.
    Or?

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,590
    Why don't you send it as a text string?

    String to int conversion is trivial enough to do at either end, but it sure makes for much easier testing (you can see exactly what you asked for).

    For one thing, you can make sure everything works from just hyperterminal.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User ledow's Avatar
    Join Date
    Dec 2011
    Posts
    435
    I have to agree:

    If the problem is too tricky, make the problem easier. If you don't know how to send a char and you control BOTH sides of the communications, make the communications simpler. Hell, even SMTP starts off with a text HELO command when it could just specify "send a FFh-byte to initiate communication".

    If you want to send byte-wise then, yes, you could use char as the storage (char is guaranteed to be only one byte wide). If you can get a file-pointer to the serial device (e.g. under Linux, /dev/ttyS0 or similar), then you can literally just open that for writing like a file and fputs() to it with a load of char's (be careful of using fprintf which might send out extraneous zero-bytes on the end of your string). If you can't get a file pointer to your serial device, I advise you to find a way to get one - and that's outside the scope of C and into the scope of "finding a suitable platform library".

    - Compiler warnings are like "Bridge Out Ahead" warnings. DON'T just ignore them.
    - A compiler error is something SO stupid that the compiler genuinely can't carry on with its job. A compiler warning is the compiler saying "Well, that's bloody stupid but if you WANT to ignore me..." and carrying on.
    - The best debugging tool in the world is a bunch of printf()'s for everything important around the bits you think might be wrong.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Serial communication
    By chico1st in forum C Programming
    Replies: 8
    Last Post: 09-10-2008, 02:01 PM
  2. Serial Communication in C++
    By NewGuy100 in forum C++ Programming
    Replies: 8
    Last Post: 04-24-2006, 01:56 PM
  3. Serial Communication
    By Korn1699 in forum C# Programming
    Replies: 0
    Last Post: 11-29-2005, 11:50 AM
  4. C Serial Communication BCD
    By ZoomCities in forum C Programming
    Replies: 1
    Last Post: 10-13-2005, 07:00 PM
  5. Need some help with Serial Communication
    By vsriharsha in forum C Programming
    Replies: 1
    Last Post: 02-25-2002, 08:11 AM

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