• AVR Freaks

Hot!MCC UART Receive Code not receiving data

Author
kylesams
New Member
  • Total Posts : 13
  • Reward points : 0
  • Joined: 2019/08/16 13:35:24
  • Location: 0
  • Status: offline
2019/09/19 12:57:31 (permalink)
0

MCC UART Receive Code not receiving data

I am working with a PIC32MM0256GPM048 processor and I am using the MCC to configure the UART and generate code with helper functions for receiving and transmitting data. I am trying to read data being transmitted to the processor over an FTDI TX line which is connected to the PIC UART RX line. The data is GPS data which streams 10 lines of data every 1 second from the GPS module.
 
I am trying to read a character from the receive buffer everytime the UART receive buffer is not empty but I never see any data appear in the buffer. I even tried printing what stored in the U2RXREG register and it always contains a NULL pointer. My MCC UART generated read functions are below as well as where I am trying to read the characters in the buffer. Please let me know if you have any tips. I have exhausted myself trying to solve this.
 
 
#1

7 Replies Related Threads

    du00000001
    Just Some Member
    • Total Posts : 3076
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: MCC UART Receive Code not receiving data 2019/09/20 10:57:17 (permalink)
    0
    Does the RX interrupt trigger?

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #2
    kylesams
    New Member
    • Total Posts : 13
    • Reward points : 0
    • Joined: 2019/08/16 13:35:24
    • Location: 0
    • Status: offline
    Re: MCC UART Receive Code not receiving data 2019/09/20 11:21:06 (permalink)
    0
    The RX Interrupt does not seem to be triggering. Any ideas why this is? It seems like my MCC UART configurations are correct...
    #3
    du00000001
    Just Some Member
    • Total Posts : 3076
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: MCC UART Receive Code not receiving data 2019/09/20 11:40:48 (permalink)
    0
    • Interrupt not enabled?
    • Pin not configured as an input ("Analog" disabled where applicable !)
    • Additional UART clock connection required for RX? (check the errata sheet!)
    • ...

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #4
    kylesams
    New Member
    • Total Posts : 13
    • Reward points : 0
    • Joined: 2019/08/16 13:35:24
    • Location: 0
    • Status: offline
    Re: MCC UART Receive Code not receiving data 2019/09/20 12:14:09 (permalink)
    0
    1. All the interrupts for this UART2 are enabled in MCC, I have attached screenshots of my other configuration settings as well
     
    2. In the screenshot with the pin manager grid view at the bottom you can see the U2RX line is configured as an input
     
    3. The errata sheet for the PIC32mm family reads that "The overflow disable feature controlled by the OVFDIS bit is not functional." for the UART, so do I have to specifically clear this bit in the UART initialization function and everytime the ISR triggers? 
     
    You mentioned the UART clock, right now I am using the SYSCLK which is at 24MHz. Should this be ok?

    Attached Image(s)

    #5
    du00000001
    Just Some Member
    • Total Posts : 3076
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: MCC UART Receive Code not receiving data 2019/09/20 15:02:58 (permalink)
    0
    • The pin manager grid is not all and everything! Check the pin manager tab as well!
    • Set a breakpoint at the start of the RX ISR! If it never breaks ... (Usually MCC code requires you to uncomment the interrupt enable code in main().)
    • "UART clock" was meant to denominate the clock output of the BRG. Some PIC UARTS require to explicitly connect this clock to the RX section of the UART.
    • OVF, FERR etc. would currently be the least of your sorrows... Clearing all error bits is certainly an option unless you know better.

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #6
    davekw7x
    Entropy++
    • Total Posts : 1827
    • Reward points : 0
    • Joined: 2012/01/16 12:01:07
    • Location: Second star on the right, straight on till morning
    • Status: offline
    Re: MCC UART Receive Code not receiving data 2019/09/20 22:19:20 (permalink)
    0
    kylesams
    ...PIC32MM0256GPM048... MCC ...trying to read data

    You mention printing, so I assume you have tested it printing something meaningful before trying to tell you what it is reading from the UART.  Right?  That means your UART bit rate is OK and UART Tx is connected in a way that gets to your terminal emulator on your workstation.

    I also assume that you have checked the connections and circuitry in the PIC receive direction.  If you disconnect the FTDI from the PIC and short the FTDI Rx and Tx pins, does it echo properly?  I would assume that you have tested this.

    Well...
    I have a suggestion:  Test the MCC-generated UART functionality in a small project that DOES NOTHING ELSE. That way you won't have to worry about other things in your application that screws the pooch.

    It takes only a few minutes to set it up with MCC.  That's one of the Big Deals about MCC: Once you get used to it, it is really easy (and quick) to do stuff like little test programs.


    Anyhow, here's a little program to test the receiver function that you are trying to use.  I strongly recommend that you just run the program with a production build (no debugger for starters). 

    /*
     * MCC program for PIC32MM0256GPM028 breadboard
     *
     * Uses FRC-PLL to get 24 MHz system clock and PB Clock
     *
     * LED1 on RB0 - Pin  4
     * LED2 on RB1 - Pin  5
     *
     * UART2 at 115200 Bsud
     * Rx on RB13  - Pin 24
     * Tx on RB14  - Pin 25
     *
     *  UART2 is set up to use interrupta.
     *  "Redirect Printf to UART" is also checked so that can use printf()
     *
     * davekw7x
     * September, 2019
     *
     */

    #include "mcc_generated_files/mcc.h"
    #include <stdio.h>
    #include <ctype.h>

    int main()
    {
        SYSTEM_Initialize();
        printf("\r\nCompiled on %s at %s by XC32 version %u\r\n",
                __DATE__, __TIME__, __XC32_VERSION);
        while (1) { // Main loop
            while (!UART2_ReceiveBufferIsEmpty())
            {
                LED2_Toggle();
                uint8_t ch = UART2_Read();
                printf("ch = 0x%02X", ch);
                if (isprint(ch)) {
                    printf(" = '%c'", ch);
                }
                printf("\r\n");
            } // End of Buffer not empty loop
        } // End of Main loop
        // Should never get here!
        return 1;
    } // End of main()



    I tested with MCC plugin version 3.85.1 and XC32 version 2.20

    Here is the output from my terminal emulator (minicom) on my workstation connected by a serial port converter to the '32MM UART pins as I type a few things:

    Compiled on Sep 20 2019 at 21:28:13 by XC32 version 2200
    ch = 0x54 = 'T'
    ch = 0x68 = 'h'
    ch = 0x69 = 'i'
    ch = 0x73 = 's'
    ch = 0x20 = ' '
    ch = 0x69 = 'i'
    ch = 0x73 = 's'
    ch = 0x20 = ' '
    ch = 0x61 = 'a'
    ch = 0x20 = ' '
    ch = 0x74 = 't'
    ch = 0x65 = 'e'
    ch = 0x73 = 's'
    ch = 0x74 = 't'
    ch = 0x2E = '.'
    ch = 0x0D
    ch = 0x0A
    Of course, in your real application you have to service the UART receiver often enough to keep the buffer from filling up.  I usually make the buffers longer than MCC's default 8 bytes.   YMMV (Your Mileage May Vary)

    Anyhow, if this works for you, then go back to your application and see what the heck is going on.  If this doesn't work for you and you have investigated connections and register settings (TRIS, ANSEL, PPS, etc.), maybe you can package your little project and post it.  The zipped file is not all that big.  See Footnote.

    Regards,

    Dave
     
    Footnote:
    In uart2.c, there is a comment that UART2_RxDataAvailable() and a few other functions are "deprecated and will not be supported in future releases."

    When I built the project it I did get a warning about it being deprecated.  With this in mind I replaced the condition on DataAvalable by
    while (UART2_IsRxReady())


    The actual function source code is MUCH simpler.  The DataAvailable function seems to work in this little test, so it may not be "broke" but it is definitely baroque.
     
    An old saying I made up trying to unravel OPC (Other Proples' Code) about a gazillion design reviews ago:
     
    "If it ain't baroque, don't fix it. But if it is, maybe you should try to simplify."
    ---davekw7x
    post edited by davekw7x - 2019/09/20 22:56:34

    Attached Image(s)


    Sometimes I just can't help myself...
    #7
    du00000001
    Just Some Member
    • Total Posts : 3076
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: MCC UART Receive Code not receiving data 2019/09/21 01:20:06 (permalink)
    0
    To clarify: "deprecated" designates items that are still available, but are planned to be removed some time in the future.

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #8
    Jump to:
    © 2019 APG vNext Commercial Version 4.5