Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

PIC32 UART communication using FTDI packet loss problem?

Status
Not open for further replies.

nick703

Advanced Member level 1
Joined
Oct 17, 2011
Messages
422
Helped
21
Reputation
44
Reaction score
22
Trophy points
1,298
Location
surat
Activity points
3,987
hello friend i have a configure UART on PIC32 using FTDI CHIP FT232RL .

i have completely send and receive string using communication of PIC32 and windows form based application.

My question is i have loss packet some time in run time. i can't identify problem whether problem is controller side or Application side.

is that any FIFO problem of FTDI?
please give me suggestion regard this becuase this problem is coming randomly like some time 1 hour or some time 4 hour or some time 10 min. every time when communication break that time we power off and start it again.

so if FIFO problem then please give me some hint to transmit and receive FIFO code write.
 

Hi,

is that any FIFO problem of FTDI?
From my experience with FT232R...I doubt it.
I found the FTDI devices are very reliable, at least the original ones. No experience with the fake devices.

My assumption of error sources (the most probable one at first)
* microcontroller software (no flow control, not interrupt driven, read/write timing problem...)
* baudrate mismatch
* schematic/ hardware ( floating inputs, error in schematic, EMC...)

Klaus
 

ok then how to handle UART OERR and FERR error?
below is my ISR routine in pic32
Code:
void TimerandUartInit(void)
{
	int    pbClk;

   	pbClk = SYSTEMConfig(SYS_FREQ, SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE);

	OpenUART2(UART_EN |UART_NO_PAR_8BIT | UART_2STOPBITS , 		// Module is ON
		 UART_RX_ENABLE | UART_TX_ENABLE | UART_RX_OVERRUN_CLEAR,// Enable TX & RX
		 pbClk/16/DESIRED_BAUDRATE-1);	// 250000 bps, 8-N-1
        UARTSetFifoMode(UART2, UART_INTERRUPT_ON_TX_NOT_FULL |    UART_INTERRUPT_ON_RX_NOT_EMPTY);
   	ConfigIntUART2(UART_RX_INT_EN | UART_TX_INT_DIS | UART_ERR_INT_EN | UART_INT_PR1 ); 
}
void __ISR(_UART_2_VECTOR, ipl1) IntUart2Handler(void)
{

	if(mU2RXGetIntFlag())
	{
		mLED_1_On();		
	    C[i] = ReadUART2();    // this is store buffer value of each data
		mU2RXClearIntFlag();
		if(C[i] =='\0')         // when receive null char that time counter start to 0
		{
			i = 0; 
			j = 0;
		}
		else
		{
			i++;
		}	
		Delay_us(1);
	}
	if (mU2TXGetIntFlag())
	{
		mU2TXClearIntFlag();
	}
	if(mU2EGetIntFlag())
	{
		mU2EClearIntFlag();
	}
	

} // Uart Handler


i didn't find in c32 example how to handle error in OERR overcome error in UART of pic32.

May be this is problem.
 

Hi,

Baud rate 250,000. The standard PC baud rate is 230,400 not 250,000. Or is it a MIDI interface, or a custom interface?

250,000 baud means a byte every 40us. What input buffersize is in your microcontroller? This determines how long the main loop (or other ISRs) may disable/delay the receive interrupt request.

UART errors:
You have to avoid hardware errors between microcontroller and FTDI.
Imagine: If you detect such an error...what can you do?
* you may light up a LED...but the data is lost anyway?
* or are you using a protocol that allows re-transmit of a data packet?
* if it happens once ... it will happen more often.
* if it happens: then you may expect that you receive erroneous data without detected error. All the data is unreliable.
--> but if it happens during development it is good to know (LED), then you should remove the cause of the issue.

ISR: it should be very short in time. Just store the data in a buffer (and do the pointer handling, setting a flag). Nothing else. Process the data in main loop.
Be sure to empty the whole hardware receive buffer within the ISR. Mind the timing overhead for entering and leaving an ISR.

Klaus
 

I have a one quary i have found OERR in my code.

so suppose we have clear the OERR error that means my communication is working?
or i have to reassign all the value of UART initializtion to reconnect the application.

because i found this problem is overrun error . and my baudrate is setting both side same.
 

I have not used PIC32 UART much. I have used PIC18F. In PIC18F's UART ISR I do like this.

Code:
if((RC1IE_bit) && (RC1IF_bit)) {
        if(OERR1_bit) {
           OERR1_bit = 0;
           CREN1_bit = 0;
           CREN1_bit = 1;
        }
      
        //other code of ISR

}

Maybe you have to do something similar with PIC32.

OEER_bit = Overflow error bit.
CREN_bit = Continious Receive Enable bit.

Also additionally you can also handle framing error.
 

