View previous topic :: View next topic |
Author |
Message |
young
Joined: 24 Jun 2004 Posts: 285
|
How to check out RS232 status? |
Posted: Thu Nov 04, 2004 7:20 am |
|
|
I am developing a program that when I send signal from a PC, the PIC will detect that I sent the signal, and after that the PIC will download the signal from the PC and do something (like writing to EEProm), when there is not signal coming from the PC, the PIC will do something else (like blink the leds) how can I detect if some signal is coming to the PC? |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Thu Nov 04, 2004 8:00 am |
|
|
Depends on what you mean by "signal". Is this RS232 data? Or maybe just one of the handshake lines?
If RS232 data, then look at one of the examples in the examples directory that deal with the uart. |
|
|
young
Joined: 24 Jun 2004 Posts: 285
|
|
Posted: Thu Nov 04, 2004 8:49 am |
|
|
Thank you, I will use #int_rda. Do you think it will affect the sleep mode if I use WDT? |
|
|
young
Joined: 24 Jun 2004 Posts: 285
|
|
Posted: Thu Nov 04, 2004 10:00 am |
|
|
When I try to use #INT_RDA, a compiler error occured, as invalide pre-processor directive. I am using 16f819, when I check the 16f819 header file, there is no such #int_rda, can I use it, if I can it how to define and used it? |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Thu Nov 04, 2004 10:42 am |
|
|
That's cause it ain't got no UART. |
|
|
Guest
|
|
Posted: Thu Nov 04, 2004 1:02 pm |
|
|
I changed microchip with UART to play with, imagin that when data in buffer is ready, there is a int_rda inturrupt to call, in this call you use getch() to read the data, but when does teh microchip know that the transferd has been read completely? int_tbe looking like for transfered data empty? is that when the received data is empty, there will be not int-rda interrupt right? |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Thu Nov 04, 2004 1:15 pm |
|
|
The receive is buffered (I believe 2 bytes plus what is being shifted in). Reading the buffer is immediate. If you get an overflow, then the USART will stop receiving. For every byte that comes in, you will get an int. The transmit int occurs all the time unless the transmit buffer is full. |
|
|
young
Joined: 24 Jun 2004 Posts: 285
|
|
Posted: Mon Nov 08, 2004 1:19 pm |
|
|
I used int_rda to recevie data from RS232, but I could not get it, However I could get the data from main() while loop ? All I added is a getchar() in it and a comparision to chech if the data is correct.
I am using 16f76 which has a hardwire USART. I setup as following.
#use rs232(baud=9600, parity=N, xmit=PIN_B4, rcv=PIN_B5,INVERT)
is that I have to use hardwire RS232 or software, because here i am using INVERT, Hardwire USART does not support INVERT, If I have to use Hardwire USART, I will need to add a RS232 hardwire invert instead of software RS232 INVERT, right. |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Mon Nov 08, 2004 1:25 pm |
|
|
You really need to post an example problem that give you a problem. Too much guessing without it. How do we know that you used the pins? If you are using the "INVERT" parameter then it sounds like you are trying to "cheat" and not use an RS232 transceiver chip. You REALLY should be using one. If you do not have one, then it is no wonder why the hardware uart didn't work since the levels would need to be inverted. Simple thing, get yourself a MAX232 or equivalent. |
|
|
young
Joined: 24 Jun 2004 Posts: 285
|
|
Posted: Mon Nov 08, 2004 1:30 pm |
|
|
I am sorry for that, my project has a very limited space, I am jsut trying to save space. using INVERT is kinds of "cheat", but if I have to use MAX232 in order to use USART, I will do it immediately as you suggested!
Do I have to use MAX232 instead of INVERT to use USART? |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Mon Nov 08, 2004 1:49 pm |
|
|
I am not sure if you understand what a MAX232 is. This is a chip that goes between the PIC microcontroller and the cable that goes to the PC. I would suggest that you always use this chip even when using a software uart (you of course wouldn't use the invert). |
|
|
young
Joined: 24 Jun 2004 Posts: 285
|
|
Posted: Mon Nov 08, 2004 2:26 pm |
|
|
Here is my testing program after using RS232, but still could not getting response (LED blinks). I tried hardwire USART also
Code: | #if defined(__PCM__)
#include <16F76.h>
#fuses XT,WDT,NOPROTECT
//#device ADC=10
#use delay(clock=4000000)
#use rs232(baud=9600, parity=N, xmit=PIN_B4, rcv=PIN_B5)
char status1[30],status;
#int_rda
void RDA_isr()
{
gets(status1);
status=status1[0];
if(satus=='R')
{
output_high(PIN_A2);
delay_ms(300);
output_low(PIN_A2);
delay_ms(300);
}
if(satus=='T')
{
output_high(PIN_A3);
delay_ms(300);
output_low(PIN_A3);
delay_ms(300);
}
}
void main()
{
enable_interrupts(INT_RDA);
enable_interrupts(global);
while(1)
{
}
}
|
|
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Mon Nov 08, 2004 2:35 pm |
|
|
1. satus does not exist in your program
2. The hardware uart is on pins RC6 & RC7
3. If the posted example is for a software uart, there is no int_rda!
4. don't use gets() inside the receive int. Use getc();
5. Never put those huge delays in there. Better to set a flag and handle in main.
6. Better use "ERRORS" in the #use RS232 if using the hardware uart.
7. Look at the uart examples. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Nov 08, 2004 2:40 pm |
|
|
Well Mark, you posted before me. But I'll post mine anyway.
16F76 has a hardware USART on pins C6 and C7.
You're using B4 and B5, which creates a software USART.
There is no #int_rda with a software USART.
It won't work. You must read the data sheet before writing code.
(and before posting).
There are other problems:
This line of your code, right here, uses the 'satus' variable.
if(satus=='R')
But that's obviously a typo. There is no 'satus' variable declared
in your program. Here's where you declare variables:
char status1[30],status;
So this means that you're typing in the program. You're not doing
copy and paste with Ctrl-C and Ctrl-V. So how can we trust that
anything is correct ? We need correct data to solve the problem. |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Mon Nov 08, 2004 2:42 pm |
|
|
and I still have no idea whether or not he knows what a MAX232 and if he is using one! |
|
|
|