Hot!Cannot connect UART to RB6 on PIC24FJ128GA204

Author
icosmos72
New Member
  • Total Posts : 1
  • Reward points : 0
  • Joined: 2018/07/30 09:21:16
  • Location: 0
  • Status: offline
2018/08/15 09:13:36 (permalink)
0

Cannot connect UART to RB6 on PIC24FJ128GA204

Hi!
Using the RPOR registers, I can successfully connect RB3 or RB15 or other pins to a UART (1-4) ... but not RB6. I don't see anything in the documentation or errata that say RB6 (RP6) is uniquely unavailable. Any guesses?
Here are my RPOR registers when I have RB3, RB6, and RC3 all connected to UART0. RB3 and RC3 operate correctly, but RB6 only operates as a digital output.
03D6    RPOR0   0x0000  0       00000000 00000000   '..'
03D8 RPOR1 0x0300 768 00000011 00000000 '..'
03DA RPOR2 0x0000 0 00000000 00000000 '..'
03DC RPOR3 0x0003 3 00000000 00000011 '..'
03DE RPOR4 0x0000 0 00000000 00000000 '..'
03E0 RPOR5 0x0000 0 00000000 00000000 '..'
03E2 RPOR6 0x0000 0 00000000 00000000 '..'
03E4 RPOR7 0x0000 0 00000000 00000000 '..'
03E6 RPOR8 0x0000 0 00000000 00000000 '..'
03E8 RPOR9 0x0300 768 00000011 00000000 '..'
03EA RPOR10 0x0000 0 00000000 00000000 '..'
03EC RPOR11 0x0700 1792 00000111 00000000 '..'
03EE RPOR12 0x0008 8 00000000 00001000 '..'
Here is how PORTB is set up:
018A    TRISB   0x22A2  8866    00100010 10100010   '"¢'
018C PORTB 0x00C8 200 00000000 11001000 '.È'
018E LATB 0x0040 64 00000000 01000000 '.@'
0190 ODCB 0x0000 0 00000000 00000000 '..'
0192 ANSB 0x2000 8192 00100000 00000000 '..'
... and here are the CONFIG bits:
_CONFIG1(JTAGEN_OFF & GCP_OFF & GWRP_OFF & ICS_PGx1 & FWDTEN_ON & WINDIS_OFF & FWPSA_PR128 & WDTPS_PS1024);
_CONFIG2(IESO_ON & WDTCMX_LPRC & FNOSC_FRC & FCKSM_CSDCMD & OSCIOFCN_ON & POSCMD_NONE)
_CONFIG3(SOSCSEL_ON)
_CONFIG4(IOL1WAY_OFF & PLLDIV_DISABLED & DSWDTPS_DSWDTPS15)
I am hoping that I am missing something silly, but it's being a while now and I can't see it.  Any help appreciated!
 
Thanks.
 
#1

