How Connecting dos devices USART one 2EUSART Pic multiplexed.

Başlatan buntger, 12 Eylül 2013, 09:10:23

buntger

Hello,
It is the first time that I have full communication ports, I2C, USB, EUSART, I'm using the PIC 18F46J50 and this has 2 EUSART, one I use for GPS, the other EUSART2 but would need the datasheet I see that are multiplexed.
I like to know how they connect. If the two devices are connected to the same bus RX / TX. Summarizing How to connect two devices in the pic USART EUSART1 and EUSART2 that are multiplexed.

THX.

buntger

Only there 2 pins TX1 and RX1 but the TX2 AND RX2 are multiplexed. View image.
or look datasheet PIC 18F46J50: http://ww1.microchip.com/downloads/en/DeviceDoc/39931d.pdf



The scheme of Figure 1 would be correct. or not!!! or as would the connection?.

THX

Kazım

I was't used this pheripheral . I'm not sure but  it's seems to be related  section  10.7 Peripheral Pin Select (PPS)

İnput and  OutPut Mapping ..

Examine this sections

Kabil ATICI

may be.

not use any component to 18F46J50- TX
use the diode to the  18F46J50- RX (OR gate)

example:

                                        -----------|>|--------TX (device1)
                                       |
18F46J50- RX   ------------|
                                       |
                                        -----------|>|--------TX (device2)

                                        ------------------RX (device1)
                                       |
18F46J50- TX   ------------|
                                       |
                                        ------------------RX (device2)
ambar7

buntger

THX.
Means, the EUSART2 can be mapped to any of RPx pins of the device.

Kazım

@ambar7 çok tecrubeli değilim ama diyotlar ters olması lazım değilmi ?

@ buntger OK.

fatih6761

@buntger
Alıntı YapIt's all in section 10 of the data sheet.

Basically, you will notice some pins of the IC have RP numbers, these are the Remappable Pins.

For inputs to the IC, use RPINRxx = RP number. For example the RPINR for the second USART (RX) is RPINR16 and you want it mapped to pin RP23 so use RPINR16=23.
For outputs from the IC use RPORxx = function number, where xx is the RP number and the function number comes from table 10.14 in the data sheet. So you would use RPOR24=05.

It makes sense when you read section 10.

Note that the remapping registers are protected so you must follow the procedure shown in example 10.7 to unlock them before they can be assigned and then re-lock them again afterwards.
http://www.edaboard.com/thread231274.html

Example from datasheet:
;*************************************
; Unlock Registers
;*************************************
; PPS registers are in
BANK 14
MOVLB 0x0E
BCF INTCON, GIE ; Disable interrupts
; for unlock sequence
MOVLW 0x55
MOVWF EECON2, 0
MOVLW 0xAA
MOVWF EECON2, 0
; Turn off PPS Write Protect
BCF PPSCON, IOLOCK, BANKED
;***************************
; Configure Input Functions
; (See Table 10-13)
;***************************
;***************************
; Assign RX2 To Pin RP0
;***************************
MOVLW 0x00
MOVWF RPINR16, BANKED
;***************************
; Configure Output Functions
; (See Table 10-14)
;***************************
;***************************
; Assign TX2 To Pin RP1
;***************************
MOVLW 0x05
MOVWF RPOR1, BANKED
;*************************************
; Lock Registers
;*************************************
MOVLW 0x55
MOVWF EECON2, 0
MOVLW 0xAA
MOVWF EECON2, 0
; Write Protect PPS (if desired)
BSF PPSCON, IOLOCK, BANKED

Table 10-13 shows input mapping to functions.
10-14 shows output mapping to functions.
These mappings are only needed if you'll use EUSART2 module.
if you use ESUART1, no mapping required.
In section 10.7.2 Available peripherals:
Alıntı Yapthe MSSP1 and EUSART1 modules are not routed through the PPS module.
If you setup EUSART1 module, function inp. and outp. are directly connected to RX1-TX1 pins. If you setup EUSART2 module then you have to map these pins.

Kabil ATICI

