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

UART slow speed

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



Joined: 24 Jan 2015
Posts: 63

View user's profile Send private message

UART slow speed
PostPosted: Tue Feb 09, 2021 11:43 am     Reply with quote

After making a big program that uses rs232, I found out that something is wrong with rs232. I realised that when i tried to send more bytes than my buffer is. I will try to print only things that matters since its big.

I split my payload into 230 bytes pieces, and i use
dbg_printf("\r\nbuffer1 : %u", tx_buffer_bytes());
between pieces to see how quickly buffer draws. 1 byte every 100ms!

Code:
#include "18F47J53.h"
#use delay(internal=8MHz, clock=48MHz, restart_wdt, USB_FULL, act=USB)
#pin_select U2TX = PIN_D4
#pin_select U2RX = PIN_D5
#define USE_TX_ISR
#use rs232(UART2,baud=57600,RECEIVE_BUFFER=250, TRANSMIT_BUFFER=256,parity=N,bits=8,xmit=PIN_D4,rcv=PIN_D5,stream=GSM,TXISR,ERRORS) //xmit=PIN_D4,rcv=PIN_D5,

void main();
   setup_adc_ports(sAN6|sAN5|sAN4|sAN2);
   setup_adc(ADC_CLOCK_INTERNAL|ADC_TAD_MUL_0);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256);  // 1 sec
   setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);      //262 ms overflow
   setup_timer_2(T2_DIV_BY_16,61,5);      //1,0 ms overflow, 5 ms interrupt
   setup_timer_3(T3_INTERNAL | T3_DIV_BY_8);
   enable_interrupts(int_timer0);
   enable_interrupts(int_timer1);
   enable_interrupts(int_timer2);
   disable_interrupts(int_timer3);
   enable_interrupts(INT_EXT1);
   enable_interrupts(INT_RDA);
   enable_interrupts(GLOBAL);



I have no problem receiving ( by manually checking kbhit() ). The problem is below.
Code:

dbg_printf("\r\nbuffer0 : %u",tx_buffer_bytes());
do{
      if ((log_send)<(total_logs)) 
      {
         memset(body,0,250);
         read_log(log_send); // it creates body
         fputs(body,GSM);
         log_send++;
         dbg_printf("\r\nbuffer1 : %u",tx_buffer_bytes());
         delay_ms(1000);
         dbg_printf("\r\nbuffer2 : %u",tx_buffer_bytes());
         delay_ms(500);
         dbg_printf("\r\nbuffer3 : %u",tx_buffer_bytes());
         delay_ms(100);
         dbg_printf("\r\nbuffer4 : %u",tx_buffer_bytes());
      }
   }  while (log_que==1);


This is what i get in my usb output:

buffer0 : 1
body part1 ..........
buffer1 : 226
buffer2 : 217
buffer3 : 212
buffer4 : 209
next body part.......
buffer1 : 248
buffer2 : 239
buffer3 : 234
buffer4 : 231
next body part.......
buffer1 : 15
buffer2 : 6
buffer3 : 1
buffer4 : 0

So in this example i lost part 2.

I've read many examples and approaches about uart but what is the problem here?
nuclear__



Joined: 24 Jan 2015
Posts: 63

View user's profile Send private message

PostPosted: Tue Feb 09, 2021 12:54 pm     Reply with quote

Well that was probably bad use of delay,
i wrote this code to replace my delay_ms and now its super fast..

Code:
dbg_printf("\r\nbuffer1 : %u",tx_buffer_bytes());
         do{
            delay_cycles( 200 );
         } while (tx_buffer_bytes()>=5);
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