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 CCS Technical Support

RS 232 Transmit in a Do Loop possible ??

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



Joined: 08 Sep 2003
Posts: 492
Location: India

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

RS 232 Transmit in a Do Loop possible ??
PostPosted: Sat Jul 19, 2003 8:42 am     Reply with quote

Hi All,

I want to transmit series of characters as fast as possible, is it OK to do it this way.

#use delay(clock=20000000)
#use rs232(baud=9600,xmit=pin_c6, rcv=pin_c7,parity=n)

void send_data()
{

for (i=0;i<10;++i)
{
putc('A');
}


}

I find that I do not receive 10 A's ,

Is it necessary to wait for the transmit to get over, or does putc() does this automatically.

thanks
arunb
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516176
Dave Yeatman
Guest







Re: RS 232 Transmit in a Do Loop possible ??
PostPosted: Sat Jul 19, 2003 9:01 am     Reply with quote

<font face="Courier New" size=-1>Arunb,
Yes the DO LOOP should work fine. The PIC gest to the last statement in the program before the transmit is complete and the CCS compiler automatically puts a SLEEP command at the end.

Try adding while(1); as the last statement and that should fix it.

Dave

:=Hi All,
:=
:=I want to transmit series of characters as fast as possible, is it OK to do it this way.
:=
:=#use delay(clock=20000000)
:=#use rs232(baud=9600,xmit=pin_c6, rcv=pin_c7,parity=n)
:=
:=void send_data()
:={
:=
:=for (i=0;i<10;++i)
:={
:= putc('A');
:=}
:=
:=
:=}
:=
:=I find that I do not receive 10 A's ,
:=
:=Is it necessary to wait for the transmit to get over, or does putc() does this automatically.
:=
:=thanks
:=arunb ___________________________
This message was ported from CCS's old forum
Original Post ID: 144516179
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

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

Re: RS 232 Transmit in a Do Loop possible ??
PostPosted: Sat Jul 19, 2003 7:48 pm     Reply with quote

You should check to make sure that the transmit register is not full before writing to it.

:=<font face="Courier New" size=-1>Arunb,
:=Yes the DO LOOP should work fine. The PIC gest to the last statement in the program before the transmit is complete and the CCS compiler automatically puts a SLEEP command at the end.
:=
:=Try adding while(1); as the last statement and that should fix it.
:=
:=Dave
:=
:=:=Hi All,
:=:=
:=:=I want to transmit series of characters as fast as possible, is it OK to do it this way.
:=:=
:=:=#use delay(clock=20000000)
:=:=#use rs232(baud=9600,xmit=pin_c6, rcv=pin_c7,parity=n)
:=:=
:=:=void send_data()
:=:={
:=:=
:=:=for (i=0;i<10;++i)
:=:={
:=:= putc('A');
:=:=}
:=:=
:=:=
:=:=}
:=:=
:=:=I find that I do not receive 10 A's ,
:=:=
:=:=Is it necessary to wait for the transmit to get over, or does putc() does this automatically.
:=:=
:=:=thanks
:=:=arunb ___________________________
This message was ported from CCS's old forum
Original Post ID: 144516187
arunb



Joined: 08 Sep 2003
Posts: 492
Location: India

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

Re: RS 232 Transmit in a Do Loop possible ??
PostPosted: Sun Jul 20, 2003 6:07 am     Reply with quote

Hi,

How does one ensure the txd buffer is not full.

thanks
arunb

