View previous topic :: View next topic |
Author |
Message |
jecottrell
Joined: 16 Jan 2005 Posts: 559 Location: Tucson, AZ
|
Receive Buffer Assistance |
Posted: Fri Oct 06, 2006 11:06 am |
|
|
Hello All,
I'm porting some code over to use one of Asmallri's UART drivers and have run into a snag. (btw, I purchased his simple SW_UART driver and I am extremely impressed with it. He was extremely helpful in trying to track down a previous bug. I learned a huge amount just by looking at the way he had done things.)
The new driver is so fast it passes through a while(kbhit) statement and keeps on going.
Code: |
while(HW_UART_KBHIT()) {
i = HW_UART_getcQ();
buffer[length] = i;
length++;
}
|
So, by the time it fetches the first character and checks the WHILE again the next character hasn't arrived and it exits the loop. I tryed a delay in the loop but that doesn't work.
Any suggestions how to fix this?
Any better ways to deal with receiving a fixed length string?
Thanks,
John |
|
|
Douglas Kennedy
Joined: 07 Sep 2003 Posts: 755 Location: Florida
|
|
Posted: Fri Oct 06, 2006 11:54 am |
|
|
Well if the while loop is inside an interrupt service routine (isr) linked to #rda
it will be called back when the next char arrives. Could it be you don't have the while inside an isr? You need the while loop to exit when there is no pending char so it can give life back to your mainline code. |
|
|
jecottrell
Joined: 16 Jan 2005 Posts: 559 Location: Tucson, AZ
|
|
Posted: Fri Oct 06, 2006 12:11 pm |
|
|
That makes sense!
No the WHILE isn't in the ISR. This isn't the typical INT_RDA driven serial stuff. Andrew has done a pretty nifty set of drivers for HW and SW serial ports and that's what I'm trying to get ported to. (Unfortunately, it's o'dark thirty in Perth right now so I'm on my own until he gets back to me.) I was hoping to have this solved by that time to save him the hassle.
Your nudge will help me look at his code again and maybe figure what's going on a little better. In the mean time I'm rewriting the receive buffer...
Thanks,
John |
|
|
Douglas Kennedy
Joined: 07 Sep 2003 Posts: 755 Location: Florida
|
|
Posted: Fri Oct 06, 2006 2:32 pm |
|
|
Well serial communications is as old as the wheel. It is pretty much perfected already. I don't see any need to have the wheel re-invented but whatever works for you more power to you. This code you purchased has some issues for you but the best solution seems to be to wait for Australia to wake up and help you. If you decide to switch back to the standard approach this board has addressed many of the possible serial communication issues and more than one person can help you. |
|
|
jecottrell
Joined: 16 Jan 2005 Posts: 559 Location: Tucson, AZ
|
|
Posted: Sat Oct 07, 2006 7:57 pm |
|
|
I found my problem fairly quickly and as usual it was self inflicted.
As a novice, I think my $30 investment for some professionally written code was minor. I learned a bunch and got a variety of new ideas of how to deal with every aspect of CCS and C programming. My only mistake was assuming the problem was with the code that I purchased and not my own doing.
John |
|
|
|