|
|
View previous topic :: View next topic |
Author |
Message |
ericne Guest
|
kbhit() problem with Software UART |
Posted: Sat Apr 18, 2009 4:03 pm |
|
|
I'm trying to make a software UART work that requests data from a server computer through Zigbee wireless comm, and receives it directly afterwards.
I'm on a PIC18F44K20 using version 4.091 of the CCS compiler.
I'm having a problem where kbhit doesn't ever trigger for the received data. I've monitored the pins coming from the Zigbee device and there is no problem there, so I'm wondering if I'm going about this in the wrong manner. Here is a selection of the relevant code from my program:
Code: | #use rs232(baud=9600,parity=N,xmit=PIN_B0,rcv=PIN_B1,bits=8,stream=XB)
#use rs232(baud=9600,parity=N,xmit=PIN_D0,rcv=PIN_D1,bits=8,stream=SIOW)
void main()
{
char tmp_str[40];
unsigned int8 n = 0;
fprintf(SIOW, "Syncing Xbee\n\r");
fprintf(XB,"SYNC");
[b]while(!kbhit(XB));[/b]
do{
tmp_str[n]=fgetc(XB);
n++;
}while(tmp_str[n-1] != '|');
tmp_str[n]='\0';
fprintf(SIOW, "%s\n\r", tmp_str);
fprintf(XB,"OK");
}
|
Both of the UARTS there are software, as the hardware UART is being occupied by another device.
Does anyone have any ideas why this isn't working?
Any ideas for alternate ways of solving this problem?
Thanks in advance for any help. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Apr 18, 2009 9:30 pm |
|
|
What is your oscillator frequency ?
Also, connect that stream to a PC with a MAX232 chip. Modify the code
so it just does a simple getc(), putc() loop (without any arrays).
See if that works. Does it echo chars back to the PC when they are
typed into a terminal window ? |
|
|
ericne Guest
|
|
Posted: Mon Apr 20, 2009 9:02 pm |
|
|
Its 20MHz External Oscillator.
I'm having absolutely know problem communicating to and from the PC. Its just through the external, zigbee which works when sending strings, but not for receiving them.
And it does work when using a simple getc or putc. |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Tue Apr 21, 2009 12:24 am |
|
|
As the most likely reason, the processing time involved with your loop exceeds one bit time.
Code: | do{
tmp_str[n]=fgetc(XB);
n++;
}while(tmp_str[n-1] != '|'); |
As a first step, you may want to code it somewhat more effective. Please consider, that CCS C hasn't the capabilities of a high optimizing compiler, that would be able to remove the double index calculation in your code. You have to tell it explicitely to the compiler.
Code: | do{
data=fgetc(XB);
tmp_str[n]=data;
n++;
}while(data != '|'); |
If it still don't work, it's possibly impossible with software UART.
As an additional remark, the code is obviously unsafe, looping forever and running out of bounds, if the expected characters don't arrive. |
|
|
|
|
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
|