1

In MPLAB X IDE v5.10, I am using dspic33ep512mu810 microcontroller.

I have following piece of C code:

#include "xc.h"

_FOSCSEL(FNOSC_FRCPLL) //INT OSC with PLL (always keep this setting)
_FOSC(OSCIOFNC_OFF & POSCMD_NONE) //disable external OSC
_FWDT(FWDTEN_OFF) //watchdog timer off
_FICD(JTAGEN_OFF & 0b11); //JTAG debugging off

void UART2TX(char c) {
    if (U2STAbits.UTXEN == 0)
        U2STAbits.UTXEN = 1; //enable UART TX

    while (U2STAbits.UTXBF == 1); //if buffer is full, wait
    U2TXREG = c;
}

int main(void) {

    //setup internal clock for 80MHz/40MIPS
    //7.37/2=3.685*43=158.455/2=79.2275
    CLKDIVbits.PLLPRE = 0; // PLLPRE (N2) 0=/2 
    PLLFBD = 41; //pll multiplier (M) = +2
    CLKDIVbits.PLLPOST = 0; // PLLPOST (N1) 0=/2
    while (!OSCCONbits.LOCK); //wait for PLL ready

    _U2TXIF = 0;
    _U2TXIE = 0;
    _U2RXIF = 0;
    _U2RXIE = 0;
    //setup UART
    U2BRG = 85; //86@80mhz, 85@79.xxx=115200
    U2MODE = 0; //clear mode register
    U2MODEbits.BRGH = 1; //use high percison baud generator
    U2STA = 0; //clear status register

    //DSPIC33EP512MU810T-I/PT, RP96 as TX pin
    RPOR7bits.RP96R = 3; //

    while (1) {
        UART2TX('H'); 
    }
 }

I am trying to send out 'H' through UART2 with baud rate 115200, but it is not working.

piet.t
  • 11,718
  • 21
  • 43
  • 52
Lewis Liu
  • 67
  • 5

1 Answers1

0

You had to switch RF0 (RP96) aus output:

TRISFbits.TRISF0 = 0;     //make F0 an onput

And you had to switch RFO to digital:

ANSELFbits.ANSF0 = 0;      //make F0 digital
Mike
  • 4,041
  • 6
  • 20
  • 37