Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PIC32 Big problems with UART, also damned OERR
05-06-2013, 04:11 PM, (This post was last modified: 05-06-2013, 04:13 PM by moreno.)
#1
PIC32 Big problems with UART, also damned OERR
Hi

Are four days that I struggle with the serial ports, until I used transmission port, I haven't found any problem but, using even the receiver nothing work properly.

The problem is the strange behaviour of the UART about Overrun Error, when this error occurs the receiver stop working and no interrupt are generated.


The code inside serial.c which manages UART's interrupts is very poor and do not have any check on receiving errors.
In a real program, with standard code, after 2000/3000 characters received, UART hang and no more characters are received (transmission continue working regularly).


As a first attempt, I tried to enable the interrupt handling errors INT_UART1_ERROR but nothing change, the interrupt is never generated.
If I put the code of INT_UART1_ERROR before the code of INT_UART1_RECEIVER the interrupt is generated continuously, very strange.


Finally I found a partial solution of the problem.
I modified the code of INT_UART1_RECEIVER from


Code:
    // Is this an RX interrupt from UART1 ?
    #if defined(PIC32_PINGUINO_220)||defined(GENERIC32MX250F128)||defined(GENERIC32MX220F032)
    if (IFS1bits.U1RXIF)
    #else    
    if (IntGetFlag(INT_UART1_RECEIVER))
    #endif
    {
        SerialGetDataBuffer(UART1);
        #if defined(PIC32_PINGUINO_220)||defined(GENERIC32MX250F128)||defined(GENERIC32MX220F032)
        IFS1bits.U1RXIF=0;
        #else    
        IntClearFlag(INT_UART1_RECEIVER);
        #endif
    }

To

Code:
    // Is this an RX interrupt from UART1 ?
    #if defined(PIC32_PINGUINO_220)||defined(GENERIC32MX250F128)||defined(GENERIC32MX220F032)
    if (IFS1bits.U1RXIF)
    #else    
    if (IntGetFlag(INT_UART1_RECEIVER))
    #endif
    {
                if (U1STAbits.OERR != 0)
                 U1STAbits.OERR = 0;
                else
                do
                 {
                  if ((U1STAbits.FERR != 0) || (U1STAbits.PERR != 0))
                   dummy = U1RXREG;
                  else
           SerialGetDataBuffer(UART1);
                 }
                while (U1STAbits.URXDA != 0);

        #if defined(PIC32_PINGUINO_220)||defined(GENERIC32MX250F128)||defined(GENERIC32MX220F032)
        IFS1bits.U1RXIF=0;
        #else    
        IntClearFlag(INT_UART1_RECEIVER);
        #endif
    }

In this manner I can send even 100.000 characters without problems but with real communications sometime even this code fails.

To put a patch at the problem I added this code

Code:
if (U1STAbits.OERR != 0)
U1STAbits.OERR = 0;

in a periodic loop.
Each 300mS the program check if there is a Overrun Error and eventually clear it to restart communications.


With these modification my program never fails to communicate.
I created a network with 4 cards which communicate with a PC (I use RS485)
After 6 hours of heavy traffic in one card, 247 overrun managed by interrupt and 152 managed by loop are occurred.

This is sufficient for my necessity but some question remain open.

- Why overrun interrupts are generated so frequently?

- Why is impossible work correctly with INT_UART1_ERROR?

Can someone help me?

May be a good idea improve serial.c library.


Bye Bye, Moreno
Reply
06-06-2013, 11:48 AM,
#2
RE: PIC32 Big problems with UART, also damned OERR
Hi Moreno,
I don't have any answer to your question, sorry ...
I was just thinking it's maybe time to get a Google Code account to commit all your improvements for PIC32 (serial.c but also ds18b20.c and maybe some other files ...).
What do you think about it ?
It is easier to complain than it is to do, but it is better to do than it is to complain.
Reply
06-06-2013, 01:33 PM,
#3
RE: PIC32 Big problems with UART, also damned OERR
Hi

Ehm, I haven't any experience about Google Code account, I'm fear to do disaster.
Can you give me more information how joint to the project??


Bye Bye, Moreno
Reply
07-06-2013, 09:39 AM,
#4
RE: PIC32 Big problems with UART, also damned OERR
Hi Moreno,
All you need is a gmail account and a SVN client (TortoiseSVN for Windows, RapidSVN for Linux for ex.). You will find thousands of tutorials on Internet how to use SVN.
I would recommend you to create a local version and a SVN version (aka working copy) of Pinguino on your computer. You can make changes on your local copy then, once everything is fine, replace files in your SVN copy and synchronize it with the SVN server.
If you do something wrong, it's always possible to get back to any previous version.
It is easier to complain than it is to do, but it is better to do than it is to complain.
Reply
07-06-2013, 11:04 AM, (This post was last modified: 07-06-2013, 11:04 AM by Zardoz.)
#5
RE: PIC32 Big problems with UART, also damned OERR
One time that you begin to use source control version, you will think "How I live without it?". It's a great tool for any that make code. Not only because allow you to undo specific previous changes, but It allow to share your code with a team or a community, and collective edit/make code without messing it.
I'm afraid that I have a blog : zardoz.es
Reply
07-06-2013, 01:17 PM,
#6
RE: PIC32 Big problems with UART, also damned OERR
Hi

I have already all the necessary programs and I have my local SVN copy which I use has source of my local working copies.

My doubts are of practical

- How associate my gmail address to the project
- How do in case of mistake

I tried to update with tortoiseSVN the 18b20 code but I receive error "405 Method not allowed), I think are necessary some kind of credential, correct??


Bye Bye, Moreno
Reply
10-06-2013, 08:56 AM,
#7
RE: PIC32 Big problems with UART, also damned OERR
Before anything, you need to send your gmail address to me so I can create your account.

(07-06-2013, 01:17 PM)moreno Wrote: Hi

I have already all the necessary programs and I have my local SVN copy which I use has source of my local working copies.

My doubts are of practical

- How associate my gmail address to the project
- How do in case of mistake

I tried to update with tortoiseSVN the 18b20 code but I receive error "405 Method not allowed), I think are necessary some kind of credential, correct??


Bye Bye, Moreno
It is easier to complain than it is to do, but it is better to do than it is to complain.
Reply
10-06-2013, 12:50 PM,
#8
RE: PIC32 Big problems with UART, also damned OERR
Hi

OK I sent you a PM message.


Bye Bye, Moreno
Reply
10-06-2013, 12:52 PM,
#9
RE: PIC32 Big problems with UART, also damned OERR
Done.
Welcome aboard and thanks for your help.
Régis

(10-06-2013, 12:50 PM)moreno Wrote: Hi

OK I sent you a PM message.


Bye Bye, Moreno
It is easier to complain than it is to do, but it is better to do than it is to complain.
Reply
11-06-2013, 09:42 PM,
#10
RE: PIC32 Big problems with UART, also damned OERR
Hi

Ok, for the moment, all work fine.

Yesterday I updated 18b20 library and today the serial library.
I added a new function Serial.ClearRxError to remove pending error and re enable receiver.


Bye Bye, Moreno
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)