:=You should check to make sure that the transmit register is not full before writing to it.
:=
:=:=<font face="Courier New" size=-1>Arunb,
:=:=Yes the DO LOOP should work fine. The PIC gest to the last statement in the program before the transmit is complete and the CCS compiler automatically puts a SLEEP command at the end.
:=:=
:=:=Try adding while(1); as the last statement and that should fix it.
:=:=
:=:=Dave
:=:=
:=:=:=Hi All,
:=:=:=
:=:=:=I want to transmit series of characters as fast as possible, is it OK to do it this way.
:=:=:=
:=:=:=#use delay(clock=20000000)
:=:=:=#use rs232(baud=9600,xmit=pin_c6, rcv=pin_c7,parity=n)
:=:=:=
:=:=:=void send_data()
:=:=:={
:=:=:=
:=:=:=for (i=0;i<10;++i)
:=:=:={
:=:=:= putc('A');
:=:=:=}
:=:=:=
:=:=:=
:=:=:=}
:=:=:=
:=:=:=I find that I do not receive 10 A's ,
:=:=:=
:=:=:=Is it necessary to wait for the transmit to get over, or does putc() does this automatically.
:=:=:=
:=:=:=thanks
:=:=:=arunb ___________________________
This message was ported from CCS's old forum
Original Post ID: 144516193
R.J.Hamlett
Guest







Re: RS 232 Transmit in a Do Loop possible ??
PostPosted: Sun Jul 20, 2003 6:30 am     Reply with quote

:=Hi,
:=
:=How does one ensure the txd buffer is not full.
:=
:=thanks
:=arunb
You don't have to bother. The putc code will 'hold' you, if the buffer is not free.
As has allready been stated, the reason for the loss of your characters, is at the 'other end'. Basically, the CCS compiler, adds a 'sleep' instruction off the end of the 'main' code. Now the UART, has a maximum of three characters of buffering (the actual 'TX' register, the buffer this transfers to, and the shift register from which characters are sent). When you send ten characters, at the end of the routine, three characters are in these registers, and when the processor then sleeps, transmission stops, and these characters do not get sent.
You can test by coding the bits in the processor registers. You don't say what chip you are using, so will need to change these to suit (I have put the values for an 18F chip):

#bit TRMT=0xFAC.1
#bit TXIF=0xF9E.4

Then the 'TRMT' bit, will be set, when the transmitter shift register is empty. Hence you can check for the data having been sent, by coding:

while (!TRMT) ;

The 'TXIF' bit, will be set, when the main holding register, transfers it's contents to the transmit buffer. It is cleared, whenever data is transferred to the holding register. So if you want to 'take over' this operation, you can code:

while (!TXIF) ;

Best Wishes

:=:=You should check to make sure that the transmit register is not full before writing to it.
:=:=
:=:=:=<font face="Courier New" size=-1>Arunb,
:=:=:=Yes the DO LOOP should work fine. The PIC gest to the last statement in the program before the transmit is complete and the CCS compiler automatically puts a SLEEP command at the end.
:=:=:=
:=:=:=Try adding while(1); as the last statement and that should fix it.
:=:=:=
:=:=:=Dave
:=:=:=
:=:=:=:=Hi All,
:=:=:=:=
:=:=:=:=I want to transmit series of characters as fast as possible, is it OK to do it this way.
:=:=:=:=
:=:=:=:=#use delay(clock=20000000)
:=:=:=:=#use rs232(baud=9600,xmit=pin_c6, rcv=pin_c7,parity=n)
:=:=:=:=
:=:=:=:=void send_data()
:=:=:=:={
:=:=:=:=
:=:=:=:=for (i=0;i<10;++i)
:=:=:=:={
:=:=:=:= putc('A');
:=:=:=:=}
:=:=:=:=
:=:=:=:=
:=:=:=:=}
:=:=:=:=
:=:=:=:=I find that I do not receive 10 A's ,
:=:=:=:=
:=:=:=:=Is it necessary to wait for the transmit to get over, or does putc() does this automatically.
:=:=:=:=
:=:=:=:=thanks
:=:=:=:=arunb ___________________________
This message was ported from CCS's old forum
Original Post ID: 144516194
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

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

Re: RS 232 Transmit in a Do Loop possible ??
PostPosted: Sun Jul 20, 2003 9:12 am     Reply with quote

