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

input.c acting weird, can it not be used for software UART?

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



Joined: 03 Mar 2016
Posts: 28

View user's profile Send private message

input.c acting weird, can it not be used for software UART?
PostPosted: Thu Jul 28, 2016 5:23 pm     Reply with quote

Hi I am trying to use input.c to read a max number of chars for the user but I am having a problem getting it to work correctly. When I use fgets, everything works fine but when I use get_string I only receive every other char and for some reason it prints an extra output.

CCS PCH C Compiler, Version 5.055

Code:

#include <18F4685.h>
#DEVICE ADC=10;

#FUSES INTRC,NOWDT,NOMCLR,NOCPD,NOBROWNOUT,NOIESO,NOFCMEN,NOLVP,PUT


#use delay(internal=16000000)
#use fast_io(C)

#USE RS232(BAUD=9600, parity=N, XMIT=PIN_C3, RCV=PIN_C4, bits=8, TIMEOUT=10000, STREAM = pc, ERRORS)

#include <string.h>
#include <stdlib.h>

#include "input.c"

char user_string[50];
//=============================================================================

void main()
{
   SET_TRIS_C(0X51); //0101 0001
   delay_ms(500);

   while(true)
   {
      int i;
      for(i=0; i<50; i++)
         user_string[i] = NULL;
      fprintf(pc, "\r\nEnter(fprintf):\r\n");
      fgets(user_string, pc);
      fprintf(pc, "\r\nRCV: %s\r\n", user_string);
   
      for(i=0; i<50; i++)
         user_string[i] = NULL;
      fprintf(pc, "\r\nEnter(input.c):\r\n");
      get_string(user_string, 50);
      fprintf(pc, "\r\nRCV: %s\r\n", user_string);
   }
}


When I enter "abcdefghijklmnop" (without the quotes) in a terminal program(Tera Term), the output I receive is as follows:
Quote:

Enter(fprintf):

RCV: abcdefghijklmnop

Enter(input.c):
acegikmo <-----------where is this coming from?
RCV: acegikmo

As you can see fgets works fine and so does fprintf, so comms are setup correctly. But, get_string has bad results.

Thanks in advance to anyone who can shed some light on this.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jul 28, 2016 5:54 pm     Reply with quote

You're using a soft UART, and get_string() echoes back the typed
character to the terminal. So, the PIC cannot receive every 2nd char
because it's spending that time outputting the previous char to TeraTerm.
A soft UART (of the type that CCS uses) consumes the entire time of the
processor. It can either send or receive. It can't do both at the same
time.
mob1182



Joined: 03 Mar 2016
Posts: 28

View user's profile Send private message

PostPosted: Thu Jul 28, 2016 6:10 pm     Reply with quote

Thanks for the quick response PCM! Very Happy
I didn't even see the InputPutc(c); Crying or Very sad That's what happens when you stare at a monitor for 12 hrs straight.

When I get back to the lab tomorrow I will try it with commenting that line out.
Is it safe to assume this will work?
Of course I would create a copy of the file first as to not modify the original, or just copy what I need.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jul 28, 2016 6:49 pm     Reply with quote

Yes, delete that line and it won't echo the char.
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