So is that okay Below code for receiver handler
Code:
void __ISR(_UART_2_VECTOR, ipl1) IntUart2Handler(void)
{
	if(IFS1bits.U3ARXIF)
	{
        if(U3ASTAbits.OERR != 0)
        {
            U3ASTAbits.OERR = 0;
            
        }
        else
        {
            if ((U3ASTAbits.FERR != 0) || (U3ASTAbits.PERR != 0))
            {
                dummy = U3ARXREG;
            }
            else
            {
                SerialGetDataBuffer();
            }
        }
        while (U3ASTAbits.URXDA != 0);
       	IFS1bits.U3ARXIF = 0;
	}
	if(IFS1bits.U3ATXIF)
	{
		IFS1bits.U3ATXIF = 0;
	}
	if(IFS1bits.U3ATXIF)
	{
		IFS1bits.U3ATXIF = 0;
	}
} // Uart Handler


when this bit is clear that time how can i start receiver interrupt agian
U3ASTAbits.OERR = 0; ?

should i adding this
U3ASTAbits.URXEN = 0;
U3ASTAbits.URXEN = 1;
 

it would appear that you are using the UART2 ISR to manipulate UART3!
I'm not sure of the actual PIC32 device you are using but it looks like you might be using the XC32 compiler (confirmation of this would be useful).
Don't put in delays into your ISR. I see in an early code snipped you have a 'Delay_us()' call and above you havew a potentially infinite way on the URXDA bit: in the UART RX ISR that is unnecessary and in any other ISR that is potentially disastrous.
On the PIC32 devices I've used, there are 3 UART interrupts: Rx, Tx and error. Typically the names of the vectors are '_UARTx_RX_VECTOR', '_UARTx_TX_VECTOR' and '_UARTx_ERR_VECTOR' (where 'x' is 1, 2 or 3). I can't see what '_UART_2_VECTOR' you are picking up.
Also, there is no need to check for the various IF flags as you will only get the ISR called for the specific situation (Tx completed, Rx completed or error encountered).
[@bailychic - that style of ISR checking is certainly needed for the PIC18 and similar low-range architectures where there are often only 1 or 2 interrupt vectors. However the PIC24/dsPIC33 and PIC32 architectures have multiple interrupt vectors and the way to write ISR code is therefore different.)
The specific questions you are asking about restarting the Rx side are all answered in the MCU's data sheet and the appropriate FRM sections.
Susan
 

Thanks For Reply,

Actully i use Mplab ide v8 and c32 compiler. And my device is PIC32MX795F512L.

_UART_2_VECTOR is for UART3A i read the datasheet and also i have send and recive packet.
Yes Delay_us() and while (U3ASTAbits.URXDA != 0) this is not required.

Code:
	int    pbClk;

   	pbClk = SYSTEMConfig(SYS_FREQ, SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE);

	OpenUART2(UART_EN |UART_NO_PAR_8BIT | UART_2STOPBITS , 		// Module is ON
			 UART_RX_ENABLE | UART_TX_ENABLE | UART_RX_OVERRUN_CLEAR,		// Enable TX & RX
			 pbClk/16/DESIRED_BAUDRATE-1);	// 250000 bps, 8-N-1
    UARTSetFifoMode(UART3A, UART_INTERRUPT_ON_TX_NOT_FULL | UART_INTERRUPT_ON_RX_NOT_EMPTY);
   	ConfigIntUART2(UART_RX_INT_EN | UART_TX_INT_DIS | UART_ERR_INT_EN | UART_INT_PR1 ); 


void __ISR(_UART_2_VECTOR, ipl1) IntUart2Handler(void)
{
	if(IFS1bits.U3ARXIF)
	{
        if(U3ASTAbits.OERR != 0)
        {
	        SerialGetDataBuffer();
            U3ASTAbits.OERR = 0;
            IEC1bits.U3ARXIE = 0;
            IEC1bits.U3ARXIE = 1;
        }
        else
        {
            if ((U3ASTAbits.FERR != 0) || (U3ASTAbits.PERR != 0))
            {
                dummy = U3ARXREG;
                U3ASTAbits.FERR = 0;
                U3ASTAbits.PERR = 0;
            }
            else
            {
                SerialGetDataBuffer();
            }
        }
        //while (U3ASTAbits.URXDA != 0);
       	IFS1bits.U3ARXIF = 0;
	}
	if(IFS1bits.U3ATXIF)
	{
		IFS1bits.U3ATXIF = 0;
	}
	if(IFS1bits.U3AEIF)
	{
		IFS1bits.U3AEIF = 0;
	}
} // Uart Handler

Above is my final code of UART receiver. give me some suggestion of above is that any required any suggestion to i do.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top