View previous topic :: View next topic |
Author |
Message |
EmbdFreak
Joined: 28 Jul 2005 Posts: 23
|
UART Rx: char missing |
Posted: Tue May 16, 2006 3:14 am |
|
|
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
|
|
Posted: Tue May 16, 2006 4:01 am |
|
|
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)
|
|
Posted: Tue May 16, 2006 7:23 am |
|
|
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
|
|
Posted: Tue May 16, 2006 7:29 am |
|
|
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
|
|
Posted: Tue May 16, 2006 8:07 am |
|
|
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
|
|
Posted: Tue May 16, 2006 8:35 am |
|
|
..
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
|
|
Posted: Tue May 16, 2006 12:27 pm |
|
|
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
|
|
Posted: Tue May 16, 2006 3:26 pm |
|
|
...and a software serial port?
Code: | fprintf(PC,"S%s",sensorin);
|
|
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Tue May 16, 2006 6:01 pm |
|
|
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. |
|
|
|