Electronic – Problem with PIC24F UART

microchippicuart

The problem I am having is with my PIC24FJ64GA002 and the UART module(s). The 24F I have is in a SPDIP28 package and it is a new B5 chip (just one under the latest B8 revision) from Microchip Direct. I have checked for errata issues which afflicted me last time with the I2C module.

Anyway, I am setting the UART1 module up as a simple transmitter. I am using PPS pin RP8 as the RX, RP9 as the TX and RP11 as the CTS pin. For now I have grounded RX and CTS as I do not need them. I have set the BRG at 115,200 (actual rate ~114,285.7, but it's close enough.) I am using the code below. I expect to see a series of bytes streaming out on RP9, but I do not. RB15 is a debug output: it pulses on each byte being sent. On RB15 I get a really slow clock, about 700 Hz, which is very low for a 115,200 baud link; I'd expect about 14 kHz.

#include <p24fj64ga002.h>

#include <uart.h>
#include <pps.h>

void init_osc()
{
    // Must be programmed for FRCPLL mode.
    //UNLOCK_OSC();
    CLKDIVbits.RCDIV = 0;
    //LOCK_OSC();
}

void main()
{
    int i = 0x55;
    PPSUnLock;
    // Initialize oscillator (set FRC to 8 MHz.)
    init_osc();
    // Initialize UART1 PPS.
    iPPSInput(IN_FN_PPS_U1RX, IN_PIN_PPS_RP8);
    iPPSInput(IN_FN_PPS_U1CTS, IN_PIN_PPS_RP11);
    iPPSOutput(OUT_PIN_PPS_RP9, OUT_FN_PPS_U1TX);
    PPSLock;
    // Interrupts disabled for now.
    //ConfigIntUART1(UART_RX_INT_EN | UART_RX_INT_PR6 | UART_TX_INT_EN | UART_TX_INT_PR6);
    OpenUART1(UART_EN & UART_BRGH_SIXTEEN & UART_NO_PAR_8BIT & UART_1STOPBIT, UART_TX_ENABLE, 34);
    TRISBbits.TRISB15 = 0;
    while(1)
    {
        LATBbits.RB15 = 1;
        LATBbits.RB15 = 0;
        while(BusyUART1());
        WriteUART1(i);
        i++;
    }
    CloseUART1();
}

I feel like I have missed something obvious, but cannot figure out what it is. If anyone has had previous experience with the UART module on 24F series devices, please let me know! I've had little luck with the Microchip forums.

Best Answer

See page 110 of the data sheet.

Also, you need to disable the analogue inputs on the pins you are using.