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

c=getc(); does not cause program to wait for rs232 input

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







c=getc(); does not cause program to wait for rs232 input
PostPosted: Mon Jun 25, 2007 6:37 pm     Reply with quote

In my code, if I have c = getc(); it does not wait for a character to be received, rather it goes and does the I2C communication. However if I have something like:

c = getc();
printf("hello");
printf("%c",c);

Then it will wait till it receives an input character from the rs232.

Does anyone know why this is?


Code:

#include <16F877A>
#fuses HS,NOWDT,NOPROTECT
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
#use i2c(Master, sda=PIN_C4, scl=PIN_C3, Force_HW)
   
void main()
{
int8 data;
char c;


     
while(1)
{
c = getc();
delay_ms(1000);

// Write the letter to the slave board.
i2c_start();
i2c_write(0xA0);
i2c_write(0x00);
i2c_write('1');
i2c_stop();

// Read from the slave board and display the data.
i2c_start();
i2c_write(0xA0);
i2c_write(0x00);
i2c_start();
i2c_write(0xA1); //last bit = 1 => reading
data = i2c_read(0);
i2c_stop();
printf("read %c \n\r", data);

delay_ms(1000);

}
   
}
PICLearning
Guest







PostPosted: Mon Jun 25, 2007 6:42 pm     Reply with quote

Just figured it out, not sure why this is the case, but once I took out the "Force_HW" from the I2C communication, it did resolve my issue. Anyone know why this is so?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jun 25, 2007 7:21 pm     Reply with quote

Post your compiler version. You can find it at the start of the .LST file,
which is in your project directory. It's a 4-digit number such as 3.191,
4.042, etc.

Also add NOLVP to your #fuses statement, as shown in bold below.
Quote:
#fuses HS,NOWDT,NOPROTECT, NOLVP
PICLearning
Guest







PostPosted: Tue Jun 26, 2007 7:36 am     Reply with quote

CCS PCM C Compiler, Version 4.016, 36498 25-Jun-07 20:37
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jun 26, 2007 2:12 pm     Reply with quote

I installed your version of the compiler and modified the program
slightly, to turn on an LED when it advances past the getc() statement.
I added the line shown in bold below:
Quote:

while(1)
{
c = getc();
output_high(PIN_B0);
delay_ms(1000);

It works OK for me. The LED stays off until I press a key in my
terminal window.

My guess is that you probably have some device attached to your
RS232 port on your PIC that is sending characters continuously,
or maybe sending one char when it's first plugged in. Or maybe
the idle state of the Rx signal coming into the PIC is not a high level.

Are you using a MAX232-type chip ?
PICLearning
Guest







PostPosted: Tue Jun 26, 2007 5:33 pm     Reply with quote

I am using a max232 chip. It just doesn't make sense that when I take off Force_HW it works for me. It isn't critical, but just annoying that there are so many things that can cause issues. Thanks though.
LearningPIC
Guest







PostPosted: Tue Jun 26, 2007 5:36 pm     Reply with quote

As a side question...

I was wondering if it is possible to change the I2C address of a PIC in the main?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jun 26, 2007 8:20 pm     Reply with quote

If you have a late version of the compiler, see this function in the manual:
Quote:
I2C_SlaveAddr( )


If you have an earlier version, you can do it by declaring the address
of the SSPADD register with the #byte directive. Then write directly
to that register with a line of code, to set the new slave address.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Wed Jun 27, 2007 2:06 am     Reply with quote

PICLearning wrote:
It just doesn't make sense that when I take off Force_HW it works for me. It isn't critical, but just annoying that there are so many things that can cause issues. Thanks though.
FORCE_HW in the I2C setup shouldn't have any effect on the RS232 reception, the problem disappearing looks more like masquerading, ie. a side effect is hiding the real issue. Most likely there is a startup issue where the connectected device is generating an edge seen by the PIC as the startbit. Try adding a small delay in the start of your program and clear any pending data:
Code:
delay_ms(100);
while ( kbhit() )  // Clear the UART receive buffer (max. 3 bytes)
  getc();


You are using v4.016, this is a very old alpha version compiler release and known to have many problems. The v4 compilers got more or less useable with the v4.030 release. Save yourself a lot of time and update to the latest release, or revert to v3.249 the last official stable release.

Another tip: Don't use malware.
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