0
\$\begingroup\$

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

\$\endgroup\$
1
\$\begingroup\$

RB1PPS= 0b00001001; //RB1 input PPS

This line only lets me to choose port and pin. It says RB1 is input that is all.

That statement is not correct. As described on page 263:

The peripheral input is selected with the peripheral xxxPPS register (Register 17-1), and the peripheral output is selected with the PORT RxyPPS register (Register 17-2).

In table 17-2 on page 268 it is shown that the value 0b00001001 maps to CCP1 (Capture/Compare/PWM module) which has nothing to do with I2C.

Otherwise your solution 1) is correct except the first two lines which are non needed. Here's the same configuration with my comments:

// map inputs of I2C peripheral 2 (xxxPPS register definition 17-1 on page 265)
// SCL to RB1
I2C2SCLPPS = ((0b001)<<3)   // PORTB
             | 0b001;       // Pin 1
// SDA to RB2
I2C2SDAPPS = ((0b001)<<3)   // PORTB
             | 0b010;       // Pin 2

// map outputs of I2C peripheral 2 (values from table 17-2 on page 268)
RB1PPS = 0b100011;      // SCL to RB1
RB2PPS = 0b100100;      // SDA to RB2
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.