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

Can't receive data from my computer with RS232
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
YulL
Guest







Can't receive data from my computer with RS232
PostPosted: Tue Sep 28, 2004 6:12 am     Reply with quote

Hi, I have a strange problem with my program : I can't receive data when I press any button of my keyboard... Crying or Very sad

Here is my complete source :

#include "C:\...\TEST.h"
#include <stdio.h>
#include <lcd.c>
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7,PARITY=N,BITS=8)

int16 demo;

void main()
{
int8 test;

setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_spi(FALSE);
setup_counters(RTCC_INTERNAL,RTCC_DIV_2);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
set_tris_a (0);
set_tris_c (0xBF); //RC7 Input & RC6 Output

output_low(LED0);
output_low(LED1);
demo=0;

lcd_init();
delay_ms( 20 );
printf(lcd_putc, "\fAIRLINK\n2080\n");
delay_ms( 3000 );
lcd_putc("\f");

printf("Continue (y,n)?");
do { test=getch(); }
while(test!='y');

printf("OK!");
delay_ms( 3000 );
lcd_putc("\f");

while(1)
{
printf(lcd_putc,"\f%ld s",demo);
demo++;
output_low(LED0);
output_low(LED1);
delay_ms( 1000 );
printf(lcd_putc,"\f%ld s",demo);
demo++;
output_low(LED0);
output_high(LED1);
delay_ms( 1000 );
printf(lcd_putc,"\f%ld s",demo);
demo++;
output_high(LED0);
output_low(LED1);
delay_ms( 1000 );
printf(lcd_putc,"\f%ld s",demo);
demo++;
output_high(LED0);
output_high(LED1);
delay_ms( 1000 );
}
}


and test.h :

#include <16F873.h>
#device adc=8
#use delay(clock=11059200)
#fuses HS, NOWDT, NOPROTECT, NOLVP, BROWNOUT, PUT
#define LED0 PIN_A0
#define LED1 PIN_A1


If you experienced that before, please tell me.
Thanks by advance for your precious help.
asmallri



Joined: 12 Aug 2004
Posts: 1634
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Tue Sep 28, 2004 7:14 am     Reply with quote

Quote:
printf("Continue (y,n)?");
do { test=getch(); }
while(test!='y');


This code sits in an endless loop until a lower case y is pressed. Was that your intention?
YulL
Guest







PostPosted: Tue Sep 28, 2004 7:47 am     Reply with quote

Yes, my program send OK to the PC if I push the 'y' key...
asmallri



Joined: 12 Aug 2004
Posts: 1634
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Tue Sep 28, 2004 7:58 am     Reply with quote

I don't understand what your problem is. The main loop of your code does not look for any input from the PC. Similarly it does not send anything to it.
Guest








Re: Can't receive data from my computer with RS232
PostPosted: Tue Sep 28, 2004 8:07 am     Reply with quote

It happens here :

YulL wrote:
printf("Continue (y,n)?");
do { test=getch(); }
while(test!='y');

printf("OK!");
delay_ms( 3000 );
lcd_putc("\f");


It tests if I push the 'y' button of the keyboard. Rolling Eyes
YulL
Guest







PostPosted: Tue Sep 28, 2004 8:38 am     Reply with quote

Ok I've remade my program and replace with this :

printf("Press any key to begin.\n\r");
getc();

The problem is that even if I don't press any button, the program continues and ignore my key...

Embarassed
asmallri



Joined: 12 Aug 2004
Posts: 1634
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Tue Sep 28, 2004 8:57 am     Reply with quote

Do you correctly receive the "Press any key to begin" message on the PC?
YulL
Guest







PostPosted: Tue Sep 28, 2004 9:01 am     Reply with quote

Yes I see that sentence on my screen but the programs keeps going and ignore my key... Crying or Very sad

Thanks for your reply
Ttelmah
Guest







PostPosted: Tue Sep 28, 2004 9:20 am     Reply with quote

YulL wrote:
Yes I see that sentence on my screen but the programs keeps going and ignore my key... Crying or Very sad

