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

Why is mine RS232 Serial slow????? at 115200

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



Joined: 08 Sep 2006
Posts: 182

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

Why is mine RS232 Serial slow????? at 115200
PostPosted: Thu Oct 05, 2006 2:28 am     Reply with quote

Hello,

I have a RS232 communication at 115200 with CTS handshaking and it works (mostly) very good only the time between two strings is very long...
Indeed I do some string compares but for sending 10k data it takes 3 minutes to send....??? Where am I going wrong???

I added mine code....

#use delay(clock=10000000)
#use rs232(baud=115200, xmit=PIN_C6, rcv=PIN_C7, errors)


#int_rda
void serial_isr()
{
string[next_in]=getch();

if (input(CTS) && string_ready)
{
output_toggle(ERROR);
}

if(string[next_in] == '\n') //End string
{
output_high(CTS); //Stop commuication
string_ready = 1;
string[next_in] = '\0';
output_toggle(HARTBEAT);
}

next_in=(next_in+1);

if(!string_ready)
{
output_low(CTS);
}
stop = 1;
}



void main()
{
int16 i, j, value, type, cont = 0;
int16 address_hi, address_lo, address;
char string1[] = "DATA:FLUSH";
char string2[] = "DATA";
char string3[] = "DATA:SAMPLE";
char string4[] = "DATA:TRIGGER";
char string5[] = "DATA:FIRST";
char string6[] = "DATA:LAST";
char string7[] = "LIST:MODE CONT";
char string8[] = "LIST:MODE SINGLE";
char string9[] = "LIST:START";
char string10[] = "LIST:STOP";
char string11[] = "POS";
char string12[] = "RESET";

setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF|ADC_TAD_MUL_0);
setup_psp(PSP_DISABLED);
setup_spi(SPI_MASTER|SPI_L_TO_H|SPI_CLK_DIV_16|SPI_SS_DISABLED);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
setup_timer_4(T4_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(VREF_LOW|-2);
setup_low_volt_detect(FALSE);
setup_oscillator(False);
enable_interrupts(int_rda);
enable_interrupts(global);

delay_ms(20);
delay_dac = 2;
send_to_dac714(0);
trigger_mode = 0;

fill_eeprom();
fill_tabel();

output_low(CTS);
while(TRUE)
{
if(string_ready)
{
if(!(strncmp(string,string2,4)) && (!(string[4] ==':'))) //"DATA";
{
data_tabel();
}
}
}
Ttelmah
Guest







PostPosted: Thu Oct 05, 2006 3:03 am     Reply with quote

Ignoring the code for a moment, use the 'code' buttons when posting code, and tick the box 'disable HTML in this post', otherwise the result is unreadable, with much of the code simply 'lost'.
Now because this hasn't been done, we can only see 'extracts' of the code, but some comments still apply. I wouldn't read the CTS pin in the interrupt handler. _You_ are setting the CTS pin, so _you_ know it it is set. The problem here is that reading a pin (assuming you are using the 'standard_io' model), will change it's programming to be an input, rather than an output, and may well result in problems. So do the interrupt handler, something like:
Code:

int1 CTS_OFF;

#int_rda
void serial_isr() {
   int8 temp;
   temp=getch();

   //If data is still arriving, and CTS is set
   if (CTS_OFF && string_ready) {
      output_toggle(ERROR);
   }

   if (temp == '\n') //End string {
      output_high(CTS); //Stop commuication
      CTS_OFF=TRUE;
      string_ready = 1;
      string[next_in] = '\0';
      output_toggle(HARTBEAT);
   }
   else string[next_in]=temp;
   next_in=(next_in+1);

   if(!string_ready) {
      output_low(CTS);
      CTS_STATE=FALSE;
   }
   stop = 1;
}

Now, I use 'temp', and only access the array once for each byte, because array accesses typically take about a dozen instruction cycles, against a direct byte access to a single variable, taking about two. This saves a little time in checking for the line feed on each pass. I'm not sure what 'stop' is meant to indicate?. It is simply set every time a byte is received. Also you need to check on the RTS handling for your transmitting device. Few devices stop immediately, when RTS turns off. On the typical PC, up to about 16 characters can be sent after this signal changes. This is going to trigger your 'error' state. I normally use a ring buffer (rather than the linear buffer you are showing), and turn off the CTS output, when the buffer has about 10 spaces left.
We cannot see the code that actually resets the CTS, and that you do reset the buffer (necessary with the linear buffer being used). I'd suspect that something is not quite properly being cleared, or something here is taking a lot longer than you think.

Best Wishes
Jody



Joined: 08 Sep 2006
Posts: 182

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

PostPosted: Thu Oct 05, 2006 3:49 am     Reply with quote

(sorry for missing the code button)
Tried your code....
It seems to do the same.... that is time related..
I send: DATA 1,2354\n and I do that 500 times.. and that takes 3 minutes before it is al send...
The communication is alright... Almost never I get garbage. But the time spend in the #int_rda routine is very long... I removed all of mine code and only uses the #int_rda routine and the main to clear all the counters. The time between the \n pieces is very long... and I have no clue where to look for.....

If you want I will send the code I am using right now...

Thanks in advance,

Jody
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