:=:=Hi,
:=:=
:=:=How does one ensure the txd buffer is not full.
:=:=
:=:=thanks
:=:=arunb
:=You don't have to bother. The putc code will 'hold' you, if the buffer is not free.
:=As has allready been stated, the reason for the loss of your characters, is at the 'other end'. Basically, the CCS compiler, adds a 'sleep' instruction off the end of the 'main' code. Now the UART, has a maximum of three characters of buffering (the actual 'TX' register, the buffer this transfers to, and the shift register from which characters are sent).

There are actually only 2 chars buffered, TSR and TXREG. Data is moved directly from the TXREG to the TSR when the stop bit of the data in the TSR has been sent. If the TSR register is empty when data is written to the TXREG, the data is immediately transferred to the TSR and the TXIF flag is set indicating that it is safe to write another byte to the TXREG. Since you have one byte buffered, if none of you ISR routines or you do not disable ints for more than 1ms, you will not see any 'space' between bytes. The 1ms is how long it takes to transmit 1 byte and 9600bps. Note that I didn't account for the time it takes to process the interrupt so the time is actually slightly less.

:=When you send ten characters, at the end of the routine, three characters are in these registers, and when the processor then sleeps, transmission stops, and these characters do not get sent.
:=You can test by coding the bits in the processor registers. You don't say what chip you are using, so will need to change these to suit (I have put the values for an 18F chip):
:=
:=#bit TRMT=0xFAC.1
:=#bit TXIF=0xF9E.4
:=
:=Then the 'TRMT' bit, will be set, when the transmitter shift register is empty. Hence you can check for the data having been sent, by coding:
:=
:=while (!TRMT) ;
:=
:=The 'TXIF' bit, will be set, when the main holding register, transfers it's contents to the transmit buffer. It is cleared, whenever data is transferred to the holding register. So if you want to 'take over' this operation, you can code:
:=
:=while (!TXIF) ;
:=
:=Best Wishes
:=
:=:=:=You should check to make sure that the transmit register is not full before writing to it.
:=:=:=
:=:=:=:=<font face="Courier New" size=-1>Arunb,
:=:=:=:=Yes the DO LOOP should work fine. The PIC gest to the last statement in the program before the transmit is complete and the CCS compiler automatically puts a SLEEP command at the end.
:=:=:=:=
:=:=:=:=Try adding while(1); as the last statement and that should fix it.
:=:=:=:=
:=:=:=:=Dave
:=:=:=:=
:=:=:=:=:=Hi All,
:=:=:=:=:=
:=:=:=:=:=I want to transmit series of characters as fast as possible, is it OK to do it this way.
:=:=:=:=:=
:=:=:=:=:=#use delay(clock=20000000)
:=:=:=:=:=#use rs232(baud=9600,xmit=pin_c6, rcv=pin_c7,parity=n)
:=:=:=:=:=
:=:=:=:=:=void send_data()
:=:=:=:=:={
:=:=:=:=:=
:=:=:=:=:=for (i=0;i<10;++i)
:=:=:=:=:={
:=:=:=:=:= putc('A');
:=:=:=:=:=}
:=:=:=:=:=
:=:=:=:=:=
:=:=:=:=:=}
:=:=:=:=:=
:=:=:=:=:=I find that I do not receive 10 A's ,
:=:=:=:=:=
:=:=:=:=:=Is it necessary to wait for the transmit to get over, or does putc() does this automatically.
:=:=:=:=:=
:=:=:=:=:=thanks
:=:=:=:=:=arunb ___________________________
This message was ported from CCS's old forum
Original Post ID: 144516195
R.J.Hamlett
Guest







Re: RS 232 Transmit in a Do Loop possible ??
PostPosted: Sun Jul 20, 2003 9:29 am     Reply with quote

