News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

i2c

Started by Pepe, Nov 24, 2021, 04:03 PM

Previous topic - Next topic

Pepe

why if I declare in basic

Device = 18F26K22
Declare Xtal = 64
Declare HSCL_Pin PORTB.1
Declare HSDA_Pin PORTB.2

the asm always puts

; I2C PINS USED BY HBUSIN AND HBUSOUT
_I2C_SDA_port = TRISC
_I2C_SDA_pin = 4
_I2C_SCL_port = TRISC
_I2C_SCL_pin = 3


top204

#1
On virtually all devices, the I2C pins are fixed and cannot be moved via PPS.

The PIC18F25K22 device does not have PPS, and most 8-bit devices that have PPS cannot move the I2C pins, so the compiler uses the known pins for the SDA and SCL, as read from the device's .ppi file.

It still places the pin and port values from the declares in the asm file, just in case, but they cannot be used for the MSSP peripheral. For example, the listing:

    Device = 18F26K22
    Declare Xtal = 16
   
    Declare HSDA_Pin = PORTB.0
    Declare HSCL_Pin = PORTB.1
       
    HBusOut 123

Places the following defines in the assembler code:

; ALIAS VARIABLES
#define __HSDA_PORT PORTB
#define __HSDA_PORT_PIN PORTB,0
#define __HSCL_PORT PORTB
#define __HSCL_PORT_PIN PORTB,1

But the Hbus library uses the _I2C_SDA_port, _I2C_SDA_pin and _I2C_SCL_port, _I2C_SCL_pin values because they are the pins that the MSSP peripheral uses and it cannot use any other pins. Some devices have a config fuse setting to use alternative pins, then the .ppi file should be opened and the HBus settings changed. I didn't make the HBus libraries use the declares because it would confuse users who do not know the MSSP peripherl uses fixed pins and would expect I2C on the pins chosen, as is the case with the software I2C commands. Where they come into play is when a user makes an I2C library using an I2C peripheral that can move the pins.

Those declares come into their own with some of the newer devices and some of the PIC24 and dsPIC33 devices that have PPS pins for the I2C peripherals as well.

Pepe

I have modified the ppi for portb but hbus still works in portc in 18f26k22, how can I change to portb?

top204

You cannot change the pins used by the MSSP peripheral with this device in any way.

Some newer 8-bit devices have a secondary pin config fuse for certain peripherals, but the 18F26K22 device does not. Some newer devices allow the I2C pins to be moved via PPS (Peripheral Pin Select), but, again, the 18F26K22 device does not have PPS, so it cannot.

Please.... Read the sections within the device's datasheet for the peripherls being used in the code. For example MSSP for the HBus commands.

tumbleweed

I think maybe Pepe is looking for "HBUS2"... the 26K22 has MSSP2 SCL2/SDA2 on PORTB.1 and PORTB.2