News:

;) This forum is the property of Proton software developers

Main Menu

I2C pins

Started by kcsl, Jul 18, 2021, 03:53 PM

Previous topic - Next topic

kcsl

I'm confused...
Running Positrol8 and building a project for the 18F45K22, can I use ANY pins I want for the I2C SDA and SCL pins ? I actually want to use PORTE.0 / PORTE.1

The documentation mentions MSSP for all the legacy Hbus commands implying you must use the correct pins (H for hardware I assume), but there's no mention of MSSP in the IC2In/Out commands so it looks like you can use any pins you like.
Is this correct ?

Thanks,
Joe

There's no room for optimism in software or hardware engineering.

Gamboa

Joe,

You have two options:
1.- Use the PIC hardware for I2C in this sense the pins are fixed by hardware. Check if that hardware can be redirected with PPS registers. Hbusin / Hbusout command.
2.- Use software routines to provide I2C connection. In this case you set the communication pins. Commands Busin / Busout, I2Cin / I2Cout.
Think of them as two totally different methods to perform the same function.

You can read the explanation in the manual to see the requirements of each method.

Regards,
Gamboa
Long live for you

Stephen Moss

#2
There is a third option which is to write your own code to use the MSSP module, reading a writing data from/to the SSPBUF and reading/setting the relevant register bits yourself. I have not done that for I2C but have for SPI.

As Gamboa indicated, when using the compilers software (Bit-Bashing) I2C/Serial commands you can direct SDA & SCL to any available I/O pin, however when using the MSSP module either with the compilers hardware commands or writing your own code the options for selecting which pins are used for SDA and SCL may be either...
None - pins are fixed as the device has either no PPS function or no PPS function for the MSSP module.
Limited - device has simple PPS function for the MSSP module, generally only permitting selection between two preset pairs of I/O pins, selection is usually set by a single register bit.
Variable - device has complex PPS function for the MSSP module permitting the SDA and SCL to be connected to a number different I/O pins as determined by the value written to the relevant RPI and RPO registers.

Whether to use bit-bashed or hardware serial will depend upon whether or not you want the PIC to be doing other things during data transmission/reception (Hardware), pin availability and the complexity of the hardware vs software solution particular when the chosen device is incompatible with the compilers hardware serial commands and you have to write you own code for it. 
I may be wrong but a quick look at the data sheet for the 18F45K22 shows that your choices when using the MSSP module are either PortB (RB1 & RB2) or Port C (RC3 & RC4) depending on which of the two available MSSP modules you use. So the only option for PortE is to use the compilers software I2C commands.