gsg
Junior Member level 1
hello
I want to test serial communication between dsPIC33FJ128MC202 and PC. I tried the example code given in the dsPIC manual (Section 17 UART). But there is no output at all. I'm checking output on the Hyperterminal of my PC.
Can someone tell me how I can check if the UART module within the dsPIC is working or if there is some other circuit problem? can I see the ASCII output from dsPIC with oscilloscope?
Here's the code:
Please guide me.
I want to test serial communication between dsPIC33FJ128MC202 and PC. I tried the example code given in the dsPIC manual (Section 17 UART). But there is no output at all. I'm checking output on the Hyperterminal of my PC.
Can someone tell me how I can check if the UART module within the dsPIC is working or if there is some other circuit problem? can I see the ASCII output from dsPIC with oscilloscope?
Here's the code:
Code:
#include <p33FJ128MC202.h>
#define FCY 40000000
#define BAUDRATE 9600
#define BRGVAL ((FCY/BAUDRATE)/16)-1
unsigned int i;
int main(void)
{
// Configure Oscillator to operate the device at 40Mhz
// Fosc= Fin*M/(N1*N2), Fcy=Fosc/2
// Fosc= 8M*40(2*2)=80Mhz for 8M input clock
PLLFBD=38; // M=40
CLKDIVbits.PLLPOST=0; // N1=2
CLKDIVbits.PLLPRE=0; // N2=2
OSCTUN=0; // Tune FRC oscillator, if FRC is used
RCONbits.SWDTEN=0; // Disable Watch Dog Timer
while(OSCCONbits.LOCK!=1) {}; // Wait for PLL to lock
U1MODEbits.STSEL = 0; // 1-stop bit
U1MODEbits.PDSEL = 0; // No Parity, 8-data bits
U1MODEbits.ABAUD = 0; // Auto-Baud Disabled
U1MODEbits.BRGH = 0; // Low Speed mode
U1BRG = BRGVAL; // BAUD Rate Setting for 9600
U1STAbits.UTXISEL0 = 0; // Interrupt after one Tx character is transmitted
U1STAbits.UTXISEL1 = 0;
IEC0bits.U1TXIE = 1; // Enable UART Tx interrupt
U1MODEbits.UARTEN = 1; // Enable UART
U1STAbits.UTXEN = 1; // Enable UART Tx
/* wait at least 104 usec (1/9600) before sending first char */
for(i = 0; i < 4160; i++)
{
Nop();
}
U1TXREG = 'a'; // Transmit one character
while(1)
{
}
}
void __attribute__((__interrupt__)) _U1TXInterrupt(void)
{
IFS0bits.U1TXIF = 0; // clear TX interrupt flag
U1TXREG = 'a'; // Transmit one character
}
Please guide me.