I'm trying to use the SHT Click library. My code below compiles without any problems. I am using the Pic18F46K22 processor. I want to read the SHT31 Sensor.
However, I see in the __ep_generic_I2C.mbas and __epp_generic_I2C.mbas library files that Port.C3 and Port.C4 pins are used by default for I2C communication. I want to use any two of the PortA or PortE pins as SOFTWARE I2C pins.
The reason why I cannot use the default PortC.3 and PortC.4 pins in the library is that there is a device performing SPI communication on these pins.How should I edit? Or is it possible to use a software I2C pin in the sht click library?
In the file __epv8_P18F45K22_I2C.mbas I see a special coding for PIC18F45K22. In this file, there is a subroutine for PORTD.0 and PORTD.1 in the _i2cInit_3 definition. Can similar software I2C communication be done for the PIC18F46K22 processor?
Thanks.
Davut
Code: Select all
program Click_SHT_PIC
include Click_SHT_types
include Click_SHT_config
sub procedure systemInit()
mikrobus_gpioInit(_MIKROBUS1, _MIKROBUS_INT_PIN, _GPIO_INPUT)
mikrobus_gpioInit(_MIKROBUS1, _MIKROBUS_RST_PIN, _GPIO_OUTPUT)
mikrobus_i2cInit(_MIKROBUS1, @_SHT_I2C_CFG[0])
mikrobus_logInit(_LOG_USBUART, 9600)
Delay_ms(100)
end sub
sub procedure applicationInit()
sht_i2cDriverInit(T_SHT_P(@_MIKROBUS1_GPIO), T_SHT_P(@_MIKROBUS1_I2C), SHT_I2C_ADDR0)
mikrobus_logWrite("System Initialized", _LOG_LINE)
Delay_ms(100)
end sub
sub procedure applicationTask()
dim
temperature as float
humidity as float
text as char[15]
Delay_ms(1500)
temperature = sht_temp_ss()
FloatToStr(temperature, @text[0])
mikrobus_logWrite("Temperature: ", _LOG_TEXT)
mikrobus_logWrite(@text[0], _LOG_TEXT)
mikrobus_logWrite("°C", _LOG_LINE)
Delay_ms(200)
humidity = sht_hum_ss()
FloatToStr(humidity, @text[0])
mikrobus_logWrite("Humidity: ", _LOG_TEXT)
mikrobus_logWrite(@text[0], _LOG_TEXT)
mikrobus_logWrite("%", _LOG_LINE)
Delay_ms(200)
end sub
main :
systemInit()
applicationInit()
while (1)
applicationTask()
wend
end.
Code: Select all
module __ep_generic_I2C
include __t_PIC
#IFDEF ENABLE_I2C THEN
sub function _i2cInit_1 (dim cfg as ^const uint32_t) as T_mikrobus_ret
sub function _i2cInit_2 (dim cfg as ^const uint32_t) as T_mikrobus_ret
#ENDIF
implements
const _MIKROBUS_ERR_I2C as byte = 4
' ------------------------------------------------------------ SYSTEM SPECIFIC '
#IFDEF ENABLE_I2C THEN
sub function _i2cInit_1 (dim cfg as ^const uint32_t) as T_mikrobus_ret
dim arg1 as ^const uint32_t
arg1 = (cfg + 0)
ANSELC.B3 = 0
ANSELC.B4 = 0
Result = 0
select case (arg1^)
case 100000 I2C1_Init( 100000 )
case 400000 I2C1_Init( 400000 )
case else Result = _MIKROBUS_ERR_I2C
end select
end sub
sub function _i2cInit_2 (dim cfg as ^const uint32_t) as T_mikrobus_ret
dim arg1 as ^const uint32_t
arg1 = (cfg + 0)
ANSELC.B3 = 0
ANSELC.B4 = 0
Result = 0
select case (arg1^)
case 100000 I2C1_Init( 100000 )
case 400000 I2C1_Init( 400000 )
case else Result = _MIKROBUS_ERR_I2C
end select
end sub
#ENDIF
end.