• AVR Freaks

Hot!Using UART on a Pin with Analog support

Author
Ekkehard
New Member
  • Total Posts : 12
  • Reward points : 0
  • Joined: 2018/01/01 16:25:16
  • Location: 0
  • Status: offline
2019/06/22 03:00:47 (permalink)
4 (1)

Using UART on a Pin with Analog support

Hello,
Summary:Using an UART receiver input on a Pin which supports Analoginput signals may fail, because the AD1PCFG register is not configured properly. Setting AD1PCFG = 0xFFFF solves the problem.
 
Details:
Used device is a PIC24FJ64GA104 in a 44-Pin case.
I spend a long time to get the UART input on physical pin 11 (AN11/C1INC/RP13/PMRD/REFO/CN13/RB13 ) running. While the UART configuration was straight forward, I was stucking in the configuration of the pin itself. Using my scope, I could see that the UART output was sending, and my attached device was answering correctly and the signal arrived at the input pin.
The final problem was the default (reset) setting in the AD1PCFG register. All bits there are set to '0', which enables(!) the analog feature. It seems that this has precedence to other features, esspecially the _U2RXR = 13 instruction, which assigns the UART2 input to the pin.
Strange enough this seems not to be the case, when the UART used to transmitt (in my setup physical Pin 24 (AN5/C1INA/RP3/SCL2/CN7/RB3), with instruction _RP3R  = 3, which assigns UART1 transmitter to pin RP3).
After setting AD1PCFG = 0xFFFF, which disables all analog input pins, the whole thing was running.
I am writing this in the hope, that someone may find this helpful, since nothing was found in the internet regarding this problem.
Greets Ekkehard
#1

7 Replies Related Threads

    ric
    Super Member
    • Total Posts : 22661
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: Using UART on a Pin with Analog support 2019/06/22 03:22:20 (permalink)
    0
    Ekkehard
    ...
    I am writing this in the hope, that someone may find this helpful, since nothing was found in the internet regarding this problem.

    Nothing?
    It is spelt out in the PIC datasheet that analog capable pins must be switched from analog to digital mode to be used as inputs.
    This is the same for all PICs, and has been discussed hundreds of time on this forum.
     
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #2
    Ekkehard
    New Member
    • Total Posts : 12
    • Reward points : 0
    • Joined: 2018/01/01 16:25:16
    • Location: 0
    • Status: offline
    Re: Using UART on a Pin with Analog support 2019/06/22 04:33:01 (permalink)
    0
    Hi ric,
    maybe I am blind, but none of my search approaches with the combination of the words "UART" "Input" "Problem" "PIC24" etc. lead to an post that helps me out. Neither in the forum search, nor via a search engine. Even after I was sure that the analog part of the pin might cause the trouble, the added word "Analog" points to something useful.
    The datasheet says only:
    Note 1: If UARTEN = 1, the peripheral inputs and outputs must be configured to an available RPn pin. 
    SeeSection 10.4 “Peripheral Pin Select (PPS)” for more information.
    which I have done. In the PPS Section is stated
    10.4.2 AVAILABLE PERIPHERALS(...)Peripheral Pin Select is not available for I2C™ changenotification inputs, 
    RTCC alarm outputs or peripheralswith analog inputs .
    The sentence makes obviously no sense, since the physical pin 11 (AN11/C1INC/RP13/PMRD/REFO/CN13/RB13 ) combines RP13 with AN11.
    I had expected to read a hint somewhere.
    Even in the Analog Port Pins section the description is unclear, since I am not reading the PORT register because the UART is active.


    10.2 Configuring Analog Port Pins
    (...)
    When reading the PORT register, all pins configured as
    analog input channels will read as cleared (a low level).
    At the end, the thing is running :-)
    #3
    MBedder
    Circuit breaker
    • Total Posts : 6767
    • Reward points : 0
    • Joined: 2008/05/30 11:24:01
    • Location: Zelenograd, Russia
    • Status: offline
    Re: Using UART on a Pin with Analog support 2019/06/22 04:52:58 (permalink)
    0
    RTFM would have solved your "problem" very efficiently and quickly.
    #4
    mbrowning
    Just a Member
    • Total Posts : 1419
    • Reward points : 0
    • Joined: 2005/03/16 14:32:56
    • Location: Melbourne, FL
    • Status: offline
    Re: Using UART on a Pin with Analog support 2019/06/22 06:28:49 (permalink)
    0
    MBedder
    RTFM would have solved your "problem" very efficiently and quickly.
    Very true. Section 10.2 Configuring Analog Port Pins
    wasn’t hard to find even using the pdf reader on my eyephone

    Oh well - there's always next year
    #5
    davekw7x
    Entropy++
    • Total Posts : 1766
    • Reward points : 0
    • Joined: 2012/01/16 12:01:07
    • Location: Left Coast, USA
    • Status: offline
    Re: Using UART on a Pin with Analog support 2019/06/22 09:56:32 (permalink)
    5 (2)
    First of all: Congrats to the OP for being able to track down and fix the problem and being brave enough to post his findings trying to help other folks who haven't had experience with stuff like this. (And, therefore, running the gauntlet between rows of world-wise and world-weary PIC wonks)
     
    mbrowning
    MBedder
    RTFM would have solved your "problem" very efficiently and quickly.
    Very true. Section 10.2 Configuring Analog Port Pins
    wasn’t hard to find even using the pdf reader on my eyephone



    Well the info is really there, and even though the data sheet is only a little more than 300 pages long, it might not be so quick to get to the bottom of things efficiently.  A lot of people don't get it.  ("It" being the fact that PPS input function pin assignment does not take into account analog/digital considerations on certain pins.)
     
    More specifically and explicitly, in the section about PPS:
     

    10.4.5 CONSIDERATIONS FOR
               PERIPHERAL PIN SELECTION
    .
    .
    .

    A final consideration is that Peripheral Pin Select functions
    neither override analog inputs, nor reconfigure
    pins with analog functions for digital I/O. If a pin is
    configured as an analog input on device Reset, it must
    be explicitly reconfigured as digital I/O when used with
    a Peripheral Pin Select.

     
    Regards,

    Dave

    Sometimes I just can't help myself...
    #6
    Ekkehard
    New Member
    • Total Posts : 12
    • Reward points : 0
    • Joined: 2018/01/01 16:25:16
    • Location: 0
    • Status: offline
    Re: Using UART on a Pin with Analog support 2019/06/24 03:22:56 (permalink)
    0
    Thank you for your warm words and citing the correct description of the problem in the manual. As always, if found the problem and created a solution, all people including we self, think that it sounds simple to solve. And RTFM is a short notice..
    Greetings Ekkehard
    P.S.: I know that companies tend to hide there solutions to protect there USP, good for companies, bad for us developers.
    #7
    oliverb
    Super Member
    • Total Posts : 180
    • Reward points : 0
    • Joined: 2009/02/16 13:12:38
    • Location: 0
    • Status: offline
    Re: Using UART on a Pin with Analog support 2019/06/24 03:39:19 (permalink)
    0
    IMO that analog thing is still a heck of a "gotcha" even now. It is easier on newer PIC18 parts where there's a nice 1:1 correspondance between port, latch, tris and ansel bits, but I still sometimes get a port left in analog mode.
     
    In the latest case I was trying to configure bidirectional I/O pins for a GLCD, using MCC. I seem to need to set them as inputs in order to get them configured properly digital.
    #8
    Jump to:
    © 2019 APG vNext Commercial Version 4.5