|
|
View previous topic :: View next topic |
Author |
Message |
mob1182
Joined: 03 Mar 2016 Posts: 28
|
input.c acting weird, can it not be used for software UART? |
Posted: Thu Jul 28, 2016 5:23 pm |
|
|
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
|
|
Posted: Thu Jul 28, 2016 5:54 pm |
|
|
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
|
|
Posted: Thu Jul 28, 2016 6:10 pm |
|
|
Thanks for the quick response PCM!
I didn't even see the InputPutc(c); 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
|
|
Posted: Thu Jul 28, 2016 6:49 pm |
|
|
Yes, delete that line and it won't echo the char. |
|
|
|
|
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
|