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 you help me about #use rs232

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



Joined: 12 Aug 2007
Posts: 41

View user's profile Send private message Send e-mail MSN Messenger

Can you help me about #use rs232
PostPosted: Sat Sep 08, 2007 3:41 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Sep 08, 2007 3:52 am     Reply with quote

Quote:
puts(a1[0]);


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

View user's profile Send private message Send e-mail MSN Messenger

Solution_?
PostPosted: Sun Sep 09, 2007 4:45 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Sep 09, 2007 7:28 am     Reply with quote

Quote:
i know that
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

View user's profile Send private message Send e-mail MSN Messenger

PostPosted: Mon Sep 10, 2007 12:34 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Sep 10, 2007 1:48 am     Reply with quote

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

View user's profile Send private message Send e-mail

RE:
PostPosted: Mon Sep 10, 2007 2:28 am     Reply with quote

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

View user's profile Send private message Send e-mail MSN Messenger

My problem goes on
PostPosted: Mon Sep 10, 2007 5:42 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Sep 10, 2007 5:56 am     Reply with quote

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

View user's profile Send private message Send e-mail MSN Messenger

PostPosted: Mon Sep 10, 2007 6:10 am     Reply with quote

Hi ckielstra,

the small program is working Smile 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

View user's profile Send private message Send e-mail MSN Messenger

i found my problem, how can i solve this problem_?
PostPosted: Mon Sep 10, 2007 7:06 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Sep 10, 2007 7:41 am     Reply with quote

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

View user's profile Send private message Send e-mail MSN Messenger

PostPosted: Mon Sep 10, 2007 8:08 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Sep 10, 2007 9:10 am     Reply with quote

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







PostPosted: Mon Sep 10, 2007 9:13 am     Reply with quote

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
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