:=:=:=Hi,
:=:=:=
:=:=:=How does one ensure the txd buffer is not full.
:=:=:=
:=:=:=thanks
:=:=:=arunb
:=:=You don't have to bother. The putc code will 'hold' you, if the buffer is not free.
:=:=As has allready been stated, the reason for the loss of your characters, is at the 'other end'. Basically, the CCS compiler, adds a 'sleep' instruction off the end of the 'main' code. Now the UART, has a maximum of three characters of buffering (the actual 'TX' register, the buffer this transfers to, and the shift register from which characters are sent).
:=
:=There are actually only 2 chars buffered, TSR and TXREG. Data is moved directly from the TXREG to the TSR when the stop bit of the data in the TSR has been sent. If the TSR register is empty when data is written to the TXREG, the data is immediately transferred to the TSR and the TXIF flag is set indicating that it is safe to write another byte to the TXREG. Since you have one byte buffered, if none of you ISR routines or you do not disable ints for more than 1ms, you will not see any 'space' between bytes. The 1ms is how long it takes to transmit 1 byte and 9600bps. Note that I didn't account for the time it takes to process the interrupt so the time is actually slightly less.
:=
I would normally agree. The data sheet seems to imply this, _but_ if you put the chip to sleep immediately after loading the transmit buffer, three characters seem to be left untransmitted. I have never been able to trace 'why', but one early Microchip sheet, shows the UART as having the 'user' register, a TX register, and the shift register. It certainly at times behaves like this... :-)

Best Wishes

:=:=When you send ten characters, at the end of the routine, three characters are in these registers, and when the processor then sleeps, transmission stops, and these characters do not get sent.
:=:=You can test by coding the bits in the processor registers. You don't say what chip you are using, so will need to change these to suit (I have put the values for an 18F chip):
:=:=
:=:=#bit TRMT=0xFAC.1
:=:=#bit TXIF=0xF9E.4
:=:=
:=:=Then the 'TRMT' bit, will be set, when the transmitter shift register is empty. Hence you can check for the data having been sent, by coding:
:=:=
:=:=while (!TRMT) ;
:=:=
:=:=The 'TXIF' bit, will be set, when the main holding register, transfers it's contents to the transmit buffer. It is cleared, whenever data is transferred to the holding register. So if you want to 'take over' this operation, you can code:
:=:=
:=:=while (!TXIF) ;
:=:=
:=:=Best Wishes
:=:=
:=:=:=:=You should check to make sure that the transmit register is not full before writing to it.
:=:=:=:=
:=:=:=:=:=<font face="Courier New" size=-1>Arunb,
:=:=:=:=:=Yes the DO LOOP should work fine. The PIC gest to the last statement in the program before the transmit is complete and the CCS compiler automatically puts a SLEEP command at the end.
:=:=:=:=:=
:=:=:=:=:=Try adding while(1); as the last statement and that should fix it.
:=:=:=:=:=
:=:=:=:=:=Dave
:=:=:=:=:=
:=:=:=:=:=:=Hi All,
:=:=:=:=:=:=
:=:=:=:=:=:=I want to transmit series of characters as fast as possible, is it OK to do it this way.
:=:=:=:=:=:=
:=:=:=:=:=:=#use delay(clock=20000000)
:=:=:=:=:=:=#use rs232(baud=9600,xmit=pin_c6, rcv=pin_c7,parity=n)
:=:=:=:=:=:=
:=:=:=:=:=:=void send_data()
:=:=:=:=:=:={
:=:=:=:=:=:=
:=:=:=:=:=:=for (i=0;i<10;++i)
:=:=:=:=:=:={
:=:=:=:=:=:= putc('A');
:=:=:=:=:=:=}
:=:=:=:=:=:=
:=:=:=:=:=:=
:=:=:=:=:=:=}
:=:=:=:=:=:=
:=:=:=:=:=:=I find that I do not receive 10 A's ,
:=:=:=:=:=:=
:=:=:=:=:=:=Is it necessary to wait for the transmit to get over, or does putc() does this automatically.
:=:=:=:=:=:=
:=:=:=:=:=:=thanks
:=:=:=:=:=:=arunb ___________________________
This message was ported from CCS's old forum
Original Post ID: 144516196
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