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 support@ccsinfo.com

RS232 – Sending/Receiving multiple characters

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



Joined: 08 May 2013
Posts: 233

View user's profile Send private message

RS232 – Sending/Receiving multiple characters
PostPosted: Tue Jul 28, 2015 8:20 am     Reply with quote

I send 3 integers via RS232 using PIC10F322.
I receive them in PIC18F4550 using EUSART.
The baud rate is 2400. I display them on a gLCD.
The code works.

My question is how do you do it more simple than that?

What I do is I send in fact 6 integers: 3 with data and 3 integers (1, 2 and 3) for each real data.
They are sent continuously in a loop. I need to know which is the first data, second and third. To identify the data position I sent also the integer 1 for first data, 2 for second and 3 for 3 third.
The problem is that I cannot send data with integers 1 or 2 or 3 because is confused with identifiers.
How do you make the code simpler without identifiers associated with data stream in order to know exactly which data is?

And later I would like to extend to 4 or more data. Then instead of integers I would like to try float numbers and later strings with a known length in bytes. Then the situation changes for my code again.

One idea was for example at the sender to convert the data in string, concatenate in one string with known length in bytes and at receiver side to read the data as string and break it again in 1 byte strings which will be converted in integers or floats depending what was sent.
Any other more simpler ideas?

Here is the code for sender:
Code:
#include <10F322.h>
#use delay(internal=16000000)
#use rs232(baud=2400, xmit=PIN_A2)

void main(){

setup_adc_ports(NO_ANALOGS);

while(TRUE){
   delay_ms(100);
   putc(1);       //identifier for the 1st data integer
   delay_ms(15);  //15ms delay between 2 sending to allow sync by receiver side
   putc(10);      //1st data integer
   delay_ms(15);
   putc(2);       //identifier for the 2nd data integer
   delay_ms(15);
   putc(11);      //2nd data integer
   delay_ms(15);
   putc(3);       //identifier for the 3rd data integer
   delay_ms(15);
   putc(22);      ////3rd data integer
}
}
temtronic



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

View user's profile Send private message

PostPosted: Tue Jul 28, 2015 12:03 pm     Reply with quote

You need to research both 'packets' and 'parsing'.

Packets refers to a group of data being sent or received. You might look at the Xbee modules to see how they do it. Generally you compose and send the following of only one transmitter to one receiver.

start of packet byte
qty of data byte
actual data bytes
end of packet byte.


The start of packet and end of packet bytes need to be unique and NOT to be confused with actual data. qty of data byte,1 - 255, should be more than enough for you. Actual data bytes, format depends on you.

There are hundreds of 'packet' formats,most will include a 'checksum' to validate the actual data. I'd keep it simple to start with though.


Parsing is the subroutine that 'decodes' the incoming data. It breaks down the various bytes into a known 'format'. You can search this forum for threads that deal with GPS to see how some programmers do it. Again, there are countless ways to do it BUT you should (must) use an ISR to acquire the data and a 'buffer' to store the incoming data . CCS does provide an example ( ex_sisr.c) in the examples folder.

So do some research, start small, test and build upon what you do.

Jay
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