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

kbhit() problem with Software UART

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







kbhit() problem with Software UART
PostPosted: Sat Apr 18, 2009 4:03 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Apr 18, 2009 9:30 pm     Reply with quote

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







PostPosted: Mon Apr 20, 2009 9:02 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Apr 21, 2009 12:24 am     Reply with quote

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.
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