View previous topic :: View next topic |
Author |
Message |
murtis
Joined: 12 Aug 2007 Posts: 41
|
Can you help me about #use rs232 |
Posted: Sat Sep 08, 2007 3:41 am |
|
|
Hi,
I am using PIC18F4620 and ccs PCWH. I want to send some data from PIC18F4620 to PC via RS232. But, i have some problem. The problem is that data comes to PC one or two times. After that there is no data. I am confused. What is the problem_?
#fuses XT, NOWDT, NOPROTECT, NOBROWNOUT, NOPUT, NOLVP, NOWRT
#use delay(clock=4000000)
#use rs232(BAUD=2400, rcv=PIN_C7, xmit=PIN_C6, parity=N, bits=8,errors,force_sw)
.
.
BYTE a1[3];
.
.
while(TRUE)
{
putchar('u');
putchar('a');
puts(a1[0]);
puts(a1[1]);
puts(a1[2]);
.
.
.
}
Also,i have a visual basic code for watching the data coming from the PIC18F4620.(MSCOMM32.ocx) What is the solution_?
Could you help me about this event_?
Thanks, _________________ MurtiS |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Sep 08, 2007 3:52 am |
|
|
puts() expects a string. You're not giving it a string. A string consists
of one or more ASCII characters with it has a 0x00 byte at end.
The 0x00 byte marks the end of the string.
Example of how to use puts():
Code: | #include <16F877.h>
#fuses HS,NOWDT,PUT,BROWNOUT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
//==============================
void main()
{
char buffer[] = {"Hello World\n\r"};
puts(buffer);
while(1);
} |
|
|
|
murtis
Joined: 12 Aug 2007 Posts: 41
|
Solution_? |
Posted: Sun Sep 09, 2007 4:45 am |
|
|
i know that
Quote: |
puts() expects a string. You're not giving it a string. A string consists
of one or more ASCII characters with it has a 0x00 byte at end.
The 0x00 byte marks the end of the string. |
but only i can see the characters coming from the PIC to PC. i do not understand the solution. What is the solution_?
Thank you very much PCM Programmer for your opinion, try to send data from PIC to PC _________________ MurtiS |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Sun Sep 09, 2007 7:28 am |
|
|
If you already knew this, than don't post code that contains errors. With puts() you are sending a string, i.e. up to the first 0x00 character. With your code this is undefined so the PIC will send some garbage to the PC. If this garbage contains an XOFF symbol or other control character that would explain why the PC stops receiving.
Just curious: why have you specified the FORCE_SW option? You are already using the pins for the hardware UART, so why waste resources on a software based UART?
Also, the ERRORS option doesn't work for a software UART. |
|
|
murtis
Joined: 12 Aug 2007 Posts: 41
|
|
Posted: Mon Sep 10, 2007 12:34 am |
|
|
Firstly, i wrote the code for uart before now. This code works other application. but i try to write the code like this. But it does not work, and i am confused. So, i tried to write other code types for uart communications. Only with puts(byte aa[i]); there is a communications between pc and PIC. _________________ MurtiS |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Mon Sep 10, 2007 1:48 am |
|
|
There are no known problems with the UART software, so there must be something different in your situation.
What is your compiler version? It looks like 3.249 or 4.055.
Have you tried the example code from PCM Programmer? And is this working?
Does the problem go away if you use Hyperterm (or another tool) instead of the mscomm control?
Post a small (max. 15 lines) and complete program that is showing your problem. Complete means, including #fuses statements, etc. so we can copy paste the code into our compiler. |
|
|
arunb
Joined: 08 Sep 2003 Posts: 492 Location: India
|
RE: |
Posted: Mon Sep 10, 2007 2:28 am |
|
|
Use hyperterminal to test send and receive functions from the PIC and PC, after you have done this use the MSCOMM32.ocx control to access the PIC.
thanks
arunb |
|
|
murtis
Joined: 12 Aug 2007 Posts: 41
|
My problem goes on |
Posted: Mon Sep 10, 2007 5:42 am |
|
|
I tried to send data from the PIC to PC like PCM PROGRAMMER said. But the data came three times from PIC...
Also, i tried to send data PIC to hyperterminal. But the data came four times from PIC to PC. I have a problem but it does not known by anybody and me. it is strange.
Had someone this problem_?
And thank you, my friends that try to help me... _________________ MurtiS |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Mon Sep 10, 2007 5:56 am |
|
|
Again:
- Post your compiler version
- Post the small program you are using to send data to the PC. (max 15 lines of code and make sure it is complete, including #fuses line).
Many things can be wrong and if you post your example program it will be much quicker than us asking all the things that can be possibly wrong. |
|
|
murtis
Joined: 12 Aug 2007 Posts: 41
|
|
Posted: Mon Sep 10, 2007 6:10 am |
|
|
Hi ckielstra,
the small program is working thank you
i could not send my program because it is very long... What is my problem_? _________________ MurtiS |
|
|
murtis
Joined: 12 Aug 2007 Posts: 41
|
i found my problem, how can i solve this problem_? |
Posted: Mon Sep 10, 2007 7:06 am |
|
|
The problem is timeout. how i can solve this problem_?
if there is a timeout, PC close the RS232...
???? _________________ MurtiS |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Mon Sep 10, 2007 7:41 am |
|
|
Quote: | the small program is working Smile thank you | I'm glad to hear the small program is working now. In all the other posts you said you couldn't get any program to work. What did you change?
If the small program is working and the large one doesn't, you made an error in the large program. What error? I don't know. I'm good in programming but very bad in mind reading.
Try comparing the small and large program.
Make the large program smaller until it starts working.
Just a wild guess:
- Make sure you have disabled the watchdog timer (#fuse NOWDT)
- Try disabling all interrupts.
Again (3rd and last time):
- Post your compiler version. It might be a known bug. |
|
|
murtis
Joined: 12 Aug 2007 Posts: 41
|
|
Posted: Mon Sep 10, 2007 8:08 am |
|
|
compiler version is 4.042 and there is no different between large and small program. i think that i am good in programming but sometimes, something is going bad.
i am testing something via PIC and after that PIC sends the result of testing. i think that timeout is appearing on RS232.
My large program is 4000 lines in word. Namely, 160 MS word pages. All lines is working very well but only i have timeout problem a little bit.
#fuses NOWDT and disabled all interrupts
Thank you, ckielstra _________________ MurtiS |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Mon Sep 10, 2007 9:10 am |
|
|
Quote: | i think that i am good in programming but sometimes, something is going bad. | Sounds very familiar, this happens to me also quiet often.
Compiler v4.042 is a reasonable good version. You might try if a newer version like v4.055 improves things.
If the small program is working and the large program is not than it is very difficult to help you. Your hardware seems ok. We checked the watchdog and interrupts. No more quick answers I can think of. The only advice I can give you is to really start debugging. Try to make your program smaller by removing or disabling the parts of your program that are not related to this problem. Add lots of debug messages, ask someone else to look at your code, etc.
I wish you good luck. Sounds like you will need it. |
|
|
Ttelmah Guest
|
|
Posted: Mon Sep 10, 2007 9:13 am |
|
|
There is no default 'timeout', in the PIC RS232 handling. If you want it, you have to write code to add it. The only way you can see a 'timout' behaviour, is if your code is generating it, either by (for instance), letting a watchdog timeout occur, while handling the RS232, or by deliberately generating it (a search here for 'timed getc', will find code examples)....
Timout handling, has been added in the latest V4 compilers, but you have to explicitly program for this.
Best Wishes |
|
|
|