News:

Let's find out together what makes a PIC Tick!

Main Menu

Configuring different pin pin function

Started by keytapper, Today at 12:33 PM

Previous topic - Next topic

keytapper

Hello everybody,

As I mentioned here, I stumble to configure USART to a different pin. I just simulating, but nothing comes out and even worse some time simulation gets mad.
This is the case I tried with 12F1840 and 16F1705, both midrange family MCU.
I got an idea like a convert I2C <> UART. This is convenient in some case that UART is already occupied.
Ignorance comes with a cost

top204

#1
The PIC12F1840 device does not have PPS (Peripheral Pin Select), so it cannot move the pins for the USART flexibly, but it does have a method of using an alternative set of pins for TX and RX, and that is by altering the APFCON SFR .

However, the PIC16F1705 does have PPS, and the compiler will automatically adjust the SFRs for it to use the pins chosen in the Declares. See the example, tested, code listing below:

    Device = 16F1705
    Declare Xtal = 8
    Declare Create_Coff = True
'
' Setup USART1, so it can adjust the Baud and the PPS for its TX and RX pins
'
    Declare HRSOut_Pin   = PORTC.0          ' Tell the compiler what pin to use for TX     
    Declare HRSIn_Pin    = PORTC.5          ' Tell the compiler what pin to use for RX
    Declare Hserial_Baud = 9600             ' Set the Baud rate

'-------------------------------------------------------------------------------
' The main program starts here
'
Main:  
    HRSOut1Ln "Hello"

In the assembler code produced by the compiler it will be:

; UART1_ACTUALBAUD = 9615.38
; UART1_BAUDERROR = 0.16
    movlb 0x03
    bcf BAUD1CON,PP_BRG16
    movlw 51
    movwf SP1BRG
    clrf SP1BRGH
    movlw 36
    movwf TX1STA
    movlw 144
    movwf RC1STA
; CONFIGURE HRSOUT1 PPS
    movlb 0x1D
    movlw 20
    movwf RC0PPS
; CONFIGURE HRSIN1 PPS
    movlw 21
    movlb ((RXPPS)>>7)
    movwf RXPPS

On some devices, only certain ports are suitable for certain peripheral PPS, so always read the datasheet to see if the Port and Pin chosen for PPS is suitable.

keytapper

Then is it just to say that is similar for the other MCU with this EUSART module.
I was doubtful, because too many things weren't doing good. Then I made a test for a 12F1840.
It's amazing.
Ignorance comes with a cost