Thanks for your reply

The obvious likelyhood, is a wiring error somewhere, that is resulting in the serial input line to the processor being seen as permanantly low. In the code that waits for a 'y', this will then never be seen, and the system will loop for ever, while in the code that waits for any key, there will be an immediate response, and the system will carry on.
As a general comment, add the 'ERRORS' directive to the RS232 line, otherwse if a couple of keys are pressed before the code reaches the wait loop, the UART will have allready overrun, and will hang. This might be the problem (if the PC is set to 'echo' incoming data, the UART will allways be in this state when called...).

Best Wishes
YulL
Guest







PostPosted: Wed Sep 29, 2004 6:00 am     Reply with quote

Yes maybe it is a wiring error but I've checked this and I haven't found any error... Crying or Very sad
dyeatman



Joined: 06 Sep 2003
Posts: 1924
Location: Norman, OK

View user's profile Send private message

Do you have the required inverter in line?
PostPosted: Wed Sep 29, 2004 6:10 am     Reply with quote

How is your connection to the PIC set up? Do you have a MAX232 or similar to invert the signal as it requires?

The PIC is expecting an inverted RS232 signal that would normally be present when an RS232 converter is in the circuit.
YulL
Guest







PostPosted: Wed Sep 29, 2004 6:15 am     Reply with quote

I'm using the MAX232CPE device for the conversion. I've checked the wiring according to the datasheet and samples taken from the web.
YulL
Guest







PostPosted: Wed Sep 29, 2004 6:50 am     Reply with quote

My RC7/RX Pin is always +2V when I don't touch my keyboard.. Is it normal?? Confused
asmallri



Joined: 12 Aug 2004
Posts: 1634
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Wed Sep 29, 2004 9:21 am     Reply with quote

YulL wrote:
My RC7/RX Pin is always +2V when I don't touch my keyboard.. Is it normal?? Confused


When the RS232 interface is idle (in stop condition) the PIC RX input should be +5V (assuming a 5volt system). The Max232 generates + and - voltages for the driver stage (the output to the PC). A capacitor installed the wrong way around will cause problems with the RS232 line voltages however, in your case, this will not be the problem because you can transmit to the PC. Four possibilities come to mind:

1. (not likely) - the RS232 interface on the PC is not idle and is sending characters to the PIC - the alternating highs and lows are therefore being averaged by the meter so a 2 volt value would be realistic. Have you got a logic probe? If so connect it to the Rx input on the PIC.

2. (likely) you have a wiring error with the output of the MAX232 connected to the output of another device. One is driving high while the other is driving low

3. (possible but not evident from your code - compiler bug?) The PIC RX input is actually configured as an output and this is driving low while the MAX is driving high

4. (possible) Your MAX232 chip is faulty.

If all else fails - buy an ICD or a mini Bitscope (or whatever it is called at www.bitscope.com) and see what is happening
YulL



Joined: 29 Sep 2004
Posts: 39
Location: Paris (France)

View user's profile Send private message

PostPosted: Wed Sep 29, 2004 9:36 am     Reply with quote

Hi, Thanks for your support.
Cool

asmallri wrote:
1. (not likely) - the RS232 interface on the PC is not idle and is sending characters to the PIC - the alternating highs and lows are therefore being averaged by the meter so a 2 volt value would be realistic. Have you got a logic probe? If so connect it to the Rx input on the PIC.


I have put my oscilloscope probe to the RC7 Pin and the signal is absolutely linear... Rolling Eyes

asmallri wrote:
2. (likely) you have a wiring error with the output of the MAX232 connected to the output of another device. One is driving high while the other is driving low.


It's not the situation here Embarassed

asmallri wrote:
3. (possible but not evident from your code - compiler bug?) The PIC RX input is actually configured as an output and this is driving low while the MAX is driving high.


It is possible but even if I define my PORTC port with :

set_tris_c (0xBF); //RC7 Input & RC6 Output

Arf I'm going to try another max232 in case of... Rolling Eyes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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