1
\$\begingroup\$

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.

\$\endgroup\$
4
  • \$\begingroup\$ I just did this on the 24FJ, yesterday, as well :) .. And for your setup you will see a 115200/(8+1+1)=11.5kHz tone. \$\endgroup\$
    – tyblu
    Jan 16, 2011 at 6:23
  • \$\begingroup\$ @tyblu Ah yeah... because you've got 8 bits of data, 1 start bit and 1 stop bit. \$\endgroup\$
    – Thomas O
    Jan 16, 2011 at 11:47
  • \$\begingroup\$ I like to debug UARTs by sending UUUU..., which translates to 1010101010*..., giving a baud/2 square wave. (0* is stop bit, and should be slightly longer than other 0 s.) \$\endgroup\$
    – tyblu
    Jan 16, 2011 at 18:42
  • \$\begingroup\$ @tyblu, Good idea. I did that too. You have to be aware though when working at high frequencies as the processor latency between loading the next byte can become a deciding factor. For example, I found at 115,200 baud my MCU could adequately produce a square wave with only a tiny bit of jitter. At 2 Mbaud, it had considerable delay between each byte and no longer resembled a square wave. \$\endgroup\$
    – Thomas O
    Jan 16, 2011 at 21:44

1 Answer 1

2
\$\begingroup\$

See page 110 of the data sheet.

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

\$\endgroup\$
3
  • \$\begingroup\$ Which datasheet? The FRM for UART, the PIC24F datasheet itself, or something else? The PIC24F datasheet has some timer documentation on 129, and the FRM only has 38 pages, am I missing something? Also, I thought that all inputs were by default digital but I will try turning them off anyway, thanks for the suggestion. \$\endgroup\$
    – Thomas O
    Jan 16, 2011 at 3:48
  • \$\begingroup\$ Datasheet for the PIC24FJ64GA002 (39881D.PDF) Should be page 110. The analogue function is mentioned there. \$\endgroup\$ Jan 16, 2011 at 3:59
  • \$\begingroup\$ Ah, turns out the problem wasn't analog inputs, but JTAG on the pins being enabled (the same as for I2C.) But it got me thinking about it being some peripheral conflict. Thanks! :) \$\endgroup\$
    – Thomas O
    Jan 16, 2011 at 16:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.