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 ?
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;
}