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

Help with serial communication

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



Joined: 29 Mar 2008
Posts: 26
Location: Ribeirão Preto, SP, Brasil

View user's profile Send private message Visit poster's website ICQ Number

Help with serial communication
PostPosted: Wed Oct 08, 2008 8:38 pm     Reply with quote

Hi all.

I need some help with serial communication. I'm using serial do communicate 2 PIC's (A=16F628 and B=18F4550). Ok, I can send and receive data.
The 628 is just a 'video board' while 4550 is the main processor.

The thing is: 628 receive data from serial and send to my car displays.
The problem: I need to send data as soon as possible (every 1ms is is possible).
If I put a 'while' in my pic and always send data to my car display, everything works fine...
The problem: I need to get data from 4550 and send to car's display.

In the main while of 628 I have something like this:
Code:

while(1) {
  if (pin5==1) { // Main processor is on
       
       gets(temp); // I need a full string not a single char
       Display(temp);

  } else {
      Display("Main processor of");
  }
}


The problem is: if I delay to send the text (500ms for example), my main loop will break until serial data is received....and I can't do that! I need to always send data to my car.
I tried to use "if (kbhit()) then gets(temp)", but I'm getting a lot of garbage data. Why?
I'm sending strings with
Code:
void Manda(char *text) {   
   fprintf(rs1,"%s\r",text);
   return;
}


With only gets() everything works, but main loop wait until data received...
I also tried to use "timed out getc" from examples, but didn't work (program still waiting).


Any help?? Tks!
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Thu Oct 09, 2008 12:45 am     Reply with quote

Hello,

if you think about, you'll see, that it can't work this way.

If you're not able to await the reception of a complete string (you aren't), then you can only receive single characters to a buffer. If the lineend is detected, the buffered data can be processed. If time consuming actions are intended concurrent to the character reception, it's best to perform the receive in an interrupt function. The processing of incoming data should be done in the main loop.

Regards,
Frank
Guest








PostPosted: Thu Oct 09, 2008 10:52 am     Reply with quote

ok, let's see if i'm right with this new idea (about what you said):
In the main loop, i'll always output to my car's display the content of var 'text'.

Then, i use an interrupt called when a char is received. If char != 13 (\r), then i just concat to var 'text_temp'. When i got char 13, then i transfer 'text_temp' to 'text' so the new text is displayed on the car's display.

That's it?
I didn't remember about interrupts to receive chars...thks! i'll try this.
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