Alıntı yapılan: graski - 12 Eylül 2013, 13:54:56
@ambar7 çok tecrubeli değilim ama diyotlar ters olması lazım değilmi ?

@ buntger OK.
Bu konu bazen kafa karıştırıcı oluyor. Bunu bilgisayar tarafına göre mi yoksa işlemci tarafına göre belirtin bilemiyorum.
İşlemci tarafında TX çıkışı lojik 1'de durur ve lojik-0 (galiba 50ms civarında olacak) başlangıç biti gelir ve sonra veri gönderilir ardından çıkış lojik-1 sonlandırma biti olarak  işlem bitirilir.
Buna göre  eğer diyotları ters koyarsak her halikarda sürekli olarak işlemci RX bacağına lojik1'de kalır ve lojik-0 hükmü olmaz.

Burada ise 1. ve 2. aletlerin TX uçları zaten sürekli lojik 1 konumdadır ve iletişime geçtiği zaman lojik-0'larda ancak aktif ana işlemcinin RX bacağı etkilenir. (burada ana işlemcinin RX bacağına  pull-up direnci eklemek yerinde bir seçim olur)
ambar7

Kazım

İzah ettiğiniz için teşekkür ederim ,anladım durumu

buntger

Hello,
I'll report on my progress, be if this work ... connecting two devices a pic TX2/RX2 mapping the other pins RPxx.
Thank you.

buntger

Hello again...
I'm trying with this code and does not work. missing something!!! , is the first time that mapping these ports.
Thanks.

'-----------Code---------------
Device =  18F46J50      'PIC Selection
Declare Xtal 12        'FIX XTAL to 12Mhz

Config_Start          'Fuses
WDTEN = OFF ;Disabled - Controlled by SWDTEN bit
PLLDIV = 3 ;Divide by 3 (12 MHz oscillator input)
STVREN = On ;Enabled
XINST = OFF ;Enabled Extended intruction disable
Debug = OFF ;Disabled
CPUDIV = OSC1
CP0 = OFF ;Program memory is not code-protected
OSC = HS 'HSPLL ;HS+PLL, USB-HS+PLL
T1DIG = On ;Secondary Oscillator clock source may be selected
LPT1OSC = OFF ;High-power operation
FCMEN = OFF ;Disabled  fail-safe clock monitor
IESO = On ;Enabled   'two-speed start-up
Config_End

All_Digital = TRUE ' Set PORTA to all digital

Dim Var1 As Byte

'Maping Ports
RPINR16= 4   'Set RB1 to be RX2
RPOR3  = 5   'Set RB0 to be TX2

'Declarations EUSART2
Declare Hserial2_Baud  = 9600       
Declare Hserial2_RCSTA = %10010000 
Declare Hserial2_TXSTA = %00100100 
Declare Hserial2_SPBRG = 77   
Declare Hserial2_Clear = On 

Loop:
HSerIn2 1000, Timeout, [Var1] ' Receive a byte serially into Var1
   Print Dec Var1, " " ' Display the byte received
GoTo Loop ' Loop forever

Timeout:
Cls
Print "Timed Out" ' Display an error if Hserin2 timed out
DelayMS 500
Stop

End

fatih6761

@buntger, take a look at my last message.
; for unlock sequence
MOVLW 0x55
MOVWF EECON2, 0
MOVLW 0xAA
MOVWF EECON2, 0
; Turn off PPS Write Protect
BCF PPSCON, IOLOCK, BANKED

You cannot configure pin mapping without turning off protection. Please read Section 10 carefully.
Microchip C Compilers for PIC18 have PPS library.

buntger

