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.

[PIC] UART2 doesnt print any thing.

Status
Not open for further replies.

Raady Here

Full Member level 5
Joined
Jun 8, 2013
Messages
242
Helped
26
Reputation
52
Reaction score
26
Trophy points
28
Location
India
Activity points
1,571
pic24FJ256GA110
MPLAB 8.88

Hi,

I am trying to print using the second UART it prints nothing on hyperteminal, but UART1 works fine.
Its a development board so I guess it wouldnt be any hardware connection error.
To use UART2 any setting recommended ?

Code:
void INIT_UART(void)
{

	/*Configuration of UART */

	__builtin_write_OSCCONL(OSCCON & 0xbf);		// Unlock Registers
	// UART 1
	_U1RXR 			= 30;						// U1RX - i/p RP3
    _RP16R 			= 3;						// U1TX - o/p RP16
	// UART 2
	_U2RXR			= 17;						// U2RX - i/p RP17
    _RP15R			= 5;						// U2TX - o/p RP15
	__builtin_write_OSCCONL(OSCCON | 0x40); 	// Lock Registers

	U1BRG 			= 103;//416;		// FRC no PLL
	U1MODE 			= 0x8008;					
	U1STAbits.UTXEN = 1;
	
	U2BRG 			= 103;//416;		// FRC no PLL
	U2MODE 			= 0x8008;					
	U2STAbits.UTXEN = 1;
	
	IFS0bits.U1RXIF = 0;						// clear interrupt flag of rx
	IEC0bits.U1RXIE = 1;						// enable rx recieved data interrupt

	IFS1bits.U2RXIF = 0;						// clear interrupt flag of rx
	IEC1bits.U2RXIE = 1;						// enable rx recieved data interrupt
	puts1UART((unsigned char *)"UART1 ready");
	puts2UART((unsigned char *)"UART2 ready");
}

unsigned char writeUART1(unsigned char data)
{
	while(U1STAbits.UTXBF==1);
	U1TXREG = data;
	return data;
}

unsigned char writeUART2(unsigned char data)
{
	while(U2STAbits.UTXBF==1);
	U2TXREG = data;	
	return 	data;
}

unsigned char readUART1(void)
{
	unsigned char data;
	while(U1STA & 0x8000); 
	while ( U1STAbits.URXDA==0);
	data = U1RXREG;
	return data;
}
unsigned char readUART2(void)
{
	unsigned char data;
	while(U2STA & 0x8000); 
	data = U2RXREG;
	writeUART2(data);
	return data;
}

void __attribute__((interrupt, no_auto_psv)) _U1RXInterrupt( void)
{
	IFS0bits.U1RXIF = 0;		// clear interrupt flag of rx	 			
}

void __attribute__((interrupt, no_auto_psv)) _U2RXInterrupt( void)
{
//	unsigned char data;
	
	IFS1bits.U2RXIF = 0;		// clear interrupt flag of rx
//	IEC1bits.U2RXIE = 0;		// enable rx recieved data interrupt
//	while(U2STAbits.URXDA & 0x8000);		
//	data	= U2RXREG;
//	writeUART2(data);	
//	IFS1bits.U2RXIF = 0;		// clear interrupt flag of rx
//	IEC1bits.U2RXIE = 1;		// enable rx recieved data interrupt	 			
 }

int puts1UART(unsigned char name[])
{
	unsigned int i=0;
	unsigned char txt;
	while(name[i] !='\0')
	{   
		txt = name[i];
		writeUART1(txt) ;
		i++;
	} 
	return 0;
}

int puts2UART(unsigned char name[])
{
	unsigned int i=0;
	unsigned char txt;
	while(name[i] !='\0')
	{   
		txt = name[i];
		writeUART2(txt) ;
		i++;
	} 
	return 0;
}
 

I have made corrections w.r.t PPS for second UART , but it didn't work.
Code:
// UART 2 
_U3RXR = 17; // U2RX - i/p RP17
_RP15R = 28; // U2TX - o/p RP15

IFS5bits.U3RXIF = 0; // clear interrupt flag of rx
IEC5bits.U3RXIE = 1; // enable rx recieved data interrupt

 

unsigned char writeUART3(unsigned char data)
{
while(U3STAbits.UTXBF==1);
U3TXREG = data; 
return data;
}

 

int puts3UART(unsigned char name[])
{
unsigned int i=0;
unsigned char txt;
while(name[i] !='\0')
{ 
txt = name[i];
writeUART3(txt) ;
i++;
} 
return 0;
}


I used sp3232ebcy-lt/R for connecting. in the schematic it doesnt look like any multiplexing done. they are connected separately. UART 1 - 51(RP16, TX) & 52(RP30,RX) pins , UART 2 - 53(RP15,TX) & 50(RP17,RX) pins.
 

In first program you used

Code C - [expand]
1
2
3
4
5
6
// UART 1
_U1RXR          = 30;                       // U1RX - i/p RP3
_RP16R          = 3;                        // U1TX - o/p RP16
// UART 2
_U2RXR          = 17;                       // U2RX - i/p RP17
_RP15R          = 5;


In second program

Code C - [expand]
1
2
3
// UART 2 
_U3RXR = 17; // U2RX - i/p RP17
_RP15R = 28; // U2TX - o/p RP15


are not they same set of pins ?
 

Zip and post the complete project files and mention which compiler you are using, C30 or XC16 ?
 

In first program you used

Code C - [expand]
1
2
3
4
5
6
// UART 1
_U1RXR          = 30;                       // U1RX - i/p RP3
_RP16R          = 3;                        // U1TX - o/p RP16
// UART 2
_U2RXR          = 17;                       // U2RX - i/p RP17
_RP15R          = 5;


In second program

Code C - [expand]
1
2
3
// UART 2 
_U3RXR = 17; // U2RX - i/p RP17
_RP15R = 28; // U2TX - o/p RP15


are not they same set of pins ?

Yes they are not the same set of pins, though schematic showed its TX2 for uart2, pins are as UART 1 - 51(RP16, TX) & 52(RP30,RX) pins , UART 2 - 53(RP15,TX) & 50(RP17,RX). so need to configure UART3 for the processor.
even then it didn't work.

- - - Updated - - -

Zip and post the complete project files and mention which compiler you are using, C30 or XC16 ?

Im using MPLAB C30 complier v3.31.View attachment NGTproject.rar
 

You are just using the same code for two UARTs but one is working and another one is not working.

Why don you interchange them one by one like,

code of U3 first and U1 second

pins of U1 to U3 and
pins of U3 to U1

In this process you will find the reason for your problem. Please report me after doing this, I cant execute the code bcs proteus is not having pic24F.
 

Which pins are you using for UART1 and UART3 Rx and Tx ?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top