[SOLVED] dsPIC33F UART problem

Status
Not open for further replies.

rsmith8917

Newbie level 3
Joined
Feb 14, 2013
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,320
Hello, I am trying to connect my dsPIC33FJ64GP802 to my PC over RS232 and I'm having difficultly getting it set up. This chip operates on 3.3v, so I am running the TX pin to an opamp to bump it up to 5v, and then running that to the MAX232. I've verified that 0v input gives me +8.5v out and 3.3v in gives me -8.5v out, so I think the hardware is ok but I don't see any data at all on the PC when I run my code. I am using a slightly modified version of the example code in the user guide (see below). I have an 8MHz crystal connected and I am using the C30 compiler (I also tried XC16 with no luck there either). Any help would be greatly appreciated.

Thanks!

#include <p33FJ64GP802.h>
#include <uart.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 40 MHz
// Fosc = Fin * M/(N1 * N2), Fcy = Fosc/2
// Fosc = 8M * 40(2 * 2) = 80 MHz for 8M input clock
PLLFBD = 38;// M = 40
CLKDIVbits.PLLPOST = 0; // N1 = 2
CLKDIVbits.PLLPRE = 0; // N2 = 2
OSCTUNbits.TUN = 0; // Tune FRC oscillator, if FRC is used
RCONbits.SWDTEN = 0; // Disable Watch Dog Timer

RPOR1bits.RP2R = 3; //Map pin 6 (RP2) to UART TX

TRISB = 0;

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
}

- - - Updated - - -

Nevermind, I figured it out...I had my TX and RX lines crossed :roll:
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…