Hello,
Now I add the asm code but doesn`t work..

'------- CODE ------------
Device =  18F46J50      'PIC Selection
Declare Xtal 12        'FIX XTAL to 12Mhz

Config_Start          'Fuses
WDTEN = OFF ;Disabled - Controlled by SWDTEN bit
PLLDIV = 3 ;Divide by 3 (12 MHz oscillator input)
STVREN = On ;Enabled
XINST = OFF ;Enabled Extended intruction disable
Debug = OFF ;Disabled
CPUDIV = OSC1
CP0 = OFF ;Program memory is not code-protected
OSC = HS 'HSPLL ;HS+PLL, USB-HS+PLL
T1DIG = On ;Secondary Oscillator clock source may be selected
LPT1OSC = OFF ;High-power operation
FCMEN = OFF ;Disabled  fail-safe clock monitor
IESO = On ;Enabled   'two-speed start-up
Config_End

All_Digital = TRUE ' Set PORTA to all digital

Dim Var1 As Byte
Dim BANKED As Byte

Asm
;*************************************
; Unlock Registers
;*************************************
; PPS registers are in BANK 14
Movlb 0x0E
Bcf INTCON, GIE ; Disable interrupts
; for unlock sequence
Movlw 0x55
Movwf EECON2, 0
Movlw 0xAA
Movwf EECON2, 0
; Turn off PPS Write Protect
Bcf PPSCON, IOLOCK, BANKED
;***************************
; Assign RX2 To Pin RP0=PORTA.0
;***************************
Movlw 0x00
Movwf RPINR16, BANKED
;***************************
; Assign TX2 To Pin RP1=PORTA.1
;***************************
Movlw 0x05
Movwf RPOR1, BANKED
;*************************************
; Lock Registers
;*************************************
Movlw 0x55
Movwf EECON2, 0
Movlw 0xAA
Movwf EECON2, 0
; Write Protect PPS (if desired)
Bsf PPSCON, IOLOCK, BANKED
EndAsm

'Maping Port
RPINR16= 0  'Para RX2 (Mapeo RX2 Pin19=RP0=RA0)
RPOR1  = 1  'Para TX2 (Mapeo TX2 pin20=RP1=RA1)

'Declarations EUSART2
Declare Hserial2_Baud  = 9600       
Declare Hserial2_RCSTA = %10010000 
Declare Hserial2_TXSTA = %00100100 
Declare Hserial2_SPBRG = 77   
Declare Hserial2_Clear = On 

Loop:
HSerIn2 1000, Timeout, [Var1] ' Receive a byte serially into Var1
   Print Dec Var1, " " ' Display the byte received
GoTo Loop ' Loop forever

Timeout:
Cls
Print "Timed Out" ' Display an error if Hserin2 timed out
DelayMS 500
Stop

End

fatih6761

@buntger, mapping inputs and outputs are different. For mapping RX2 input to RP0, u use RPINR16 = 0. But for mapping TX2 to outputs, RPORx = 0x05
x means RPx number. 0x05 is the function code of TX2. For mapping TX2 to RP1 you should use RPOR1 = 0x05

buntger

Hello fatih6761.
First of all thx for your patience and time.

Now I've changed RPOR1 = 5, I think these two lines left over at the end of asm code. (RPINR16 = 0 and RPOR1 = 5),
because they are in the asm code, anyway I have taken and I have put time and does not work.

I think the asm code it was ok.!!!

_________________________________________________________

' dim BANKED as byte
'Asm
;*************************************
; Unlock Registers
;*************************************
; PPS registers are in BANK 14
Movlb 0x0E
Bcf INTCON, GIE ; Disable interrupts
; for unlock sequence
Movlw 0x55
Movwf EECON2, 0
Movlw 0xAA
Movwf EECON2, 0
; Turn off PPS Write Protect
Bcf PPSCON, IOLOCK, BANKED
;***************************
; Assign RX2 To Pin RP0=PORTA.0
;***************************
Movlw 0x00                                                'OK?  <-----------------
Movwf RPINR16, BANKED                            'OK?  <-----------------
;***************************
; Assign TX2 To Pin RP1=PORTA.5
;***************************
Movlw 0x05                                               'OK?  <-----------------
Movwf RPOR1, BANKED                              'OK?  <-----------------
;*************************************
; Lock Registers
;*************************************
Movlw 0x55
Movwf EECON2, 0
Movlw 0xAA
Movwf EECON2, 0
; Write Protect PPS (if desired)
Bsf PPSCON, IOLOCK, BANKED
'EndAsm


'Maping Port
'RPINR16= 0                                       'Deleted Line  <-----------------
'RPOR1  = 5                                        'Deleted Line  <-----------------