View previous topic :: View next topic |
Author |
Message |
YulL Guest
|
Can't receive data from my computer with RS232 |
Posted: Tue Sep 28, 2004 6:12 am |
|
|
Hi, I have a strange problem with my program : I can't receive data when I press any button of my keyboard...
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. |
|
![](templates/subSilver/images/spacer.gif) |
asmallri
Joined: 12 Aug 2004 Posts: 1634 Location: Perth, Australia
|
|
Posted: Tue Sep 28, 2004 7:14 am |
|
|
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? |
|
![](templates/subSilver/images/spacer.gif) |
YulL Guest
|
|
Posted: Tue Sep 28, 2004 7:47 am |
|
|
Yes, my program send OK to the PC if I push the 'y' key... |
|
![](templates/subSilver/images/spacer.gif) |
asmallri
Joined: 12 Aug 2004 Posts: 1634 Location: Perth, Australia
|
|
Posted: Tue Sep 28, 2004 7:58 am |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
Guest
|
Re: Can't receive data from my computer with RS232 |
Posted: Tue Sep 28, 2004 8:07 am |
|
|
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](images/smiles/icon_rolleyes.gif) |
|
![](templates/subSilver/images/spacer.gif) |
YulL Guest
|
|
Posted: Tue Sep 28, 2004 8:38 am |
|
|
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](images/smiles/icon_redface.gif) |
|
![](templates/subSilver/images/spacer.gif) |
asmallri
Joined: 12 Aug 2004 Posts: 1634 Location: Perth, Australia
|
|
Posted: Tue Sep 28, 2004 8:57 am |
|
|
Do you correctly receive the "Press any key to begin" message on the PC? |
|
![](templates/subSilver/images/spacer.gif) |
YulL Guest
|
|
Posted: Tue Sep 28, 2004 9:01 am |
|
|
Yes I see that sentence on my screen but the programs keeps going and ignore my key...
Thanks for your reply |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Tue Sep 28, 2004 9:20 am |
|
|
YulL wrote: | Yes I see that sentence on my screen but the programs keeps going and ignore my key...
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 |
|
![](templates/subSilver/images/spacer.gif) |
YulL Guest
|
|
Posted: Wed Sep 29, 2004 6:00 am |
|
|
Yes maybe it is a wiring error but I've checked this and I haven't found any error... ![Crying or Very sad](images/smiles/icon_cry.gif) |
|
![](templates/subSilver/images/spacer.gif) |
dyeatman
Joined: 06 Sep 2003 Posts: 1924 Location: Norman, OK
|
Do you have the required inverter in line? |
Posted: Wed Sep 29, 2004 6:10 am |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
YulL Guest
|
|
Posted: Wed Sep 29, 2004 6:15 am |
|
|
I'm using the MAX232CPE device for the conversion. I've checked the wiring according to the datasheet and samples taken from the web. |
|
![](templates/subSilver/images/spacer.gif) |
YulL Guest
|
|
Posted: Wed Sep 29, 2004 6:50 am |
|
|
My RC7/RX Pin is always +2V when I don't touch my keyboard.. Is it normal?? ![Confused](images/smiles/icon_confused.gif) |
|
![](templates/subSilver/images/spacer.gif) |
asmallri
Joined: 12 Aug 2004 Posts: 1634 Location: Perth, Australia
|
|
Posted: Wed Sep 29, 2004 9:21 am |
|
|
YulL wrote: | My RC7/RX Pin is always +2V when I don't touch my keyboard.. Is it normal?? ![Confused](images/smiles/icon_confused.gif) |
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 |
|
![](templates/subSilver/images/spacer.gif) |
YulL
Joined: 29 Sep 2004 Posts: 39 Location: Paris (France)
|
|
Posted: Wed Sep 29, 2004 9:36 am |
|
|
Hi, Thanks for your support.
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...
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
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](images/smiles/icon_rolleyes.gif) |
|
![](templates/subSilver/images/spacer.gif) |
|