Picproje Elektronik Sitesi

DERLEYİCİLER => Proton+ => Konuyu başlatan: buntger - 12 Eylül 2013, 09:10:23

Başlık: How Connecting dos devices USART one 2EUSART Pic multiplexed.
Gönderen: buntger - 12 Eylül 2013, 09:10:23
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.
Başlık: Ynt: How Connecting dos devices USART one 2EUSART Pic multiplexed.
Gönderen: buntger - 12 Eylül 2013, 11:59:50
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 (http://ww1.microchip.com/downloads/en/DeviceDoc/39931d.pdf)

(http://imageshack.com/scaled/large/22/1riu.jpg)

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

THX
Başlık: Ynt: How Connecting dos devices USART one 2EUSART Pic multiplexed.
Gönderen: Kazım - 12 Eylül 2013, 13:34:10
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
Başlık: Ynt: How Connecting dos devices USART one 2EUSART Pic multiplexed.
Gönderen: Kabil ATICI - 12 Eylül 2013, 13:46:24
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)
Başlık: Ynt: How Connecting dos devices USART one 2EUSART Pic multiplexed.
Gönderen: buntger - 12 Eylül 2013, 13:53:39
THX.
Means, the EUSART2 can be mapped to any of RPx pins of the device.
Başlık: Ynt: How Connecting dos devices USART one 2EUSART Pic multiplexed.
Gönderen: Kazım - 12 Eylül 2013, 13:54:56
@ambar7 çok tecrubeli değilim ama diyotlar ters olması lazım değilmi ?

@ buntger OK.
Başlık: Ynt: How Connecting dos devices USART one 2EUSART Pic multiplexed.
Gönderen: fatih6761 - 12 Eylül 2013, 14:27:44
@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 (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.
Başlık: Ynt: How Connecting dos devices USART one 2EUSART Pic multiplexed.
Gönderen: Kabil ATICI - 12 Eylül 2013, 14:32:25
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)
Başlık: Ynt: How Connecting dos devices USART one 2EUSART Pic multiplexed.
Gönderen: Kazım - 12 Eylül 2013, 14:54:57
İzah ettiğiniz için teşekkür ederim ,anladım durumu
Başlık: Ynt: How Connecting dos devices USART one 2EUSART Pic multiplexed.
Gönderen: buntger - 13 Eylül 2013, 12:26:00
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.
Başlık: Ynt: How Connecting dos devices USART one 2EUSART Pic multiplexed.
Gönderen: buntger - 20 Eylül 2013, 21:20:09
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
Başlık: Ynt: How Connecting dos devices USART one 2EUSART Pic multiplexed.
Gönderen: fatih6761 - 20 Eylül 2013, 21:40:15
@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.
Başlık: Ynt: How Connecting dos devices USART one 2EUSART Pic multiplexed.
Gönderen: buntger - 21 Eylül 2013, 07:38:45
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
Başlık: Ynt: How Connecting dos devices USART one 2EUSART Pic multiplexed.
Gönderen: fatih6761 - 21 Eylül 2013, 15:42:52
@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
Başlık: Ynt: How Connecting dos devices USART one 2EUSART Pic multiplexed.
Gönderen: buntger - 21 Eylül 2013, 20:45:15
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  <-----------------
Başlık: Ynt: How Connecting dos devices USART one 2EUSART Pic multiplexed.
Gönderen: buntger - 24 Eylül 2013, 12:37:36
Hello,
I added the ports manipulation command "TRISA" and I do not work.
I do not know what to do ...

'PORTA.0 = Input
'PORTA.1 = Output

TRISA =% 00000001

''''''''''''' ALL 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

Dim Var1 As Byte

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

Declare All_Digital = True
TRISA = %00000001


;*************************************
; 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


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
Başlık: Ynt: How Connecting dos devices USART one 2EUSART Pic multiplexed.
Gönderen: buntger - 25 Eylül 2013, 12:56:32
Hello,
I've added this Fuse "IOL1WAY" but .. does not work.

Config_Start          'Fuses para el programador QL-2006(MCU ELECTRONICS)
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
WDTPS = 32768 ;1:32768
DSWDTOSC = INTOSCREF ;DSWDT uses INTRC
RTCOSC = T1OSCREF ;RTCC uses T1OSC/T1CKI
DSBOREN = On ;Enabled
DSWDTEN = OFF ;Watch Dog
DSWDTPS = G2 ;1:2,147,483,648 (25.7 days)
MSSP7B_EN = MSK7 ;7 Bit address masking mode
IOL1WAY = OFF ;The IOLOCK bit (PPSCON<0>) can be set once              <----------------------- ADD
Config_End
Başlık: Ynt: How Connecting dos devices USART one 2EUSART Pic multiplexed.
Gönderen: buntger - 02 Ekim 2013, 21:20:27
Hello,
Attempting to operate the 2 Euart the PIC18F46J50. I removed the ASM code for a similar but does not work.
I need your helpThank you ..

This is the New Code.

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 ;No CPU system clock divide
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
WDTPS = 32768 ;1:32768
DSWDTOSC = INTOSCREF ;DSWDT uses INTRC
RTCOSC = T1OSCREF ;RTCC uses T1OSC/T1CKI
DSBOREN = On ;Enabled
DSWDTEN = OFF ;Watch Dog
DSWDTPS = G2 ;1:2,147,483,648 (25.7 days)
IOL1WAY = OFF ;The IOLOCK bit (PPSCON<0>) can be set once
' MSSP7B_EN = MSK7 ;7 Bit address masking mode
'WPFP = PAGE_63 ;Write Protect Program Flash Page 63
' WPEND = PAGE_WPFP ;Page WPFP<5:0> through Configuration Words erase/write protected
WPCFG = OFF ;Configuration Words page not erase/write-protected
WPDIS = OFF ;WPFP<5:0>/WPEND region ignored
Config_End

'Declarations EUSART2
Declare Hserial2_Baud  = 9600       'Set baud rate to 9600
Declare Hserial2_RCSTA = %10010000  'Enable serial port and continuous receive
Declare Hserial2_TXSTA = %00100100  'Enable transmit and asynchronous mode
Declare Hserial2_SPBRG = 77         'Set SPBRG for 12Mhz Xtal
Declare Hserial2_Clear = On         'Optionally clear the buffer before receiving

Declare All_Digital = True    'PortA all Digital
Dim Var1 As Byte

'Configuring USART2
Dim IOLOCK As PPSCON.0
Dim INTCON_GIE As INTCON.7 'global interrupt disable bit (GIEH)
Dim t_gie As Bit           'saved GEIH state

t_gie = 0

t_gie = INTCON_GIE    'save current state of GIE intr bit and disable interrupts
INTCON_GIE = 0
'Unlock PPS configuration
EECON2 = $55         'send sequence to unlock the PPS configuration
EECON2 = $AA
IOLOCK = 0
'Mapping Ports
PPSCON.0=0    'Turn off PPS Write Protect 0
RPINR16=0     'PortA.0= RX2  Mapping Port
RPOR1=5       'PortA.1= TX2  Mapping Port
'Lock PPS configuration
EECON2 = $55
EECON2 = $AA
IOLOCK = 1
If t_gie = 1 Then INTCON_GIE = 1

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



THX.