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

Problem With RS232

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








Problem With RS232
PostPosted: Fri Jan 21, 2005 9:57 am     Reply with quote

Hello,
I am using 18F2620 and I wrote a very simple code that send data to PC and get a char from PC. It does sending data out but not receiving any data.
I am using build in serial io monitor that comes with PIC C. The hardware handshaking is in place but for simplicity I set them off in Serial monitor so there should be no hardware handshaking.
The code is as follow:

#include <18F2620.h>
#include <stdio.h>
#use delay(clock=8000000)
#fuses NOWDT,WDT128,INTRC, NOPROTECT, NOIESO, NOBROWNOUT, BORV21, PUT, NOCPD, STVREN, NODEBUG, NOLVP, NOWRT, NOWRTD, NOEBTR, NOCPB, NOEBTRB, NOWRTC, NOWRTB, NOFCMEN, NOXINST, NOPBADEN, NOLPT1OSC, NOMCLR
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)

#define toggle(x) {if(input(x)) output_low(x); else output_high(x);}

void beep(int16 delay,int16 freq)
{
int16 i;
for(i=0;i<delay;i++)
{
delay_us(freq);
toggle(PIN_C2);
}
}

void main()
{
byte c;
setup_oscillator(OSC_8MHZ); // selecting internal osc 8mhz
// setting output tri state register
set_tris_a(0xff);
set_tris_b(0);
set_tris_c(0);
// needed by my hardware
output_high(PIN_C1);
// first beep
beep(100000,300);
printf("Software was compiled on ");
printf(__TIME__);
printf("\r\nBefore getc\r\n");
// second beep
beep(10000,100);
c=getc();
// third beep
beep(1000,200);
printf("read data =%c\n\r",c);
printf("Program finished\r\n");
}


The result:

The above program write the requested message to output and I can hear two beep so I believe it come and stops at getc.

If I change the value for TRIS-C to 0b11000000. The received message is garbage but I can hear two beeps.
TRIS-C=0b10000000 : The received message is garbage but I can hear two beeps.
TRIS_C= 0b01000000 : The received message is correct and I can hear two beep.

I all cases, when I am tying to send a data (for example 0x22) to the PIC so I can hear the third beep, I couldn’t hear it ( and can’t see the remaining messages)

Could you please help me to find a solution for this?

Best regards
Ttelmah
Guest







PostPosted: Fri Jan 21, 2005 11:13 am     Reply with quote

You may in part at least be hitting the 'run off the end' problem.
In the PC, when you compile a C program, the 'main', is called from the OS, and when it ends, you return to this OS, and the processor keeps running. On the PIC, the 'main' is the entire program. Hence the code _must_ stay inside the program, and not 'run off the end'. If (for instance, and without any 'setup' instructions), you have a main like:
Code:

main() {
    printf("Test Message /n/r");
}

Only part of this message will be received by a device watching the port, as the processor finishes sending the code to the UART, then runs off the end, immediately going to sleep, and stoping sending data.
Hence you must either add a delay long enough for the data to be sent, or prevent the code running off the end:
Code:

main() {
    printf("Test Message /n/r");
    //This puts the processor into an infinite loop
    while (true) ;
}

This normally only results in the loss of the last three characters, not the whole message though.

Your 'toggle' function is already present in the C.

Are you running this on a chip, or a ICE?. MicroChip, have at times changed the TRIS requirements to enable the UART. On some chips (according to the data sheet yours), the pattern 0b11000000 is needed, while on others, the TRIS requirements for the pins invert. I ran into a problem when the 18Fxx2 first came out, that MicroChip's ICE unit, required 0B10xxxxxx, while the actual chips required 0B00xxxxxx. They updated the pod for the ICE fairly quickly, and made the behaviour the same.
Add 'ERRORS' to your RS232 defintion, otherwise if the receive buffer overflows, the system will never recover.
How is your RS232 wired?.

Best Wishes
Guest








PostPosted: Fri Jan 21, 2005 12:37 pm     Reply with quote

Thanks,
I add the suggested code ( while(1); at the end and ERRORS in #use RS232) without any sucess:
I will draw the wiring and post it later.

I couldn't find any refrence to toggle in PIC C, where can I find information about it?

Best regards
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

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

PostPosted: Fri Jan 21, 2005 1:15 pm     Reply with quote

Anonymous wrote:

I couldn't find any refrence to toggle in PIC C, where can I find information about it?


Check the "readme.txt" file that was installed in the PICC directory. It contains up to the minute information about the compiler, syntax and functions.

If it does not list "output_toggle" then your compiler is too "old" and does not support the function call.
_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
Guest








PostPosted: Fri Jan 21, 2005 3:38 pm     Reply with quote

Thanks
My compiler is version 3.214 and the IDE is 3.212 which I belive isn't very old.

I couldn't find any refrence to output_toggle in readme.txt or help file, but when I used it in my program, it works without any compilation error.

Any suggestion on RS232 problem?

best regards
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

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

PostPosted: Fri Jan 21, 2005 4:32 pm     Reply with quote

Anonymous wrote:
Thanks
My compiler is version 3.214 and the IDE is 3.212 which I belive isn't very old.

I couldn't find any refrence to output_toggle in readme.txt or help file, but when I used it in my program, it works without any compilation error.

Any suggestion on RS232 problem?

best regards


From the readme.txt:

A new built in function OUTPUT_TOGGLE(pin) will toggle the state of
a specified pin. The parameter is the same as OUTPUT_HIGH.

Try searching for "OUTPUT_TOGGLE" or turn off case sensitivity. Should appear just before the 1/2 way point through the file.
_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
Guest








PostPosted: Sat Jan 22, 2005 4:15 am     Reply with quote

Hello,

How can attach a file to the forum?
I want to attach the schematic of the design.

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