1

I will be communicating with some device via SMBus. I use PIC18F26K83 and I will use RB1 and RB2 pins as SCL and SDA pins. My question is about PPS mapping. In datasheet it says that I need to set both of these pins to both input and output. As PPS output selection it is simple because " RxyPPS: PIN Rxy OUTPUT SOURCE SELECTION REGISTER" let's me choose pin,port and SDA/SCL. However, "xxxPPS: PERIPHERAL xxx INPUT SELECTION" register only lets me to choose port and pin. To be more clear let me give an example:

RB1PPS= 0b00001001; //RB1 input PPS

This line only lets me to choose port and pin. It says RB1 is input that is all. On the other hand:

RB1PPS= 0b00100011; // RB1= I2C2 (SCL) output.

This line lets me choose port, pin and also SCL output. It says RB1 is output but also it is SCL.

In datasheet Page: 266 PPS Input register details, there are some register values that I need to use in order to choose input as SDA or SCL. ( I added datasheet)

So my question is: Do I need to choose SDA or SCL for input just like I choose for output? Which code block seems more accurate?

1)

RB1PPS= 0b00001001; //RB1 input PPS
RB2PPS= 0b00001010; //RB2 input PPS
RB1PPS= 0b00100011; // RB1= I2C2 (SCL) output.
RB2PPS= 0b00100100; //RB2= I2C(SDA) output.
I2C2SCLPPS = 0b00001001; // RB1 I2C2 Clock
I2C2SDAPPS= 0b00001010;  // RB2 I2C2 Data

or

2)

RB1PPS= 0b00001001; //RB1 input PPS
RB2PPS= 0b00001010; //RB2 input PPS
RB1PPS= 0b00100011; // RB1= I2C2 (SCL) output.
RB2PPS= 0b00100100; //RB2= I2C(SDA) output

Datasheet: Datasheet of PIC18F26K83

1 Answer 1

1

TRY THIS

/* Unlock PPS */

PPSLOCK = 0x55;
PPSLOCK = 0xAA;
PPSLOCKbits.PPSLOCKED = 0x00;


/* Setting of PPS */

/* RB1 <-> SCL2 */
RB1PPSbits.RB1PPS = 0x23;
I2C2SCLPPS  = 0x09;  

/* RB2 <-> SDA2 */    
RB2PPSbits.RB2PPS = 0x24;
I2C2SDAPPS = 0x0A;

/* Lock PPS */

PPSLOCK = 0x55;
PPSLOCK = 0xAA;
PPSLOCKbits.PPSLOCKED = 0x01;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.