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 Rx: char missing

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



Joined: 28 Jul 2005
Posts: 23

View user's profile Send private message

UART Rx: char missing
PostPosted: Tue May 16, 2006 3:14 am     Reply with quote

Hi forum,
A program i had earlier developed has a small UART bug. The system recevies a 3 digit no. followed by CR. It is received this data via a hardware UART. Problem is only two digits are being received correctly.e.g of ABC<CR> being sent, only AB is received leaving out C behind. Can u identify the problematic part?

The following code tested it. Code not relevant to the prob. is not being pasted:

Code:

#use rs232 (baud=4800,xmit=PIN_C6,rcv=PIN_C7,stream=SIN_REMOUT,ERRORS)


void main()
{
    output_low(PIN_A0);  // No LCD backlight,until 'A' pressed
    lcd_init();
    rtc_init();
    init_ext_eeprom();
    setup_timer_0(RTCC_INTERNAL| RTCC_8_BIT | RTCC_DIV_256);
    setup_timer_1(T1_INTERNAL | T1_DIV_BY_8);
    enable_interrupts(INT_EXT);
    enable_interrupts(INT_TIMER0);
    enable_interrupts(INT_TIMER1);
    enable_interrupts(GLOBAL);
    initial_menu();
    fprintf(SIN_REMOUT,"conv\r");  // initializing the modem
    delay_ms(2000);
    fprintf(SIN_REMOUT,"conv\r");
    lcd_putc('\f');
    lcd_gotoxy(1,1);
    printf(lcd_putc,"*******************");
    lcd_gotoxy(1,2);
    printf(lcd_putc,"Level=");
    set_timer0(0);   //Re-initialize timer here
    INTcountavg=0;   //starts counting NOW !

    while(1)
    {
        fgets(sensorin,SIN_REMOUT); // acquires data
        fprintf(PC,"S%s",sensorin);
        range=strtod(sensorin,endptr); // range in inches stored in long
        snum++;

        if(showrange)
       {
         //   fprintf(PC,"RO");
   displayrange();
   set_timer0(0);   //restart timer0
   set_timer1(0);   //restart timer1
        }
     }   // while ends
}   
EmbdFreak



Joined: 28 Jul 2005
Posts: 23

View user's profile Send private message

PostPosted: Tue May 16, 2006 4:01 am     Reply with quote

i think ive figured out the problem. Its the soft uart tx taking more time than the buffer and store char.

Thanks forum !
carmarmu



Joined: 09 May 2006
Posts: 15
Location: Valencia (Spain)

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

PostPosted: Tue May 16, 2006 7:23 am     Reply with quote

Indeed!
You must make the reception of data by interruption, or otherwise, you will lose data.
Luck!!

EmbdFreak wrote:
i think ive figured out the problem. Its the soft uart tx taking more time than the buffer and store char.

Thanks forum !

_________________
**CaRmArMu** Valencia (Spain)
kender



Joined: 09 Aug 2004
Posts: 768
Location: Silicon Valley

View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger

PostPosted: Tue May 16, 2006 7:29 am     Reply with quote

carmarmu wrote:
You must make the reception of data by interruption, or otherwise, you will lose data.


It's a soft UART. Theoretiacally, it's possible to get an interrupt (or rather a "callback") from a soft UART, but does CCS compiler support it?
SLo
Guest







PostPosted: Tue May 16, 2006 8:07 am     Reply with quote

If your PIC supports it, you can arrange for the software data Rx pin to be one that also offers an external interrupt and use the external interrupt to trigger the start of software reception.
This still has limitations, but eases the need to frequently call kbhit()
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

PostPosted: Tue May 16, 2006 8:35 am     Reply with quote

..

Last edited by treitmey on Tue May 16, 2006 1:23 pm; edited 1 time in total
Mark



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

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

PostPosted: Tue May 16, 2006 12:27 pm     Reply with quote

He's already using the hardware uart for receiving!

Code:

#use rs232 (baud=4800,xmit=PIN_C6,rcv=PIN_C7,stream=SIN_REMOUT,ERRORS)
fgets(sensorin,SIN_REMOUT); // acquires data
SLo
Guest







PostPosted: Tue May 16, 2006 3:26 pm     Reply with quote

...and a software serial port?
Code:
fprintf(PC,"S%s",sensorin);
Mark



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

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

PostPosted: Tue May 16, 2006 6:01 pm     Reply with quote

SLo wrote:
...and a software serial port?
Code:
fprintf(PC,"S%s",sensorin);


Yes, but this appears to be for debugging. I see no place where the poster is trying to receive from a software uart therefore all these suggestions are pointless.
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