15 Replies Related Threads

    Aussie Susan
    Super Member
    • Total Posts : 3357
    • Reward points : 0
    • Joined: 2008/08/18 22:20:40
    • Location: Melbourne, Australia
    • Status: offline
    Re: Cannot connect UART to RB6 on PIC24FJ128GA204 2018/08/15 19:34:51 (permalink)
    0
    How do you know it is 'no successful'? What are you doing to know?
    How do you know it is operating as a digital output and not UART0 Tx.
    What if you ONLY connect the output to RP6 and not all of the other pins at the same time (I know this should be possible but you may be running into fan-out limitations)?
    Susan
    #2
    dan1138
    Super Member
    • Total Posts : 2868
    • Reward points : 0
    • Joined: 2007/02/21 23:04:16
    • Location: 0
    • Status: offline
    Re: Cannot connect UART to RB6 on PIC24FJ128GA204 2018/08/15 19:59:51 (permalink)
    4 (1)
    I have been trying to help him on Stack Overflow on this thread.
     
    Microchip has a bit in the ANSB register to enable/disable analog input on RB6.
     
    If this bit is set or clear does not appear to affect the UART using RB6 as an output. When this bit is not zero RB6 cannot be used as any kind of digital input.
     
    Nothing in the family reference or datasheet show any actual analog functionality associated with RB6. This seems like a silicon bug but there is nothing in the errata.
     
    Somebody (not me) will need to ask Microchip technical support to "clarify" the functions associated with RB6.
    #3
    davekw7x
    Entropy++
    • Total Posts : 1573
    • Reward points : 0
    • Joined: 2012/01/16 12:01:07
    • Location: Left Coast, USA
    • Status: offline
    Re: Cannot connect UART to RB6 on PIC24FJ128GA204 2018/08/15 23:19:45 (permalink)
    0
    dan1138
    I have been trying to help him on Stack Overflow on this thread.

    You gave the solution there: In order to use RB6 as any kind of digital input (including UART Rx), bit 6 of ANSB must be cleared to zero.
     
    To the OP: You seem to show that bit 6 of ANSB is zero, but we don't know exactly what else is going on in your program.  You didn't show RPINR18 (which contains the bits for U1RXR assignment).
     
    I tested on my PIC24FJ128GA204, and the value of ANSB at reset is 0xF24F.  Bit 6 is 1, as is clearly shown in the Data Sheet.
     
    One problem is that ANSBbits does not include a definition for ANSB6 (I checked XC16 versions 1.30 through 1.35), so you can't write ANSBbits.ANSB6 = 0;  You have to clear it "manually."
    For example, when configuring the UART pins, in addition to the PPS assignments you need something like
    ANSB &= 0xFFBF;

     
    From my test program that echoes received chars and their hex values:
    Compiled on Aug 15 2018 at 23:14:36 PDT by XC16 version 1035
    UART1 Tx on Pin RB5, UART1 RX on Pin RB6
    Value of ANSB at reset          = 0xF24F
    After UART initialization, ANSB = 0xF20F
    ch = T (0x54)
    ch = h (0x68)
    ch = e (0x65)
    ch =   (0x20)
    ch = q (0x71)
    ch = u (0x75)
    ch = i (0x69)


     
    Regards,

    Dave
    post edited by davekw7x - 2018/08/15 23:33:00

    Sometimes I just can't help myself...
    #4
    qɥb
    Monolothic Member
    • Total Posts : 3329
    • Reward points : 0
    • Joined: 2017/09/09 05:07:30
    • Location: Jupiter
    • Status: offline
    Re: Cannot connect UART to RB6 on PIC24FJ128GA204 2018/08/15 23:27:10 (permalink)
    4 (1)
    davekw7x
    ...
    You gave the solution there: In order to use RB6 as any kind of digital input (including UART Rx), bit 6 of ANSB must be cleared to zero.
    ...

    That was my first thought, but in post#1 the OP stated that ANSB contained 0x2000, so bit#6 was clear.
     

    This forum is mis-configured so it only works correctly if you access it via https protocol.
    The Microchip website links to it using http protocol. Will they ever catch on?
    PicForum "it just works"
    #5
    davekw7x
    Entropy++
    • Total Posts : 1573
    • Reward points : 0
    • Joined: 2012/01/16 12:01:07
    • Location: Left Coast, USA
    • Status: offline
    Re: Cannot connect UART to RB6 on PIC24FJ128GA204 2018/08/15 23:36:10 (permalink)
    4 (1)
    qɥb

    That was my first thought, but in post#1 the OP stated that ANSB contained 0x2000, so bit#6 was clear.



    The O.P. didn't show RPINR18, which contains the assignment for U1RXR, (or anything else that he did with the UART or anything else, period), so we can't know why his program does not work.
     
    [Edit]
    Actually, I think I see that TRISB6 is equal to 0.  That won't work if you expect RB6 to be an input.  (The PPS Rx assignment and UART activation will not override TRIS = 0.  Really.  Gotta be an input.)
     [/Edit]
    Bottom line: We need to see some code.  Crystal ball getting cloudy.
     
    Regards,

    Dave
    post edited by davekw7x - 2018/08/15 23:42:08

    Sometimes I just can't help myself...
    #6
    scott@assetlinkglobal.com
    New Member
    • Total Posts : 6
    • Reward points : 0
    • Joined: 2018/07/29 07:39:42
    • Location: 0
    • Status: offline
    Re: Cannot connect UART to RB6 on PIC24FJ128GA204 2018/09/26 08:45:40 (permalink)
    0
     
    Hello all ---
     
    This is the OP; my icosmos72 account complains that I "do not have access" wherever I click on the site.  My apologies for taking so long to work around this forum problem --- other tasks came up, in the usual way, but I did not mean to insult this community or the great help you're providing.
     
    Enclosed is a test program that demonstrates the problem with RB6.  Note that I think someone else had the same problem: https://www.microchip.com/forums/m902128.aspx .  (Is there a way to link these issues?)
     
    Here's the experiment, as embodied in the enclosed program:
    • RB3, RB6, and RB7 are outputs, monitored on a logic analyzer
    • RB3 and RB6 are toggled as digital outputs, to confirm that the logic analyzer is hooked up right
    • RB3, RB6, and RB7 are then connected to UART1
    • UART1 gets some bytes shoved at it
    • Lo and Behold, RB3 and RB7 get those bytes, but RB6 does not:
     
    [image]blob:https://www.microchip.com...495f-8c8d-d4fff6d12260[/image]
     
    Again thank you for your thoughts on this, and my apologies that I disappeared for so long.

    Attached Image(s)

    #7
    qhb
    Superb Member
    • Total Posts : 7526
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: Cannot connect UART to RB6 on PIC24FJ128GA204 2018/09/26 22:17:13 (permalink)
    0
    There's some talk at cross purposes in this topic.
    Many are trying to fix a receive/input problem, but the OP is trying to OUTPUT the TX signal!
     
    Not related to your problem, but
    [1] your pause() function would be better using the built in __delay_ms() function.
     
    [2] Here:
                U1TXREG = i;
                do { status = U1STA; } while (status&0x0100);
                do { status = U1STA; } while (!(status&0x0100));

    Would be cleaner as:
                U1TXREG = i;
               while (U1STAbits.UTXBF);    //wait until U1TXREG is available

    #8
    dan1138
    Super Member
    • Total Posts : 2868
    • Reward points : 0
    • Joined: 2007/02/21 23:04:16
    • Location: 0
    • Status: offline
    Re: Cannot connect UART to RB6 on PIC24FJ128GA204 2018/09/27 01:09:46 (permalink)
    4.5 (2)
    @scott@assetlinkglobal.com

    I built your code as posted using MPLABX v4.05 and XC16 v1.35

    Then programmed my Curiosity board using the PKOB on the board:
    *****************************************************

    Connecting to Starter Kit on Board...

    Currently loaded firmware on Starter Kit on Board
    Firmware Suite Version.....01.51.06
    Firmware type..............dsPIC33F/24F/24H

    Target voltage detected
    Target device PIC24FJ128GA204 found.
    Device ID Revision = 4

    Device Erased...

    Programming...

    The following memory area(s) will be programmed:
    program memory: start address = 0x0, end address = 0x5ff
    configuration memory
    Programming/Verify complete




    The PIC24FJ128GA204 on the Curiosity board is silicon rev B3.

    Your code works as you expected on my Curiosity board.



    Can you tell us more about your specific setup?
    post edited by dan1138 - 2018/09/27 01:17:46
    #9
    scott@assetlinkglobal.com
    New Member
    • Total Posts : 6
    • Reward points : 0
    • Joined: 2018/07/29 07:39:42
    • Location: 0
    • Status: offline
    Re: Cannot connect UART to RB6 on PIC24FJ128GA204 2018/09/27 09:00:20 (permalink)
    0
    Thank you all again for taking the time to look into this.
     
    Here's what I get when clicking "Debug" on the project:
     

    *****************************************************

    Connecting to MPLAB REAL ICE...

    Currently loaded firmware on REAL ICE
    Firmware Suite Version.....01.54.00
    Firmware type..............dsPIC33F/24F/24H

    Target voltage detected
    Target device PIC24FJ128GA204 found.
    Device ID Revision = 0x4

    Device Erased...

    Programming...

    The following memory area(s) will be programmed:
    program memory: start address = 0x0, end address = 0x5ff
    configuration memory
    Programming/Verify complete

    Running


     
    My initial tests were using MPLAB X v4.05, this was v5.05 on a different computer.  Same REAL ICE.
     
    My XC16 license is for 1.23, though the assembly looks fine and it's setting the registers the way I want them.
     

    // Second experiment: connect RB3 (on RPOR1) and RB6 and RB7 (on RPOR3) to UART1, and push some bytes at 9600baud.
    // We see the UART bytes on RB3 and RB7, but not RB6.
    RPOR1 = 0x0300;
    556: 04 30 20 mov.w #0x300, w4
    558: c4 1e 88 mov.w w4, 0x3d8
    0000055a <.LSM23>:
    RPOR3 = 0x0303;
    55a: 34 30 20 mov.w #0x303, w4
    55c: e4 1e 88 mov.w w4, 0x3dc
    0000055e <.LSM24>:
    U1MODE = 0x8000;
    55e: 04 00 28 mov.w #0x8000, w4
    560: 04 28 88 mov.w w4, 0x500
    00000562 <.LSM25>:
    U1STA = 0x2400;
    562: 04 40 22 mov.w #0x2400, w4
    564: 14 28 88 mov.w w4, 0x502
    00000566 <.LSM26>:
    U1BRG = 25;
    566: 94 01 20 mov.w #0x19, w4
    568: 44 28 88 mov.w w4, 0x508
    0000056a <.LSM27>:
    for (i=0; i<20; i++) {
    56a: 00 02 eb clr.w w4
    56c: 04 0f 78 mov.w w4, [w14]
    56e: 11 00 37 bra 0x592 <.L9>
    00000570 <.L12>:
    U1TXREG = i;
    570: 1e 02 78 mov.w [w14], w4
    572: 24 28 88 mov.w w4, 0x504

     
    The board is one whose basic design we've been using since 2012 (using the 64kB version of this chip), using with this processor since 2015, and this is a new spin that adds a header for an XBee-style modem.  There is nothing connected to these nets but the pad ready to receive the modem.  RB6 and RB7 are both routed to this header (what do you call a header when the header pins aren't inserted? "these through-holes") which is one reason I looked at RB7 too, in case there was a labeling error or something.  It's also why I did the intentional digital I/O toggling, to confirm I'm wiggling the net I think I am.  I tried this on two different boards from this run.
     
    As before I would love it if I were just doing something boneheaded --- I implemented a bit-banging version of this which works nicely, but would certainly prefer not to have to maintain that code.  Also, of course, if this is a real issue that is affecting other people, wanted to give them something in their Google search as they banged their head against it.
     
    Could it be the package?  This is the 44-pin TQFP package.
     
    Thank you again for your advice on the example code and for running the example project.  It certainly seems like this is an esoteric problem, but I can't see a way around it yet.
     
    #10
    dan1138
    Super Member
    • Total Posts : 2868
    • Reward points : 0
    • Joined: 2007/02/21 23:04:16
    • Location: 0
    • Status: offline
    Re: Cannot connect UART to RB6 on PIC24FJ128GA204 2018/09/27 17:40:58 (permalink)
    4.5 (2)
    @scott@assetlinkglobal.com

    In post #10 you mentioned that the controller in your PCB is the PIC24FJ64GA204 yet the RealICE session in that post has identified a PIC24FJ128GA204 as the target device.

    The PIC24FJ128GA204 is the device in my Curiosity board and I would expect that the code you posted would behave the same in both places. This it is not doing.

    We are both using a Seleae logic analyzer to capture the outputs of RB3, RB6 and RB7.

    Using the same source code, target device and diagnostic tool we see different results.

    The differences are:

    Compiler: XC16 v1.23 vs v1.35
    Programmer: RealICE vs Starter kit PKOB
    Target HW: (not specified) vs DM240004 PIC24F Curiosity Development Board

    I cannot see how any of these difference can account for the observed behavior.

    The most obvious conclusion is that your PIC24FJ128GA204 target controller is somehow different than mine. Although you have not said as much you have implied that your code behaves the same in other PIC24F target devices.

    Suggestions:

    Try building your code with XC16 v1.35 (free mode) compiler.
    Get a new DM240004 PIC24F Curiosity Development Board and try your code in that.

    Anyone else have an idea?
    #11
    u_Student
    an advanced beginner
    • Total Posts : 29
    • Reward points : 0
    • Joined: 2013/11/27 06:22:21
    • Location: Ireland
    • Status: offline
    Re: Cannot connect UART to RB6 on PIC24FJ128GA204 2018/10/02 05:31:43 (permalink)
    0
    Might be a stupid idea? The whole thing isn't effected by ASCL1?  Is it set in the CONFIG4 part like this: #pragma config I2C1SEL = DISABLE

    Please correct me if I do ANY kind of mistakes, I'm not native in English.
    #12
    scott@assetlinkglobal.com
    New Member
    • Total Posts : 6
    • Reward points : 0
    • Joined: 2018/07/29 07:39:42
    • Location: 0
    • Status: offline
    Re: Cannot connect UART to RB6 on PIC24FJ128GA204 2018/10/04 06:14:21 (permalink)
    0
    Thanks all again for the above suggestions.  They are all fair things to try.  @dan1138, the only board I have with this processor is our product, so you're right that that's a variable I haven't changed.  @u_Student, good thought, and I agree in general that there's often some funny CONFIG with a side effect, but that particular bit is already (left) disabled in the test code.
     
    Still, reasonable things to try, given the time.  Thank you all for donating yours in helping explore this issue.
     
    #13
    u_Student
    an advanced beginner
    • Total Posts : 29
    • Reward points : 0
    • Joined: 2013/11/27 06:22:21
    • Location: Ireland
    • Status: offline
    Re: Cannot connect UART to RB6 on PIC24FJ128GA204 2018/10/04 06:40:14 (permalink)
    0
    @scott, I'm curious about the outcome.
    I have a project with 24FJ64GA202 (It seems to me we working with similar families 202 vs 204) and I also intend to use an UART Rx on that particular RB6 pin. I chosen this uC, because I need 3 independent UART now, and 4 a bit later on, along with a DIP package. I just finished with the basics, so I set the pin functions in the MCC what I need, but not written any source code yet.
     
    Because...
    What I'd like to ask from you, what UART library can I use at XC16/v1.26? Is it available any useful, or I have to write the functions for them myself? I did not seen any GA2xx on the "devices" list.
     
    Thanks.
    in the MCC

    Please correct me if I do ANY kind of mistakes, I'm not native in English.
    #14
    scott@assetlinkglobal.com
    New Member
    • Total Posts : 6
    • Reward points : 0
    • Joined: 2018/07/29 07:39:42
    • Location: 0
    • Status: offline
    Re: Cannot connect UART to RB6 on PIC24FJ128GA204 2018/10/04 07:10:02 (permalink)
    0
    Others on this forum will probably have more direct answers to your question about libraries, but personally, I've found it more direct and insightful to just set the registers.  There are only five you really have to deal with: MODE, STA, BRG, TXREG, and RXREG.  I set them up directly in my test example:
     
    <code>
    U1MODE = 0x8000;
    U1STA = 0x2400;
    U1BRG = 25;
    </code>
     
    ... and then do a blocking loop to transmit (there are suggestions for better blocking logic above, though personally I like making sure the byte is really out the door before returning, and not just in a holding register).  It's definitely personal preference, but with only five registers involved, I'd suggest that it's no harder to learn these five registers than to learn a library's abstraction of them.
     
    The PIC24F Family Reference Manual 21. UART document has sections titled "Setup for..." that walk you nicely through the sequence of what to do.  Also, while I haven't tried it, the MPLAB Code Configurator seems a possible nice middle ground that eases you into writing this code.
     
    Just some thoughts, hope they're helpful!
     
    #15
    u_Student
    an advanced beginner
    • Total Posts : 29
    • Reward points : 0
    • Joined: 2013/11/27 06:22:21
    • Location: Ireland
    • Status: offline
    Re: Cannot connect UART to RB6 on PIC24FJ128GA204 2018/10/04 07:23:28 (permalink)
    0
    @scott  Yes, I know I am a beginner, but I understand what you mean. Thanks for the advice. So I'll do directly with the registers. Actually this project is half live, as it's running on an 8 bit uC (18F26K22) a part of them, but I have to transfer into 16 version.

    Please correct me if I do ANY kind of mistakes, I'm not native in English.
    #16
    Jump to:
    © 2018 APG vNext Commercial Version 4.5