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

Hardware rs232 hangs

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







Hardware rs232 hangs
PostPosted: Fri Apr 18, 2003 5:55 pm     Reply with quote

I am probably violating some 'c' rule or other, or there may be a bug in the CCS compiler handling of the hardware RS232 on the 16C74. See below for programs communicating between two 16C74 via the hardware RS232.
The situation is:
1. If I send the same number of characters as I try to receive then the program works. However..
2: If I send less characters than I expect (as shown) then the programs behave as would be expected initially. The receiving end sits in the getc function waiting for the last character
to arrive. If the 'reset' button is pressed a second time to send a second burst of characters the display loop completes. If I press the 'reset' button again the receive program hangs in the getc loop no matter how many times the button is pressed.
3. By using various outputs to my LED array on port b I see that one byte of garbage is received on power up, hence my use of the a to get attention at the correct moment. I was
attempting to send binary data (not characters) between two pieces of equipment and simplified my problems down to this level when I was getting errors.
I think I have to either convert to hex, transmit, then convert to bytes - or - write my own RS232 code to use the status and control registers. I suspect an error bit (overrun or framing) needs to be cleared although with the delays I used I can't see why the program should hang.
I regard myself as experienced in electronics but only a novice C programmer.

// 16C74 at transmitter end - partial code...
#use RS232 (baud=9600, parity=N, bits=8, xmit=pin_c6, rcv=pin_c7)

main()
{
#define reset (input (pin_B6))
int i;

if (!reset){ // if reset pressed then send

putc ('a'); // send an a to get attention at the other end

for (i=1; i<=27; i++) {
putc (0x40 + i); // send A thru the next 26 codes to keep ASCII
delay_ms (1); // but putc (i) doesn't work either
} // end for loop
while (!reset); // wait for button to be released
} // end if loop

delay_ms (2000); // wait 2 seconds
} // end main loop



// 16C74 at receiving end - partial code...
#use RS232 (baud=9600, parity=N, bits=8, xmit=pin_c6, rcv=pin_c7)

main()
{
char data [30]; // declare array
int i;

while (1) // loop endlessly
{
while (getc() != 0x61); // wait for start character

for (i=1; i<=28; i++) { // 27 works, 28 does not
data [i] = getc(); // get data into array
} // program hangs in this loop

for (i=1; i<=28; i++) { // display data on LEDs
output_b (data[i]); // each for 1/2 seconds
delay_ms (500);
}
delay_ms (3000); // wait 3 seconds
}
}
___________________________
This message was ported from CCS's old forum
Original Post ID: 13796
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: Hardware rs232 hangs
PostPosted: Fri Apr 18, 2003 6:26 pm     Reply with quote

:=I am probably violating some 'c' rule or other, or there may be a bug in the CCS compiler handling of the hardware RS232 on the 16C74. See below for programs communicating between two 16C74 via the hardware RS232.
:=// 16C74 at receiving end - partial code...
:= #use RS232 (baud=9600, parity=N, bits=8, xmit=pin_c6, rcv=pin_c7)
--------------------------------------------------

It's about time to leave for the day, so I can give you one
quick tip. If you use the ERRORS directive, it will clear the
USART if an over-run error occurs. Example:

#use RS232 (baud=9600, xmit=pin_c6, rcv=pin_c7, ERRORS)

This only works with the hardware USART (which you are using).
___________________________
This message was ported from CCS's old forum
Original Post ID: 13799
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

Re: Hardware rs232 hangs
PostPosted: Sat Apr 19, 2003 9:06 am     Reply with quote

:=I am probably violating some 'c' rule or other, or there may be a bug in the CCS compiler handling of the hardware RS232 on the 16C74. See below for programs communicating between two 16C74 via the hardware RS232.
:=The situation is:
:=1. If I send the same number of characters as I try to receive then the program works. However..
:=2: If I send less characters than I expect (as shown) then the programs behave as would be expected initially. The receiving end sits in the getc function waiting for the last character
:=to arrive. If the 'reset' button is pressed a second time to send a second burst of characters the display loop completes. If I press the 'reset' button again the receive program hangs in the getc loop no matter how many times the button is pressed.
:=3. By using various outputs to my LED array on port b I see that one byte of garbage is received on power up, hence my use of the a to get attention at the correct moment. I was
:=attempting to send binary data (not characters) between two pieces of equipment and simplified my problems down to this level when I was getting errors.
:=I think I have to either convert to hex, transmit, then convert to bytes - or - write my own RS232 code to use the status and control registers. I suspect an error bit (overrun or framing) needs to be cleared although with the delays I used I can't see why the program should hang.
:=I regard myself as experienced in electronics but only a novice C programmer.
:=
:=// 16C74 at transmitter end - partial code...
:= #use RS232 (baud=9600, parity=N, bits=8, xmit=pin_c6, rcv=pin_c7)
:=
:=main()
:={
:= #define reset (input (pin_B6))
:= int i;
:=
:= if (!reset){ // if reset pressed then send

:= putc ('a'); // send an a to get attention at the other end
:=
:= for (i=1; i<=27; i++) {
:= putc (0x40 + i); // send A thru the next 26 codes to keep ASCII
:= delay_ms (1); // but putc (i) doesn't work either
:= } // end for loop
:= while (!reset); // wait for button to be released
:= } // end if loop
:=
:= delay_ms (2000); // wait 2 seconds
:=} // end main loop
:=
:=
:=
:=// 16C74 at receiving end - partial code...
:= #use RS232 (baud=9600, parity=N, bits=8, xmit=pin_c6, rcv=pin_c7)
:=
:=main()
:={
:=char data [30]; // declare array
static int i, ch_rcved, packet_ready;

while (1) // loop endlessly
{
if(kbhit()) // IF falling down pulse in Rcv_PIN !!!
{
do
{
ch_rcved = getc();

if(ch_rcved == 0x61) // Start character
i = 0; //
else
i++;

if(ch_rcved == 'z') // last char expected
packet_ready = TRUE;

data[i] = ch_rcved; // store in buffer

}while(!packet_ready); //

}


if(packet_ready)
{
for (i=0; i<=27; i++) // display data on LEDs
{
output_b (data[i]); // each for 1/2 seconds
delay_ms (500);
}
packet_ready = FALSE;
}

delay_ms (3000); // wait 3 seconds
}
}


Be sure that the Rcv_PIN is glitch free, if necesary put a 10K pull up resistor.

Hope this help.

Humberto
___________________________
This message was ported from CCS's old forum
Original Post ID: 13818
_________________
Humberto
bunge
Guest







Re: Hardware rs232 hangs
PostPosted: Tue Apr 22, 2003 5:57 pm     Reply with quote

Thanks to everyone for the help. Yes, the problem was an input over-run, and yes the "errors" addition to the #use rs232... line solved the problem until I can write some more elegant code. Regards, Peter Bunge.
___________________________
This message was ported from CCS's old forum
Original Post ID: 13931
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