CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

sending int or float values from RS232

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Ismail



Joined: 15 Mar 2012
Posts: 6

View user's profile Send private message

sending int or float values from RS232
PostPosted: Tue May 08, 2012 9:47 am     Reply with quote

Hi everyone, plz I wanna send a int or float values from RS232 to a modulator "modem" of siemens (not GSM modem but modulator) and I find just "putc" or "puts" for string.
iit'll be so kinf of u if u help me
temtronic



Joined: 01 Jul 2010
Posts: 9244
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue May 08, 2012 9:53 am     Reply with quote

CCS kindly supplies lots of good, working code in the examples folder....it'd be a GREAT place to start !!!

Also, pressing F11 while working on your project will open the onscreen HELP files, again TONS of great info, right at your fingertips !!
Ismail



Joined: 15 Mar 2012
Posts: 6

View user's profile Send private message

PostPosted: Tue May 08, 2012 10:11 am     Reply with quote

thx but I've already done this and I find just get_float() but for put; I didnt find anything
jgschmidt



Joined: 03 Dec 2008
Posts: 184
Location: Gresham, OR USA

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Tue May 08, 2012 11:00 am     Reply with quote

Have you tried printf() ?
Douglas Kennedy



Joined: 07 Sep 2003
Posts: 755
Location: Florida

View user's profile Send private message AIM Address

PostPosted: Tue May 08, 2012 11:02 am     Reply with quote

If you want your float to be seen as a decimal (base ten) value that can be read by a person look at printf. If you want a 4 byte base 2 normalized notation just send the 4 bytes one byte at a time directly from the 4 memory locations containing the normalized mantissa and the exponent.
Ismail



Joined: 15 Mar 2012
Posts: 6

View user's profile Send private message

PostPosted: Tue May 08, 2012 11:46 am     Reply with quote

I can't use printf because I don't want to see data values on hyperterminal.
I want to communicate between two pic using two modems (modulator & demodulator); so I should send data to a modulator (modem) and receive it back by demodulator.
Ttelmah



Joined: 11 Mar 2010
Posts: 19541

View user's profile Send private message

PostPosted: Tue May 08, 2012 2:10 pm     Reply with quote

Printf, has nothing to do with hyperterminal. It just converts internal values into an output form. You can send (for example), a floating point number, as 8 hex digits representing the 4 bytes stored, using this, just as easily as sending it in decimal.
Let's put it this way, printf, is what is used in 99.9% of PIC applications to send data out the RS232, talking to modems, other PIC's, robots, etc. etc.. The only time hyperterminal comes into use, is as a slightly 'useful' way of looking at what is sent. It is rarely what is actually going to receive the data....

Best Wishes
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Tue May 08, 2012 2:12 pm     Reply with quote

If you want to send the floats as ASCII use printf(). If you want to send the floats as binary use something like make8() and putc(). In either case they will be turned into a stream of 1's and 0's that you can put through your modulator & demodulator.
_________________
The search for better is endless. Instead simply find very good and get the job done.
RF_Developer



Joined: 07 Feb 2011
Posts: 839

View user's profile Send private message

PostPosted: Wed May 09, 2012 7:19 am     Reply with quote

Sending stuff from A to B. Sounds simple, but it is not.

The UARTs send and receive bytes. They can be set to send 7, 8 or 9 bits of data, most people use them to send bytes. That means int8s, ints, signed or unsigned, or chars in CCS C. Since the early 1960s the commonest code for representing characters has been ASCII, which codes characters in seven bits. Other codes exist, IBM, for historical reasons related to punched cards, had, and still has their own family of codes, EBCDIC, to code characters into eight bits. These codes are so commonly used, and are so familar that many people think all serial communications use characters, coded in ASCII, but its not true. The 256 possible variations of 8 bits can mean anything you want.

The simplest thing to send in CCS C is int - each eight bit byte, or "character" representing an integer from 0 to 255.

To send larger integers needs more bytes. This makes for some problems. If you want to send an unsigned int16 you have to send at least two bytes. The problems include: which byte do you send first? What happens if the sender and receiver get out of synchronisation; how do we decide which byte is which? The order of bytes, least significant of most significant first is an example of endianness, and there is a convention that communications links by default are little-endian, meaning the least significant byte goes first. That means very little, of course, if the two ends can't agree on where a pair of bytes begins and ends.

Sending floating point values is a big problem. Mainly as both ends of the link must agree of the binary format of floating point numbers. This varies from processor to processor and from compiler to compiler. CCS C uses a different format of floating point numbers to that used on Microchip's C! Both are different to the commonest standard, IEEE754, which is used by PCs.

That is what's known as sending data "unformatted", or in raw binary. Generally a bad way to go. Formatting the data in some way is a good thing. That means converting the raw binary into some other format that is easier to deal with, but which needs more bytes on the transmission link.

The oldest form of formatting was to convert the data into ASCII in some way. Generally that meant making it readable by humans. So to send the integer "100", you don't send one byte: the binary value 100, instead you send the ASCII characters '1', '0', '0'. Great! printf() does that for you which is great. BUT there's still the problem of synchronisation. If the transmitting end is sending "100100100100100", is that "001", or "010", or "100" over and over? The way to get round that is to send some non-numeric character before and after the data, so that the receiving end can know where one number stops and the next one starts. Even just putting a character between numbers is a good thing, say ',', so that to send 100 continuously you send, "100,100,100,100" and so on.

That evolved into the idea of packets of data: formatted sequences of characters whish contained additional data as well as the actual data being transmitted. Something like STX (start of text - an ASCII "control" character), number of data bytes in binary, data bytes - can be anything you like, but you must send the number of bytes you said you would, CRC (a checking byte, or bytes), ETX (End of text control character). There are many variants on this general theme, but essentially all modern comms traffic uses something based on this. All networks use this sort of packet in some form or other. This message is sent on the Internet by something evolved from this. Many comms links, mainly those which evolved out of synchronous transmission methods, rather than RS232's asynchronous method, are defined in terms of bit-streams rather than characters, but there's not much in it wither way.

Personally I'll always send in some packet formatted way between devices that I'm programming. It allows my code to know when something goes wrong, and there are no synchronisation issues.

So, what is it that you want to send? What problems are you trying to solve? Is it important the data gets through reliably?

RF Developer
Ismail



Joined: 15 Mar 2012
Posts: 6

View user's profile Send private message

PostPosted: Sat May 12, 2012 10:46 am     Reply with quote

thank u all, I used printf() to send data but I wanna know how can I do to check that works very well in ISIS (PROTEUS); i.e. how can I cammunicate between two electronic boards in ISIS
dyeatman



Joined: 06 Sep 2003
Posts: 1934
Location: Norman, OK

View user's profile Send private message

PostPosted: Sat May 12, 2012 11:07 am     Reply with quote

How many times do we have to keep saying this is a CCS User forum and
that we DO NOT do Proteus here! If you have Proteus questions please use
their forum!
_________________
Google and Forum Search are some of your best tools!!!!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group