|
|
View previous topic :: View next topic |
Author |
Message |
Guest
|
Software and hardware Uarts problem |
Posted: Tue Jan 11, 2005 3:24 am |
|
|
Hi guys,
I am using a Hard uart (HU) for most of my app, and i use 2 soft uarts (SU) for debug and another gadget.
When i use the HU for comms, then use a SU to tell me what is happening, the SU responds with garbage immediately after the HU finishes the comms. The SU only works perfectly when the HU is idle. The code works and proceeds to the next instruction, but i want to remove the debug code and can't run past the 'while(!OKd);'
I think it could be a delay or FERR issue, but using a delay hasn't helped and i'm about to look at the FERR error in more detail. Or should i consider swithing off the Interrupt when using the SU?
(Keep in mind for the examples below that 'rsGSM' is a HU, and 'rsCOM' is a SU, both tested on their own and found to work without flaw.)
Eg
If i send:
Code: |
do
{
fprintf(rsGSM,"AT\r\n"); // Send AT, then wait for OK
fputs("InMSG=",rsCOM); // Send the captured contents of the interrupt buffer
fputs(InMSG,rsCOM); // InMSG is the buffer in the UART interrupt handler
// I get garbage from rsCOM here^
if(strstr(InMSG,AuxStr))
{
OKd = TRUE;
fputs("\r\n Good 100\r\n",rsCOM);
}
else
{
// Error or OK not aquired
fputs("\r\n Error 100\r\n",rsCOM);
}
while(!OKd);
fputs("AT OK'd",rsCOM);
// rsCOM behaves, and sends a clean message here ^
|
The code above works, and proceed to the next section of code, but the 'fputs(InMSG,rsCOM);' part just after sending AT sends garbage.
In short my problem is:
Now i want to remove the fputs(InMSG,rsCOM); and preceeding line to speed things up a little, and when i do, i can't get past While(!OKd); what should i be looking for? |
|
|
Ttelmah Guest
|
|
Posted: Tue Jan 11, 2005 3:38 am |
|
|
What you describe, is both expected, and normal.
The software UART, _requires_ that the chip is doing nothing else. You can with great care, at high clock rates, sometimes program a very slow SU, while still doing some other tasks, but in general this is the exception.
From your description, you are trying to use the SU, while also doing hardware serial I/O, presumably with interrupts occurring for both transmit and receive. The timing errors this produces, will result in garbage.
There are some possible ways that have been used in the past. One approach (which applies if the 'software' rate is the same, or faster than the rate used for the hardware channel), is to disable interrupts on a 'per character' basis during the software transmit, and allow interrupts to occur only between the characters. I have published a 'wrapper' function to do this on a couple of occasions in the past. For very slow software transmission rates, it is possible to write your own 'bit banged' routine, based on using one of the hardware timers, rather than the software timings used in the CCS implementation.
If the data rates do not lend themselves to these approaches, and/or you need receive operation on the other channels, while also doing I/O on the HU, then I',m afraid that you ether need to look at a PIC with more serial ports, or add some external UARTs. I have used the MAX3100 in the past to give muliple hardware serial streams.
Best Wishes |
|
|
Guest
|
|
Posted: Tue Jan 11, 2005 5:15 am |
|
|
Thanks Ttelmah,
You seem to have hit the nail on the head.
I was expecting that the HU stops the SU, does it's business, and then hand-over to the SU again. Not to return a duff string.
I had removed the SU code in the trouble region, and replaced it with a delay (of upto 1200ms during tests). I was expecting that the HU would have enough time to get the response message and proceed to the next part of my program. But it failed, why?
Regarding more HU's, could i use AND gates to multiplex the HW? |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
|
Guest
|
|
Posted: Tue Jan 11, 2005 9:22 am |
|
|
Nice one!
But what about my other question?:
Quote: |
I had removed the SU code in the trouble region, and replaced it with a delay (of upto 1200ms during tests). I was expecting that the HU would have enough time to get the response message and proceed to the next part of my program. But it failed, why?
|
regards |
|
|
Ttelmah Guest
|
|
Posted: Tue Jan 11, 2005 3:58 pm |
|
|
Anonymous wrote: | Nice one!
But what about my other question?:
Quote: |
I had removed the SU code in the trouble region, and replaced it with a delay (of upto 1200ms during tests). I was expecting that the HU would have enough time to get the response message and proceed to the next part of my program. But it failed, why?
|
regards |
Without seeing all the code that is running, hard to tell. One thought would be that you have used a delay in the HU interrupt handler. Also have you got 'errors' set in the #use RS232 statement?.
Best Wishes |
|
|
|
|
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
|