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

how to send int16 number to another PIC via RS232

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



Joined: 17 Nov 2011
Posts: 187

View user's profile Send private message Send e-mail

how to send int16 number to another PIC via RS232
PostPosted: Thu Jan 09, 2014 10:24 am     Reply with quote

hello ,
please help how to send 16 bit number from PIC to another PIC
I tried something like this but I know it don't work...

Code:


//TRANSMIT 16 bit long unsigned int number:

//define software UART to pins
#use rs232(STREAM = min_data,baud = 9600, xmit=pin_C4)

//and send it to another PIC

int16 minute_data;

fprintf(minute_data,"%Lu",second_counter);

//receive that int16: there's only one stream in receiver

//XMIT is here for that kbhit() works ... this only receive data
#use rs232(baud = 9600, RCV = pin_D3,XMIT = pin_D2,ERRORS)

   //maybe something like that ... but how ?
   
               char rcv_data;
               int16 bignumber;
               
               while(!kbhit()){
               delay_us(1);
               }
               
               if(kbhit())
               
               //I know there must be some kind of buffer because long int is two bytes long
               //but how??
               char string[3];
               
               bignumber = atol(string);

 


I'll be happy if someone help me

friendly regards
-arto-
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jan 09, 2014 12:47 pm     Reply with quote

There are many threads that discuss this problem. Here are some of them.
They may not be perfect but at least they will give you some ideas:
http://www.ccsinfo.com/forum/viewtopic.php?t=47659
http://www.ccsinfo.com/forum/viewtopic.php?t=42046
http://www.ccsinfo.com/forum/viewtopic.php?t=41592
http://www.ccsinfo.com/forum/viewtopic.php?t=36796
artohautala



Joined: 17 Nov 2011
Posts: 187

View user's profile Send private message Send e-mail

PostPosted: Sun Jan 12, 2014 8:26 am     Reply with quote

PCM programmer wrote:
There are many threads that discuss this problem. Here are some of them.
They may not be perfect but at least they will give you some ideas:
http://www.ccsinfo.com/forum/viewtopic.php?t=47659
http://www.ccsinfo.com/forum/viewtopic.php?t=42046
http://www.ccsinfo.com/forum/viewtopic.php?t=41592
http://www.ccsinfo.com/forum/viewtopic.php?t=36796


ok no success ...

is it ok to send data to another pic like this:

//define software UART to pins
#use rs232(STREAM = sec_data,baud = 9600, xmit=pin_C4)

//and send it to another PIC

int8 second_counter;

fprintf(sec_data,"%u",second_counter);

must there be something carriage return maybe \r when I send unsigned int second_counter ?

I tried to use the examples input.c but no success...

is my transmitter OK ?
and what kind of receiver must be to make things work ?

best regards

-arto-
temtronic



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

View user's profile Send private message

PostPosted: Sun Jan 12, 2014 10:42 am     Reply with quote

code snippets NOT tested but theory should be solid...

xmt...
int16 value;
int8 msb;
int8 lsb;

value=0x1234;
msb=make8(value,1);
lsb=make8(value,0);

putc(msb);
putc(lsb);


rcv...
int16 value;
int8 msb;
int8 lsb;


getc(msb);
getc(lsb);
make16(msb,lsb);


hth
jay
artohautala



Joined: 17 Nov 2011
Posts: 187

View user's profile Send private message Send e-mail

PostPosted: Sun Jan 12, 2014 11:03 am     Reply with quote

temtronic wrote:
code snippets NOT tested but theory should be solid...

xmt...
int16 value;
int8 msb;
int8 lsb;

value=0x1234;
msb=make8(value,1);
lsb=make8(value,0);

putc(msb);
putc(lsb);


rcv...
int16 value;
int8 msb;
int8 lsb;


getc(msb);
getc(lsb);
make16(msb,lsb);


hth
hth


HI !
"temtronic"

I do not understand what means hth ...

but is it so that I can not use printf() function to communicate between
two pics ?

have to use putc() function ?

OK thanks a lot for your good answer I'll give up to use fprintf() !

best regards

-arto-
temtronic



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

View user's profile Send private message

PostPosted: Sun Jan 12, 2014 11:37 am     Reply with quote

hth = hope this helps
putc(x) is the simple ,easy way to do it....

if you press F11 while your project is open, the CCS manual comes up...
locate printf(...) and see how to use it.


cheers
jay
artohautala



Joined: 17 Nov 2011
Posts: 187

View user's profile Send private message Send e-mail

PostPosted: Sun Jan 12, 2014 11:55 am     Reply with quote

temtronic wrote:
hth = hope this helps
putc(x) is the simple ,easy way to do it....

if you press F11 while your project is open, the CCS manual comes up...
locate printf(...) and see how to use it.


cheers
jay


OH YEH thank's a lot

now it works OK !

I printed out that CCS manual long time ago ...

maybe I'm a bit dumbass to think easy way ...

and I'm not good reading any manuals ...

thank's for your good advice and have fun and good winter...

brdgs

-arto-
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