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

USART fgets() not working

 
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

USART fgets() not working
PostPosted: Thu Jul 24, 2008 11:28 pm     Reply with quote

Hi all.

I'm trying to communicate 2 pics but it's not working...

With a single char, everything works....but not for a string.
This is my code:

display PIC:
Code:

  char temp[50];

   while (TRUE)
   {
      n++;
      fgets(temp,rs1);
      printf(lcd_putc,"%s %d",temp,n);
   }


proc. PIC:
Code:

   while (1) {
     
      output_toggle(PIN_B7);     
      fprintf(rs1,"Jonis %d\n\r",n);
      delay_ms(1000);
      n++;
 
   }


i already tried to use \0 after %d but still not working. What's wrong?
I need to pass a full string from PIC A to PIC B and fgets would be perfect for my needs.
Ttelmah
Guest







PostPosted: Fri Jul 25, 2008 5:15 am     Reply with quote

First, I'd suggest you pull the code for 'get_string', in input.c, and modify this to use your required stream. Gets, is a 'dangerous' function, since if the carriage return doesn't arrive, the data _will_ overflow the buffer, damage other variables, and lead to program failure...
The code in input.c, is simple to copy, and produce your own version using the named stream.
Now, you say 'usart'. Are you actually using the hardware USART, or a software UART?. Have you got the 'errors' statement in your RS232 definition?. What is your baud rate?. What is actually happening (is B7 toggling)?.

Best Wishes
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

PostPosted: Fri Jul 25, 2008 9:32 am     Reply with quote

Ttelmah wrote:
First, I'd suggest you pull the code for 'get_string', in input.c, and modify this to use your required stream. Gets, is a 'dangerous' function, since if the carriage return doesn't arrive, the data _will_ overflow the buffer, damage other variables, and lead to program failure...
The code in input.c, is simple to copy, and produce your own version using the named stream.
Now, you say 'usart'. Are you actually using the hardware USART, or a software UART?. Have you got the 'errors' statement in your RS232 definition?. What is your baud rate?. What is actually happening (is B7 toggling)?.

Best Wishes


I'm using hardware USART on both 628A and 4550 in Isis (proteus) Simulator. Using 'putc()' and 'kbhit()' or 'getc()' everything works fine! The problem is with fgets().

Let me explain...I have a project for my car. With an 18F4550, i can read almost all sensors from my car and steering well buttons. Since my original tape doesn't have CD, i changed from a pioneer CD player....so my steering well doesn't work anymore. With my project, i'll read, know and send controls from steering well to my new pioneer cd player, which has "Wired Control" connector (and my project still working with all other sensors too). All functions like sensors status are displayed in onboard computer display, which is original from my GM Vectra.

This display uses i2c communication, but with +1 port (3 in total) and some modifications. This modifications uses some delays and theses delays are generating errors while pressing some buttons....i mean, i need to press the buttons for a few ms to work, instead of just push and leave. Because of this and others problems i'll put and 16F628A dedicated to display communication. What i need is to send string from one pic to another and if is possible, is better to get the full string and process instead of char by char on the display control.
The proc. pic (4550) will send a lot of messages to display, but since display has some delays, it will just use the last full valid string.

ex:
A send (every 50ms):
Teste 1
Teste 2
Teste 3
Teste 4
Teste 5

and display control has 100ms delay, so it will use only:
Teste1
Teste3
Teste5



BTW, i'm using 9600 baud. Can i use more with these pics?
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

PostPosted: Fri Jul 25, 2008 11:10 am     Reply with quote

now, i'm trying with simple code but still not working....

on display pic:
Code:

   while(TRUE) {
      c=getc();
      lcd_putc(c);
   }


on master pic:
Code:

   while (1) {
     
      output_toggle(PIN_B7);     

      putc('j');
      putc('o');
      putc('n');
      putc('i');     
      putc('s');
      delay_ms(1000);
      n++;

 
   }


What's wrong? I can see just "jo" on the LCD.
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