PIC16F1779 settings for EUSART


+ Reply to Thread
Results 1 to 10 of 10
  1. #1
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,807

    Default PIC16F1779 settings for EUSART

    I have a hard time understanding how to set port output and input for the Tx/Rx of the USART peripheral.

    Tried the MCC also but the C code is not easy to understand also.

    Any help please on setting the PPS registers? What the heck is xy in the xyPPS?

    Ioannis

  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    2,389


    1 out of 1 members found this post helpful. Did you find this post helpful? Yes | No

    Default Re: PIC16F1779 settings for EUSART

    What the heck is xy in the xyPPS?
    whatever it needs to be
    eg on your chip

    if its an input then xy= the input to the module
    ie.
    RXPPS = 0x09; //RB1->EUSART:RX;
    makes rx on portb.1

    if its an output then xy= the output port/pin for the module
    ie.
    RB0PPS = 0x24; //RB0->EUSART:TX;
    makes tx on portb.0
    Warning I'm not a teacher

  3. #3
    Join Date
    Aug 2011
    Posts
    412


    Did you find this post helpful? Yes | No

    Default Re: PIC16F1779 settings for EUSART

    See the datasheet sect 12.8 (this can be different for each device)

    To map the input use the register shown in 12-1 'xxxPPS peripheral input selection' along with Table 12-1
    To map the EUSART RX, xxxPPS=RXPPS... that's the register you need to set.
    Look back at 12-1 to get the PORT and PIN setting.
    For example, to select PORTB pin 4 the setting would be '--001100', so
    RXPPS = $0C

    To map the output use the register shown in 12-2 'RxyPPS output source selection register'
    along with Table 12-2. 'x' is the PORTx (ie 'A','B', 'C') and 'y' is the pin '0'-'7' (ie 'RB5')
    To map the EUSART TX, the output signal in Table 12-2 is TX/CK which shows RxyPPS = 100100, so
    RB5PPS = $24

  4. #4
    Join Date
    Aug 2011
    Posts
    412


    Did you find this post helpful? Yes | No

    Default Re: PIC16F1779 settings for EUSART

    Also, this is all enabled by the PPSLOCKED bit in the PPSLOCK register, which defaults to 0 (unlocked).
    To set/clear PPSLOCKED you have to follow the sequence shown in sect 12-4 exactly.
    There is also a CONFIG PPS1WAY setting in CONFIG2 which, if set, only allows you to change it once.

    I'd recommend setting CONFIG PPS1WAY = OFF and not setting the PPSLOCKED bit. That way you don't have to bother with it.

  5. #5
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,807


    Did you find this post helpful? Yes | No

    Default Re: PIC16F1779 settings for EUSART

    Thank you Richard and tumbleweed.

    That clears things.

    The versatility of this system is great and helps very much in the PCB layout.

    Ioannis
    Last edited by Ioannis; - 21st May 2023 at 22:05.

  6. #6
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,807


    Did you find this post helpful? Yes | No

    Default Re: PIC16F1779 settings for EUSART

    Seems that I did not quite understood that PPS thing...

    I set the registers as:

    RD2PPS=%00011010 for RD2 as UART output
    and
    RXPPS=%00011011 for RD3 as UART RX input

    Hserout does not spiting anything out. Code follows:

    Code:
    #CONFIG
        __config _CONFIG1, _FOSC_INTOSC & _WDTE_ON & _PWRTE_ON & _MCLRE_OFF & _CP_OFF & _BOREN_ON & _CLKOUTEN_OFF & _IESO_ON & _FCMEN_ON
        __config _CONFIG2, _WRT_OFF & _PPS1WAY_OFF & _ZCD_OFF & _PLLEN_ON & _STVREN_ON & _BORV_LO & _LPBOR_OFF & _LVP_OFF
    #ENDCONFIG
    
    
    OSCCON=%11110000
    
    DEFINE OSC 32          
        
    LATA = %00000000
    LATB = %00000000
    LATC = %00000000 
    LATD = %00000000
    LATE = %00000000
    
    TRISA = %00100011
    TRISB = %00010011
    TRISC = %00000000
    TRISD = %00001000
    TRISE = %00000000
    
    ;*********************************************************************
    ;           ADC Settings
    ;*********************************************************************
    ansela=3
    wpua=0
    anseld=0
    WPUD=0
    ODCOND=0
    ADCON0=%00000001
    ADCON1=%10110000
    ADCON2=%00000000
    
    cm1con0=0
    cm2con0=0
    cm3con0=0
    cm4con0=0
    cm5con0=0
    cm6con0=0
    cm7con0=0
    cm8con0=0
    
    cm1con1=0
    cm2con1=0
    cm3con1=0
    cm4con1=0
    cm5con1=0
    cm6con1=0
    cm7con1=0
    cm8con1=0
    
    cmout=0
    
    
    ;*********************************************************************
    
     ' Set LCD Data port
    DEFINE LCD_DREG PORTD
    ' Set starting Data bit (0 or 4) if 4-bit bus
    DEFINE LCD_DBIT 4
    ' Set LCD Register Select port
    DEFINE LCD_RSREG PORTD
    ' Set LCD Register Select bit
    DEFINE LCD_RSBIT 0
    ' Set LCD Enable port
    DEFINE LCD_EREG PORTD
    ' Set LCD Enable bit
    DEFINE LCD_EBIT 1
    ' Set LCD bus size (4 or 8 bits)
    DEFINE LCD_BITS 4
    ' Set number of lines on LCD
    DEFINE LCD_LINES 2
    ' Set command delay time in us
    'DEFINE LCD_COMMANDUS 1500
    ' Set data delay time in us
    'DEFINE LCD_DATAUS 250
    
    DEFINE ADC_BITS 10 ' Set number of bits in result
    DEFINE ADC_SAMPLEUS 50 ' Set sampling time in uS
    'DEFINE ADC_CLOCK 3
    
    '************************************************************
    '            UART Setup
    '
    DEFINE HSER_RC1STA 90h
    DEFINE HSER_TX1STA 24h				'9600 baud rate, BRGH=1
    DEFINE HSER_BAUD 9600
    define HSER_SPBRG 51
    DEFINE HSER_CLROERR 1
    
    pause 100
    t1con=0
    
    wADC1 var word
    
    DAC1CON0=%10100000   'Enable,right just.,Output enable,Vref
    DAC2CON0=%10100000   'Enable,right just.,Output enable,Vref
    
    DAC1REFH=0
    DAC1REFL=0
    DAC2REFH=0
    DAC2REFL=0
    DACLD=%00000011
    
    '*************    RD2 = UART TX out
    RD2PPS=%00011010
    
    '*************    RD3 = UART RX input
    RXPPS=%00011011
    
    
    lcdout $fe,$1,"Test"
    pause 1500
    
    clear
    
    
    while 1
    
        adcin 0,wADC1
        lcdout $fe,$80,#wADC1,"  "
        toggle latb.5   'LED hertbeat
        DAC1REFL=wADC1.lowbyte
        DAC1REFH=wADC1.highbyte
        DAC2REFL=wADC2.lowbyte
        DAC2REFH=wADC2.highbyte
        DACLD=%00000011
        hserout ["DAC1:",#wADC1,13,10]
        pause 500
    
    wend
    
    end
    The RD2 pin is the output to the RS-232 driver and RD3 the input from driver. The LED is flashing at the proper rate, so program is looping. But no serial output.

    Ioannis
    Last edited by Ioannis; - 24th May 2023 at 22:06.

  7. #7
    Join Date
    Aug 2011
    Posts
    412


    1 out of 1 members found this post helpful. Did you find this post helpful? Yes | No

    Default Re: PIC16F1779 settings for EUSART

    If you look at Table 12-1 Port Selection and Table 12-2 Available Ports For Output you'll find that the EUSART can't be mapped to PORTD, only PORTB and PORTC.

    There are restrictions like this in many of the devices... the PPS matrix isn't a full x-y mux and you usually only get a choice of two ports to pick from.

  8. #8
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,807


    Did you find this post helpful? Yes | No

    Default Re: PIC16F1779 settings for EUSART

    Ooops...

    Thanks,
    Ioannis

  9. #9
    Join Date
    Apr 2014
    Location
    OK
    Posts
    557


    1 out of 1 members found this post helpful. Did you find this post helpful? Yes | No

    Default Re: PIC16F1779 settings for EUSART

    If I may make a suggestion; I noticed when you were trying to use PORTD for UART, you initialized your TX Pin low (LATD = 0). I initialize my UART TX Pin high, as that is the idle state. Secondly, your WPUD didn't take advantage of the ability to bias your RX Pin high as well. You may get a false Start of Signal reading when your companion device initializes. Using a Weak Pull-Up on RX reduces that chance.

  10. #10
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,807


    1 out of 1 members found this post helpful. Did you find this post helpful? Yes | No

    Default Re: PIC16F1779 settings for EUSART

    Thank you Mike for the suggestions. Indeed this is the proper way to initialize the ports. At the moment that was the least of the problems.

    The important thing is to read carefully the datasheet and as tumbleweed noted, I was setting UART on wrong ports.

    Now that I paid more attention and am really awake(!), it works as it should and all is fine.

    The people in this forum are one of a kind. Thank you all.

    Ioannis

Similar Threads

  1. EUSART vs. MSSP
    By keithv in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 15th February 2018, 17:22
  2. EUSART's - Which timers do they use?
    By Christopher4187 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 1st June 2015, 23:06
  3. Any different between USART and EUSART?
    By Demon in forum Off Topic
    Replies: 1
    Last Post: - 2nd February 2014, 09:04
  4. EUSART Stop Receiving
    By CocaColaKid in forum Serial
    Replies: 1
    Last Post: - 27th June 2007, 18:54
  5. Eusart?
    By rastan in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 27th January 2005, 22:50

Members who have read this thread : 10

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts