• AVR Freaks

Hot!Mirroring I2C on PIC16LF18346

Author
iisnsr
New Member
  • Total Posts : 9
  • Reward points : 0
  • Joined: 2019/07/23 07:24:40
  • Location: 0
  • Status: offline
2019/10/03 04:12:08 (permalink)
0

Mirroring I2C on PIC16LF18346

Hi
I'm trying to get an I2C signal mirrored to other pins using the CLC modules using assembly on a PIC16LF18346. Naively, I've configured each of the four input gates to use two inputs each that use the SCL2 for both inputs in CLC1 and SDA2 for both inputs in CLC2. The four gates are then fed into a 4-input AND gate and sent to RC6 or RC7. I thought this would be the best scenario to ensure that the signal is correct, even if heavily repetitive. I'm using MPLAB X IDE v5.25 and MCC to generate C code (haven't found how to get it to do assembly yet) that I've lifted and placed into my code. I've attached the graphical configuration for reference. The code it generates is as follows:
void CLC1_Initialize(void)
{
// Set the CLC1 to the options selected in the User Interface
// LC1G1POL not_inverted; LC1G2POL not_inverted; LC1G3POL not_inverted; LC1G4POL not_inverted; LC1POL not_inverted;
CLC1POL = 0x00;
// LC1D1S SCL2;
CLC1SEL0 = 0x14;
// LC1D2S SCL2;
CLC1SEL1 = 0x14;
// LC1D3S SCL2;
CLC1SEL2 = 0x14;
// LC1D4S SCL2;
CLC1SEL3 = 0x14;
// LC1G1D3N disabled; LC1G1D2N disabled; LC1G1D4N disabled; LC1G1D1T enabled; LC1G1D3T disabled; LC1G1D2T enabled; LC1G1D4T disabled; LC1G1D1N disabled;
CLC1GLS0 = 0x0A;
// LC1G2D2N disabled; LC1G2D1N disabled; LC1G2D4N disabled; LC1G2D3N disabled; LC1G2D2T enabled; LC1G2D1T enabled; LC1G2D4T disabled; LC1G2D3T disabled;
CLC1GLS1 = 0x0A;
// LC1G3D1N disabled; LC1G3D2N disabled; LC1G3D3N disabled; LC1G3D4N disabled; LC1G3D1T enabled; LC1G3D2T enabled; LC1G3D3T disabled; LC1G3D4T disabled;
CLC1GLS2 = 0x0A;
// LC1G4D1N disabled; LC1G4D2N disabled; LC1G4D3N disabled; LC1G4D4N disabled; LC1G4D1T enabled; LC1G4D2T enabled; LC1G4D3T disabled; LC1G4D4T disabled;
CLC1GLS3 = 0x0A;
// LC1EN enabled; INTN disabled; INTP disabled; MODE 4-input AND;
CLC1CON = 0x82;
}
void CLC2_Initialize(void)
{
// Set the CLC2 to the options selected in the User Interface
// LC2G1POL not_inverted; LC2G2POL not_inverted; LC2G3POL not_inverted; LC2G4POL not_inverted; LC2POL not_inverted;
CLC2POL = 0x00;
// LC2D1S SDA2;
CLC2SEL0 = 0x15;
// LC2D2S SDA2;
CLC2SEL1 = 0x15;
// LC2D3S SDA2;
CLC2SEL2 = 0x15;
// LC2D4S SDA2;
CLC2SEL3 = 0x15;
// LC2G1D3N disabled; LC2G1D2N disabled; LC2G1D4N disabled; LC2G1D1T enabled; LC2G1D3T disabled; LC2G1D2T enabled; LC2G1D4T disabled; LC2G1D1N disabled;
CLC2GLS0 = 0x0A;
// LC2G2D2N disabled; LC2G2D1N disabled; LC2G2D4N disabled; LC2G2D3N disabled; LC2G2D2T enabled; LC2G2D1T enabled; LC2G2D4T disabled; LC2G2D3T disabled;
CLC2GLS1 = 0x0A;
// LC2G3D1N disabled; LC2G3D2N disabled; LC2G3D3N disabled; LC2G3D4N disabled; LC2G3D1T enabled; LC2G3D2T enabled; LC2G3D3T disabled; LC2G3D4T disabled;
CLC2GLS2 = 0x0A;
// LC2G4D1N disabled; LC2G4D2N disabled; LC2G4D3N disabled; LC2G4D4N disabled; LC2G4D1T enabled; LC2G4D2T enabled; LC2G4D3T disabled; LC2G4D4T disabled;
CLC2GLS3 = 0x0A;
// LC2EN enabled; INTN disabled; INTP disabled; MODE 4-input AND;
CLC2CON = 0x82;
}
RC6PPS = 0x04; //RC6->CLC1:CLC1OUT;
RC7PPS = 0x05; //RC7->CLC2:CLC2OUT;

and this is to mirror SCL2 to RC6 and SDA2 to RC7. Now I'm confused as the user manual describes SCL2 and SDA2 to be 0x1A and 0x1B respectively according to page 163 and this is what I use in my program with I2C2 working as it should. I've tried both configurations to no avail.
My assembly configuration is:
 banksel PORTC
movlw 0x00
movwf PORTC
banksel LATC
clrf LATC
banksel TRISC
movlw 0x00
movwf TRISC
banksel ANSELC
clrf ANSELC
banksel WPUC
movlw 0x00
movwf WPUC
banksel ODCONC
movlw 0x00
movwf ODCONC
; CLC Config
banksel CLC1POL
clrf CLC1POL
; movlw 0x14
movlw 0x1A
movwf CLC1SEL0
movwf CLC1SEL1
movwf CLC1SEL2
movwf CLC1SEL3
movlw 0x0A
movwf CLC1GLS0
movwf CLC1GLS1
movwf CLC1GLS2
movwf CLC1GLS3
movlw 0x82
movwf CLC1CON

banksel CLC2POL
clrf CLC2POL
; movlw 0x15
movlw 0x1B
movwf CLC2SEL0
movwf CLC2SEL1
movwf CLC2SEL2
movwf CLC2SEL3
movlw 0x0A
movwf CLC2GLS0
movwf CLC2GLS1
movwf CLC2GLS2
movwf CLC2GLS3
movlw 0x82
movwf CLC2CON

banksel RC6PPS
movlw 0x04
movwf RC6PPS
movlw 0x05
movwf RC7PPS

Just to be clear, I am getting correct communication signals from I2C2 but nothing is coming out of pins RC6/RC7. I can appreciate that on the surface there may be no inherent point in doing this; however, I'm trying to build a proof of concept so that I am able to mirror and show signals from other peripherals that I don't have direct access to via on-board test points.

Attached Image(s)

#1

4 Replies Related Threads

    iisnsr
    New Member
    • Total Posts : 9
    • Reward points : 0
    • Joined: 2019/07/23 07:24:40
    • Location: 0
    • Status: offline
    Re: Mirroring I2C on PIC16LF18346 2019/10/04 06:42:08 (permalink)
    0
    Ok, having delved into a number of configurations it looks like a peripheral (at least the I2C) can only be allocated to one resource at any one time, so if routed to pins then that is where they must stay. However, I've managed to configure the CLC to use a CLCIN that has the associate pin connected to it and get the mirrored output that I need.
     
    I've also managed to adjust the CLCs so that they are perhaps more correctly configured.
     
    For interest, I've included the code below as well as the attachment for CLC1 and CLC2 respectively.
     
     banksel CLC1POL
     movlw 0x0E
     movwf CLC1POL
     movlw 0x00
     movwf CLC1SEL0
     movwf CLC1SEL1
     movwf CLC1SEL2
     movwf CLC1SEL3
     movlw 0x02
     movwf CLC1GLS0
     movlw 0x00
     movwf CLC1GLS1
     movwf CLC1GLS2
     movwf CLC1GLS3
     movlw 0x82
     movwf CLC1CON
     
     banksel CLC2POL
     movlw 0x0E
     movwf CLC2POL
     movlw 0x01
     movwf CLC2SEL0
     movwf CLC2SEL1
     movwf CLC2SEL2
     movwf CLC2SEL3
     movlw 0x02
     movwf CLC2GLS0
     movlw 0x00
     movwf CLC2GLS1
     movwf CLC2GLS2
     movwf CLC2GLS3
     movlw 0x82
     movwf CLC2CON

     banksel CLCIN0PPS
     movlw 0x0F
     movwf CLCIN0PPS
     movlw 0x0D
     movwf CLCIN1PPS

     banksel RC6PPS
     movlw 0x04
     movwf RC6PPS
     movlw 0x05
     movwf RC7PPS

    While I can appreciate that I can reduce the code by removing unnecessary banksel instances, and replacing movlw 0x00 with clrf they are essentially to ensure that I have flexibility and sanity checked!

    Attached Image(s)

    #2
    jack527
    New Member
    • Total Posts : 5
    • Reward points : 0
    • Joined: 2016/07/21 23:35:44
    • Location: 0
    • Status: offline
    Re: Mirroring I2C on PIC16LF18346 2020/11/20 07:03:40 (permalink)
    -1 (1)
    How to put some variables in bank1 ? Thanks!
    #3
    ric
    Super Member
    • Total Posts : 28967
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: Mirroring I2C on PIC16LF18346 2020/11/20 13:17:39 (permalink)
    +1 (1)
    jack527
    How to put some variables in bank1 ? Thanks!

    Why have you hijacked someone else's question to ask something totally unrelated?
    Please start your own thread, and explain a bit further
    ** What language you are woirking in (C? Assembler?)
    ** What PIC device you are working on
    ** Why you need something in bank 1
     
    post edited by ric - 2020/11/20 13:19:08

    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!
    #4
    Beau Schwabe
    Starting Member
    • Total Posts : 32
    • Reward points : 0
    • Joined: 2019/09/23 21:16:53
    • Location: 0
    • Status: offline
    Re: Mirroring I2C on PIC16LF18346 2020/11/21 00:27:54 (permalink)
    0
    To the OP ... I had to do something similar using the CLC cells with a PIC18F57K42T-I/PT to redirect where UART serial data was coming and going.
     
    You might also look into IOC (Interrupt On Change) and set the pin to generate a high priority interrupt on a HIGH and LOW transition.  I used this method in combination with the CLC to "reach" a particular port I couldn't reach otherwise.
     
    Note: This exercise was because we already had PCB boards populated and made and there was a requested change from our client.
     
    Additional Note: The DSM (Data Signal Modulator) is another possibility to look into as far as re-directing I/O connectivity.
     
     
    post edited by Beau Schwabe - 2020/11/21 00:34:09
    #5
    Jump to:
    © 2020 APG vNext Commercial Version 4.5