diff --git a/pic/PIC_HAL.tbs b/pic/PIC_HAL.tbs index c3800a2..953dc55 100644 --- a/pic/PIC_HAL.tbs +++ b/pic/PIC_HAL.tbs @@ -17,25 +17,25 @@ function pic_reg_read(addr as word,length as byte)as string exit function end if - i2c.start() + si2c_start() - i2c.write(PIC_CHIP_ADDR_W) - i2c.write(PIC_CMD_R) + si2c_write(PIC_CHIP_ADDR_W) + si2c_write(PIC_CMD_R) tmp=addr / 256 - i2c.write(tmp) + si2c_write(tmp) tmp=addr or 256 - i2c.write(tmp) + si2c_write(tmp) - i2c.stop() - i2c.start() - i2c.write(PIC_CHIP_ADDR_R) + si2c_stop() + si2c_start() + si2c_write(PIC_CHIP_ADDR_R) for tmp=1 to length-1 - data=data+chr(i2c.read(ACK)) + data=data+chr(si2c_read(ACK)) next tmp - data=data+chr(i2c.read(NACK)) + data=data+chr(si2c_read(NACK)) pic_reg_read=data - i2c.stop() + si2c_stop() end function function pic_reg_write(addr as word, data as string)as ok_ng @@ -47,23 +47,23 @@ function pic_reg_write(addr as word, data as string)as ok_ng pic_reg_write=NG if data="" then exit function - i2c.start() + si2c_start() - i2c.write(PIC_CHIP_ADDR_W) - i2c.write(PIC_CMD_W) + si2c_write(PIC_CHIP_ADDR_W) + si2c_write(PIC_CMD_W) tmp=addr/256 - i2c.write(tmp) + si2c_write(tmp) tmp=addr or 256 - i2c.write(tmp) + si2c_write(tmp) buf="" for pos=1 to len(data) buf=mid(data,pos,1) - i2c.write(asc(buf)) + si2c_write(asc(buf)) next pos - i2c.stop() + si2c_stop() pic_reg_write=OK end function diff --git a/pic/pic_gra.tbs b/pic/pic_gra.tbs index 2b90ec7..62aa869 100644 --- a/pic/pic_gra.tbs +++ b/pic/pic_gra.tbs @@ -66,11 +66,6 @@ function pic_init(byref signature as string, use_ssi as no_yes, byref fw_str as pic_use_ssi=use_ssi channel=si2c_register(signature,data_pin,clk_pin,use_ssi) - i2c.num=channel - i2c.sdamap=data_pin - i2c.sclmap=clk_pin - i2c.enabled=YES - '7.RXDTSEL 0 = RX/DT function is on RC5 '6.SDOSEL 0 = SDO function is on RC2 '5.SSSEL 1 = SS function is on RA3 @@ -300,7 +295,7 @@ sub pic_config(num as pic_pin_enum, f as pic_func_enum, int_pin as byte, channel end if #endif - i2c.num=channel + si2c_get(channel) if pic_func(num)<>f then if pic_func(num)=PIC_FUNC_PWM then @@ -353,7 +348,7 @@ sub pic_config(num as pic_pin_enum, f as pic_func_enum, int_pin as byte, channel #if PLATFORM_ID=TPP3W or PLATFORM_ID=TPP2W or PLATFORM_ID=TPP3WG2 or PLATFORM_ID=TPP2WG2 if pic_func(num)=PIC_FUNC_UART then - i2c.num=channel + si2c_get(channel) 'Disable uart before we change to another function 'SPEN = 0 s=pic_reg_read(PIC_RCSTA,1) @@ -748,7 +743,7 @@ sub pic_adc_config( p as pic_adc_ref_positive_voltage,n as pic_adc_ref_negative_ dim value,value2 as byte dim s as string - i2c.num=channel + si2c_get(channel) s=pic_reg_read(PIC_ADCON1,1) value=asc(s) @@ -956,8 +951,7 @@ function pic_adc_get(ch as pic_adc_enum, channel as byte)as word end if end select - - i2c.num=channel + si2c_get(channel) pic_reg_write(PIC_ADCON0,chr(value)) @@ -995,7 +989,7 @@ sub pic_io_enabled(num as pic_pin_enum, en as no_yes, channel as byte) if pic_func(num)<>PIC_FUNC_IO then exit sub - i2c.num=channel + si2c_get(channel) select case num case PIC_PIN0: 'RC5 @@ -1085,7 +1079,7 @@ sub pic_io_set(num as pic_pin_enum, state as low_high, channel as byte) if pic_func(num)<>PIC_FUNC_IO then exit sub - i2c.num=channel + si2c_get(channel) select case num case PIC_PIN0: 'RC5 @@ -1176,7 +1170,7 @@ function pic_io_get(num as pic_pin_enum, channel as byte)as low_high pic_io_get=LOW - i2c.num=channel + si2c_get(channel) select case num case PIC_PIN0: 'RC5 @@ -1286,7 +1280,7 @@ sub pic_pwm_config(ch as pic_pwm_enum, pulse_width as word,period as word, presc if pic_func(ch)<>PIC_FUNC_PWM then exit sub - i2c.num=channel + si2c_get(channel) select case ch case PIC_PWM0: @@ -1384,7 +1378,7 @@ sub pic_pwm_start(ch as pic_pwm_enum, channel as byte) if pic_func(ch)<>PIC_FUNC_PWM then exit sub - i2c.num=channel + si2c_get(channel) select case ch case PIC_PWM0: if pic_func(0)<>PIC_FUNC_PWM then exit sub @@ -1432,7 +1426,7 @@ sub pic_pwm_stop(ch as pic_pwm_enum, channel as byte) if pic_func(ch)<>PIC_FUNC_PWM then exit sub - i2c.num=channel + si2c_get(channel) select case ch case PIC_PWM0: @@ -1527,7 +1521,7 @@ sub pic_pwm_duty_set(ratio as word, pwm_channel as byte, channel as byte) ratio=1000 end if - i2c.num=channel + si2c_get(channel) s=pic_reg_read(PIC_CCPXCON,1) rCCPxN(pwm_channel)=asc(s) @@ -1581,7 +1575,7 @@ sub pic_pwm_duty(ratio0 as word, ratio1 as word, ratio2 as word, channel as byte if ratio2>1000 then ratio2=1000 end if - i2c.num=channel + si2c_get(channel) s=pic_reg_read(PIC_CCP1CON,1) rCCPxN(0)=asc(s) s=pic_reg_read(PIC_CCP2CON,1) @@ -1651,7 +1645,7 @@ sub pic_ser_config(br as pic_brate_enum, par as pic_parity_mode_enum, irq_enable exit sub end if - i2c.num=channel + si2c_get(channel) if pic_uart_flag and &h80 then #if PIC_DEBUG_PRINT=1 @@ -1844,7 +1838,7 @@ sub pic_ser_setsend(data as string, channel as byte) exit sub end if - i2c.num=channel + si2c_get(channel) pic_reg_write(TX_BUFF_ADDR,data) pic_reg_write(TX_BYTE_COUNT,chr(len(data))) end sub @@ -1900,7 +1894,7 @@ function pic_ser_get(channel as byte)as string exit function end if dim rec as byte - i2c.num=channel + si2c_get(channel) keep_check: s=pic_reg_read(RX_BYTE_COUNT,1) @@ -1917,7 +1911,7 @@ function pic_ser_txlen(channel as byte)as byte 'Returns the number of bytes currently waiting in the TX buffer. The buffer is maintained by the GRA firmware and can fit up to 80 bytes. const TX_BYTE_COUNT=&h77 dim s as string - i2c.num=channel + si2c_get(channel) s=pic_reg_read(TX_BYTE_COUNT,1) pic_ser_txlen=asc(s) end function @@ -1927,7 +1921,7 @@ function pic_ser_rxlen(channel as byte)as byte const RX_BYTE_COUNT=&h76 dim s as string - i2c.num=channel + si2c_get(channel) s=pic_reg_read(RX_BYTE_COUNT,1) pic_ser_rxlen=asc(s) end function diff --git a/pic/tbt_pic_gra.tbs b/pic/tbt_pic_gra.tbs index 623b020..dcbce28 100644 --- a/pic/tbt_pic_gra.tbs +++ b/pic/tbt_pic_gra.tbs @@ -43,12 +43,8 @@ function tbt_pic_gra_init(byref signature as string, byref tbt as tbt_pic_gra, u tbt_pic_gra_init=OK tbt.pic_init_flag=PIC_INIT_SIGNATURE tbt.i2c_num_pic=si2c_register(signature,tbt.PIC_DATA_PIN,tbt.PIC_CLK_PIN,use_ssi) - i2c.num = tbt.i2c_num_pic - i2c.sdamap=tbt.PIC_DATA_PIN - i2c.sclmap=tbt.PIC_CLK_PIN - i2c.enabled=YES - i2c.num=tbt.i2c_num_pic + si2c_get(tbt.i2c_num_pic) '7.RXDTSEL 0 = RX/DT function is on RC5 '6.SDOSEL 0 = SDO function is on RC2 @@ -219,25 +215,25 @@ function tbt_pic_gra_reg_read(addr as word,length as byte)as string exit function end if - i2c.start() + si2c_start() - i2c.write(PIC_CHIP_ADDR_W) - i2c.write(PIC_CMD_R) + si2c_write(PIC_CHIP_ADDR_W) + si2c_write(PIC_CMD_R) tmp=addr / 256 - i2c.write(tmp) + si2c_write(tmp) tmp=addr or 256 - i2c.write(tmp) + si2c_write(tmp) - i2c.stop() - i2c.start() - i2c.write(PIC_CHIP_ADDR_R) + si2c_stop() + si2c_start() + si2c_write(PIC_CHIP_ADDR_R) for tmp=1 to length-1 - data=data+chr(i2c.read(ACK)) + data=data+chr(si2c_read(ACK)) next tmp - data=data+chr(i2c.read(NACK)) + data=data+chr(si2c_read(NACK)) tbt_pic_gra_reg_read=data - i2c.stop() + si2c_stop() end function @@ -252,23 +248,23 @@ function tbt_pic_gra_reg_write(addr as word, data as string)as ok_ng tbt_pic_gra_reg_write=NG if data="" then exit function - i2c.start() + si2c_start() - i2c.write(PIC_CHIP_ADDR_W) - i2c.write(PIC_CMD_W) + si2c_write(PIC_CHIP_ADDR_W) + si2c_write(PIC_CMD_W) tmp=addr/256 - i2c.write(tmp) + si2c_write(tmp) tmp=addr or 256 - i2c.write(tmp) + si2c_write(tmp) buf="" for pos=1 to len(data) buf=mid(data,pos,1) - i2c.write(asc(buf)) + si2c_write(asc(buf)) next pos - i2c.stop() + si2c_stop() tbt_pic_gra_reg_write=OK end function @@ -641,7 +637,7 @@ sub tbt_pic_gra_config(byref tbt as tbt_pic_gra, num as tbt_pic_gra_pin_enum, f exit sub end if - i2c.num=tbt.i2c_num_pic + si2c_get(tbt.i2c_num_pic) if tbt.pic_func(num)<>f then if tbt.pic_func(num)=PIC_FUNC_PWM then @@ -733,7 +729,7 @@ sub tbt_pic_gra_pwm_config_simple(byref tbt as tbt_pic_gra, ch as tbt_pic_gra_pw rCCPRxL = (ccprxl shr 2) rCCPxN = &h0C or ((ccprxl and &h03) shl 4) - i2c.num=tbt.i2c_num_pic + si2c_get(tbt.i2c_num_pic) select case ch diff --git a/super_i2c/super_i2c.tbs b/super_i2c/super_i2c.tbs index eaafd40..5e36afb 100644 --- a/super_i2c/super_i2c.tbs +++ b/super_i2c/super_i2c.tbs @@ -76,6 +76,8 @@ register_normal_slot: end if si2c_in_use(f)=YES + si2c_sda(f)=sda + si2c_scl(f)=scl si2c_user_signature(f)=signature si2c_register=f #IF I2C_AVAILABLE @@ -84,16 +86,16 @@ register_normal_slot: i2c.sclmap=scl i2c.enabled=YES #ELSE - si2c_sda(f)=sda - si2c_scl(f)=scl - si2c_register=f - - io.num=scl - io.state=HIGH - io.enabled=YES - io.num=sda - io.state=HIGH - io.enabled=NO + ssi.channel=channel + ssi.enabled=NO + ssi.baudrate=PL_SSI_BAUD_100kHz + ssi.clkmap=pin_clk + ssi.dimap=pin_data + ssi.domap=pin_data + ssi.direction=PL_SSI_DIRECTION_LEFT + ssi.zmode=PL_SSI_ZMODE_ENABLED_ON_ZERO + ssi.mode=PL_SSI_MODE_0 + ssi.enabled=YES #ENDIF #if SI2C_DEBUG_PRINT @@ -176,7 +178,7 @@ end sub sub si2c_stop() #IF I2C_AVAILABLE - i2c.stop() + si2c_stop() #ELSE io.num=si2c_sda(si2c_num) io.enabled=YES @@ -303,11 +305,19 @@ sub si2c_init() end sub function si2c_is_busy(num as byte)as no_yes +#IF I2C_AVAILABLE + if i2c.state <> I2C_IDLE + si2c_is_busy=YES + else + si2c_is_busy=NO + end if +#ELSE if io.lineget(si2c_scl(num))=LOW then si2c_is_busy=YES else si2c_is_busy=NO end if +#ENDIF end function #if SI2C_DEBUG_PRINT diff --git a/tibbits/tbt13/tbt13.tbs b/tibbits/tbt13/tbt13.tbs index e4ed4e2..5e64269 100644 --- a/tibbits/tbt13/tbt13.tbs +++ b/tibbits/tbt13/tbt13.tbs @@ -33,10 +33,7 @@ function tbt13_init(signature as string, data_pin as byte, clk_pin as byte, byre #endif tbt_channel=si2c_register(signature,data_pin,clk_pin,use_ssi) - i2c.num=tbt_channel - i2c.sdamap=data_pin - i2c.sclmap=clk_pin - i2c.enabled=YES + si2c_get(tbt_channel) #if TBT13_DEBUG_PRINT=1 adc_debug_print("i2c num:"+str(tbt_channel)) #endif @@ -73,11 +70,11 @@ sub tbt13_channel_select(channel as tbt13_nums, tbt_channel as byte) end select - i2c.num=tbt_channel - i2c.start() - i2c.write(TBT13_WRITE_ADDR) - i2c.write(ch) - i2c.start() + si2c_get(tbt_channel) + si2c_start() + si2c_write(TBT13_WRITE_ADDR) + si2c_write(ch) + si2c_start() end sub function tbt13_get_prev_mv(tbt_channel as byte) as integer @@ -113,12 +110,12 @@ function tbt13_get_prev(tbt_channel as byte) as word exit function end if - i2c.num=tbt_channel - i2c.start() - i2c.write(TBT13_READ_ADDR) - byte_hi=i2c.read(ACK) - byte_lo=i2c.read(ACK) - i2c.stop() + si2c_get(tbt_channel) + si2c_start() + si2c_write(TBT13_READ_ADDR) + byte_hi=si2c_read(ACK) + byte_lo=si2c_read(ACK) + si2c_stop() #if ADC_RESOLUTION=ADC_RES_LOW tbt13_get_prev=byte_lo/64 +byte_hi*4 '10 bit diff --git a/tibbits/tbt14/tbt14.tbs b/tibbits/tbt14/tbt14.tbs index 97f44cc..5e99ee4 100644 --- a/tibbits/tbt14/tbt14.tbs +++ b/tibbits/tbt14/tbt14.tbs @@ -31,10 +31,7 @@ function tbt14_init(signature as string, data_pin as byte, clk_pin as byte, load #endif tbt_channel=si2c_register(signature,data_pin,clk_pin,use_ssi) - i2c.num=tbt_channel - i2c.sdamap=data_pin - i2c.sclmap=clk_pin - i2c.enabled=YES + si2c_get(tbt_channel) #if TBT14_DEBUG_PRINT=1 tbt14_debug_print("i2c num:"+str(tbt_channel)) @@ -87,7 +84,7 @@ sub tbt14_set(n as dac_nums,v as word, load_pin as byte, busy_pin as byte, tbt_c tbt14_debug_print(hex(n)+"/"+hex(v)) #endif - i2c.num=tbt_channel + si2c_get(tbt_channel) io.num=busy_pin while io.state=LOW @@ -102,12 +99,12 @@ sub tbt14_set(n as dac_nums,v as word, load_pin as byte, busy_pin as byte, tbt_c tmp1=v and &h00FF io.lineset(load_pin,LOW) - i2c.start() - i2c.write(TBT14_WRITE_ADDR) - i2c.write(tmp) - i2c.write(tmp0) - i2c.write(tmp1) - i2c.stop() + si2c_start() + si2c_write(TBT14_WRITE_ADDR) + si2c_write(tmp) + si2c_write(tmp0) + si2c_write(tmp1) + si2c_stop() io.lineset(load_pin,HIGH) io.num=busy_pin diff --git a/tibbits/tbt22/tbt22.tbs b/tibbits/tbt22/tbt22.tbs index 9584141..f3ffa40 100644 --- a/tibbits/tbt22/tbt22.tbs +++ b/tibbits/tbt22/tbt22.tbs @@ -68,10 +68,7 @@ function tbt_rtd_init(signature as string, data_pin as byte, clk_pin as byte, in #endif tbt_channel=si2c_register(signature, data_pin, clk_pin, use_ssi) - i2c.num=tbt_channel - i2c.sdamap=data_pin - i2c.sclmap=clk_pin - i2c.enabled=YES + si2c_get(tbt_channel) dim b as byte dim tbt22_sockets_full as no_yes = YES @@ -103,44 +100,44 @@ end function sub tbt22_rtd_read_all(byref config as byte, byref rtd as word, byref hi_fault as word, byref lo_fault as word, byref fault as byte, int_pin as byte, tbt_channel as byte) dim tmp as byte=0 - i2c.num=tbt_channel + si2c_get(tbt_channel) - i2c.start() - i2c.write(TBT22_RTD_CODE_W) - i2c.write(TBT22_RTD_CMD_READ) - i2c.stop() + si2c_start() + si2c_write(TBT22_RTD_CODE_W) + si2c_write(TBT22_RTD_CMD_READ) + si2c_stop() - i2c.start() - i2c.write(TBT22_RTD_CODE_R) + si2c_start() + si2c_write(TBT22_RTD_CODE_R) 'wait pic co-processor to fetch the data ... while (io.lineget(int_pin) = LOW) wend - config = i2c.read(ACK) 'byte 0 - tmp = i2c.read(ACK) 'byte 1 - rtd = tmp * 256 + i2c.read(ACK) 'byte 2 - tmp = i2c.read(ACK) 'byte 3 - hi_fault = tmp * 256 + i2c.read(ACK)'byte 4 - tmp = i2c.read(ACK) 'byte 5 - lo_fault = tmp * 256 + i2c.read(ACK)'byte 6 - fault = i2c.read(NACK) 'byte 7 - i2c.stop() + config = si2c_read(ACK) 'byte 0 + tmp = si2c_read(ACK) 'byte 1 + rtd = tmp * 256 + si2c_read(ACK) 'byte 2 + tmp = si2c_read(ACK) 'byte 3 + hi_fault = tmp * 256 + si2c_read(ACK)'byte 4 + tmp = si2c_read(ACK) 'byte 5 + lo_fault = tmp * 256 + si2c_read(ACK)'byte 6 + fault = si2c_read(NACK) 'byte 7 + si2c_stop() while (io.lineget(int_pin) = LOW) wend end sub sub tbt22_rtd_reg_write(addr as tbt22_rtd_reg_write_addr, data as byte, int_pin as byte, tbt_channel as byte) dim tmr as dword - i2c.num=tbt_channel - - i2c.start() - i2c.write(TBT22_RTD_CODE_W) - i2c.write(TBT22_RTD_CMD_WRITE) - i2c.write(addr) - i2c.write(data) - i2c.stop() + si2c_get(tbt_channel) + + si2c_start() + si2c_write(TBT22_RTD_CODE_W) + si2c_write(TBT22_RTD_CMD_WRITE) + si2c_write(addr) + si2c_write(data) + si2c_stop() while (io.lineget(int_pin) = LOW) wend end sub @@ -319,20 +316,20 @@ function tbt22_rtd_fw_version(tbt_channel as byte)as string exit function end if - i2c.num=tbt_channel + si2c_get(tbt_channel) s="" - i2c.start() - i2c.write(TBT22_RTD_CODE_W) - i2c.write(TBT22_RTD_CMD_FW_VER) - i2c.stop() - i2c.start() - i2c.write(TBT22_RTD_CODE_R) + si2c_start() + si2c_write(TBT22_RTD_CODE_W) + si2c_write(TBT22_RTD_CMD_FW_VER) + si2c_stop() + si2c_start() + si2c_write(TBT22_RTD_CODE_R) for i = 0 to 14 - s = s + chr(i2c.read(ACK)) + s = s + chr(si2c_read(ACK)) next i - s = s + chr(i2c.read(NACK)) - i2c.stop() + s = s + chr(si2c_read(NACK)) + si2c_stop() tbt22_rtd_fw_version = s end function diff --git a/tibbits/tbt28/tbt28.tbs b/tibbits/tbt28/tbt28.tbs index dc82cf7..6a2c0c3 100644 --- a/tibbits/tbt28/tbt28.tbs +++ b/tibbits/tbt28/tbt28.tbs @@ -52,10 +52,7 @@ function tbt28_init(byref signature as string, use_ssi as no_yes, pin_clk as byt #endif channel=si2c_register(signature, pin_data, pin_clk, use_ssi) - i2c.num=channel - i2c.sdamap=pin_data - i2c.sclmap=pin_clk - i2c.enabled=YES + si2c_get(channel) 'Switch sensor to power down mode tbt28_cmd_send(TBT28_CMD_POWER_DOWN) @@ -86,13 +83,12 @@ function tbt28_get(byref channel as byte) as word exit function end if - ' si2c_get(channel) - i2c.num=channel - i2c.start() - i2c.write(TBT28_READ_ADDR) - upper=i2c.read(ACK) - lower=i2c.read(NACK) - i2c.stop() + si2c_get(channel) + si2c_start() + si2c_write(TBT28_READ_ADDR) + upper=si2c_read(ACK) + lower=si2c_read(NACK) + si2c_stop() #if TBT28_DEBUG_PRINT=1 tbt28_debug_print("u:"+hex(upper)+" l:"+hex(lower)) @@ -107,10 +103,10 @@ function tbt28_get(byref channel as byte) as word end function sub tbt28_cmd_send(cmd as byte) - i2c.start() - i2c.write(TBT28_WRITE_ADDR) - i2c.write(cmd) - i2c.stop() + si2c_start() + si2c_write(TBT28_WRITE_ADDR) + si2c_write(cmd) + si2c_stop() end sub sub tbt28_delay_msecond(value as word) diff --git a/tibbits/tbt29/tbt29.tbs b/tibbits/tbt29/tbt29.tbs index 4f77870..ce5b8c4 100644 --- a/tibbits/tbt29/tbt29.tbs +++ b/tibbits/tbt29/tbt29.tbs @@ -65,10 +65,7 @@ function tbt29_init(byref signature as string, use_ssi as no_yes, pin_clk as byt channel=si2c_register(signature, pin_data, pin_clk, use_ssi) - i2c.num=channel - i2c.sdamap=pin_data - i2c.sclmap=pin_clk - i2c.enabled=YES + si2c_get(channel) 'check the TBT29_MFG_ID if tbt29_read_data(TBT29_REG_MFGID,channel)<>TBT29_MFG_ID then @@ -122,7 +119,7 @@ function tbt29_get(channel as byte) as integer exit function end if - i2c.num=channel + si2c_get(channel) tbt29_delay_msecond(DELAY_IN_65_MS) @@ -150,46 +147,46 @@ function tbt29_read_data(op as tbt29_regs, byref channel as byte) as word upper=0 lower=0 - i2c.num=channel - i2c.start() + si2c_get(channel) + si2c_start() 'send address + op - i2c.write(TBT29_WRITE_ADDR) - i2c.write(op) + si2c_write(TBT29_WRITE_ADDR) + si2c_write(op) - i2c.start() + si2c_start() - i2c.write(TBT29_READ_ADDR) + si2c_write(TBT29_READ_ADDR) if op=TBT29_REG_RESOL then - lower=i2c.read(ACK) + lower=si2c_read(ACK) else - upper=i2c.read(ACK) - lower=i2c.read(NACK) + upper=si2c_read(ACK) + lower=si2c_read(NACK) end if - i2c.stop() + si2c_stop() tbt29_read_data=upper*256+lower end function sub tbt29_write_data(op as tbt29_regs,data as word, channel as byte) dim value as byte - i2c.num=channel - i2c.start() + si2c_get(channel) + si2c_start() - i2c.write(TBT29_WRITE_ADDR) - i2c.write(op) + si2c_write(TBT29_WRITE_ADDR) + si2c_write(op) if op=TBT29_REG_RESOL then value=data and &h00FF - i2c.write(value) + si2c_write(value) else value=(data and &hFF00)/256 - i2c.write(value) + si2c_write(value) value=data and &h00FF - i2c.write(value) + si2c_write(value) end if - i2c.stop() + si2c_stop() end sub sub tbt29_delay_msecond(value as word) diff --git a/tibbits/tbt30/tbt30.tbs b/tibbits/tbt30/tbt30.tbs index f2473d0..957a8ce 100644 --- a/tibbits/tbt30/tbt30.tbs +++ b/tibbits/tbt30/tbt30.tbs @@ -48,10 +48,7 @@ sub tbt30_init(byref signature as string, use_ssi as no_yes, pin_clk as byte, pi tbt30_init_flag=TBT30_INIT_SIGNATURE channel=si2c_register(signature, pin_data, pin_clk, use_ssi) - i2c.num = channel - i2c.sdamap=pin_data - i2c.sclmap=pin_clk - i2c.enabled=YES + si2c_get(channel) #if TBT30_DEBUG_PRINT=1 tbt30_debug_print("i2c num: "+str(channel)) @@ -96,16 +93,16 @@ function tbt30_get(byref humidity as word, byref temperature as word, channel as tbt30_get=OK - i2c.num=channel + si2c_get(channel) 'fetch humidity data - i2c.start() - i2c.write(TBT30_READ_ADDR) - data1=i2c.read(ACK) - data2=i2c.read(ACK) - data3=i2c.read(ACK) - data4=i2c.read(NACK) - i2c.stop() + si2c_start() + si2c_write(TBT30_READ_ADDR) + data1=si2c_read(ACK) + data2=si2c_read(ACK) + data3=si2c_read(ACK) + data4=si2c_read(NACK) + si2c_stop() status=data1 and &h80 status=status/128 @@ -175,9 +172,9 @@ function tbt30_get(byref humidity as word, byref temperature as word, channel as #endif 'send the measurement request - i2c.start() - i2c.write(TBT30_WRITE_ADDR) - i2c.stop() + si2c_start() + si2c_write(TBT30_WRITE_ADDR) + si2c_stop() ' tbt30_delay_msecond(50) diff --git a/tibbits/tbt35/tbt35.tbs b/tibbits/tbt35/tbt35.tbs index aae7234..50b703a 100644 --- a/tibbits/tbt35/tbt35.tbs +++ b/tibbits/tbt35/tbt35.tbs @@ -41,46 +41,43 @@ function tbt35_init(byref signature as string, use_ssi as no_yes, pin_clk as byt tbt35_init_flag=TBT35_INIT_SIGNATURE channel=si2c_register(signature, pin_data, pin_clk, use_ssi) - i2c.num=channel - i2c.sdamap=pin_data - i2c.sclmap=pin_clk - i2c.enabled=YES + si2c_get(channel) #if TBT35_DEBUG_PRINT=1 tbt35_debug_print("i2c num: "+str(channel)) #endif - i2c.start() - i2c.write(TBT35_WRITE_ADDR) - i2c.write(TBT35_CMD_READ_COEFFICIENT) - i2c.start() - i2c.write(TBT35_READ_ADDR) + si2c_start() + si2c_write(TBT35_WRITE_ADDR) + si2c_write(TBT35_CMD_READ_COEFFICIENT) + si2c_start() + si2c_write(TBT35_READ_ADDR) 'a0 - tmp=i2c.read(ACK) + tmp=si2c_read(ACK) a0_tmp=tmp*256 - tmp=i2c.read(ACK) + tmp=si2c_read(ACK) a0_tmp=a0_tmp+tmp 'b1 - tmp=i2c.read(ACK) + tmp=si2c_read(ACK) b1_tmp=tmp*256 - tmp=i2c.read(ACK) + tmp=si2c_read(ACK) b1_tmp=b1_tmp+tmp 'b2 - tmp=i2c.read(ACK) + tmp=si2c_read(ACK) b2_tmp=tmp*256 - tmp=i2c.read(ACK) + tmp=si2c_read(ACK) b2_tmp=b2_tmp+tmp 'c12 - tmp=i2c.read(ACK) + tmp=si2c_read(ACK) c12_tmp=tmp*256 - tmp=i2c.read(NACK) + tmp=si2c_read(NACK) c12_tmp=c12_tmp+tmp - i2c.stop() + si2c_stop() 'a0 :signed, integer bits=12,fractional bits=3 a0=a0_tmp and &h7FF8 @@ -347,14 +344,14 @@ function tbt35_get_kpa(channel as byte)as float exit function end if - i2c.num=channel + si2c_get(channel) - i2c.start() - i2c.write(TBT35_WRITE_ADDR) - i2c.write(TBT35_CMD_START_CONVERSION) - i2c.write(&h00) - i2c.stop() + si2c_start() + si2c_write(TBT35_WRITE_ADDR) + si2c_write(TBT35_CMD_START_CONVERSION) + si2c_write(&h00) + si2c_stop() 'Time between start convert command and data available in the Pressure and Temperature registers #if PLATFORM_TYPE_32 @@ -363,27 +360,27 @@ function tbt35_get_kpa(channel as byte)as float tbt35_delay_msecond(3) #endif - i2c.start() + si2c_start() - i2c.write(TBT35_WRITE_ADDR) - i2c.write(TBT35_CMD_READ_PRESSURE) + si2c_write(TBT35_WRITE_ADDR) + si2c_write(TBT35_CMD_READ_PRESSURE) - i2c.start() - i2c.write(TBT35_READ_ADDR) + si2c_start() + si2c_write(TBT35_READ_ADDR) 'pressure - tmp=i2c.read(ACK) + tmp=si2c_read(ACK) padc=tmp*256 - tmp=i2c.read(ACK) + tmp=si2c_read(ACK) padc=padc+tmp 'temprature - tmp=i2c.read(ACK) + tmp=si2c_read(ACK) tadc=tmp*256 - tmp=i2c.read(NACK) + tmp=si2c_read(NACK) tadc=tadc+tmp - i2c.stop() + si2c_stop() padc=padc /64 tadc=tadc /64 diff --git a/tibbits/tbt36/tbt36.tbs b/tibbits/tbt36/tbt36.tbs index f3852cf..e4138ac 100644 --- a/tibbits/tbt36/tbt36.tbs +++ b/tibbits/tbt36/tbt36.tbs @@ -74,10 +74,7 @@ function tbt36_init(byref signature as string, use_ssi as no_yes, pin_clk as byt tbt36_init_flag=TBT36_INIT_SIGNATURE channel=si2c_register(signature, pin_data, pin_clk, use_ssi) - i2c.num=channel - i2c.sdamap=pin_data - i2c.sclmap=pin_clk - i2c.enabled=YES + si2c_get(channel) dim id as byte=&h00 @@ -150,7 +147,7 @@ sub tbt36_get(byref x_value as integer, byref y_value as integer, byref z_value exit sub end if - i2c.num=channel + si2c_get(channel) 'Read X axis value hi_byte=tbt36_get_reg(TBT36_REG_DATA_X1) @@ -228,6 +225,7 @@ sub tbt36_get(byref x_value as integer, byref y_value as integer, byref z_value end sub sub tbt36_error() +#IF I2C_AVAILABLE select case i2c.state case I2C_IDLE: sys.debugprint("I2C Error: I2C_IDLE this should not be seen.\r\n") @@ -238,36 +236,39 @@ sub tbt36_error() case I2C_ARBITRATION_ERROR: sys.debugprint("I2C Error: I2C_ARBITRATION_ERROR\r\n") end select +#ELSE + sys.debugprint("I2C Error: I2C object is not available.\r\n") +#ENDIF end sub sub tbt36_write_reg(cmd as byte, data as byte) - i2c.start() + si2c_start() - if i2c.state <> I2C_STARTED then + if si2c_is_busy()=NO then tbt36_error() end if - i2c.write(TBT36_WRITE_ADDR) + si2c_write(TBT36_WRITE_ADDR) - i2c.write(cmd) + si2c_write(cmd) - if i2c.state <> I2C_STARTED then + if si2c_is_busy()=NO then tbt36_error() end if - i2c.write(data) + si2c_write(data) - if i2c.state <> I2C_STARTED then + if si2c_is_busy()=NO then tbt36_error() end if - i2c.stop() + si2c_stop() - if i2c.state <> I2C_IDLE then + if si2c_is_busy()=YES then tbt36_error() end if @@ -275,35 +276,35 @@ end sub function tbt36_get_reg(cmd as byte) as byte dim tmp as byte - i2c.start() + si2c_start() - if i2c.state <> I2C_STARTED then + if si2c_is_busy()=NO then tbt36_error() end if - i2c.write(TBT36_WRITE_ADDR) - i2c.write(cmd) + si2c_write(TBT36_WRITE_ADDR) + si2c_write(cmd) - if i2c.state <> I2C_STARTED then + if si2c_is_busy()=NO then tbt36_error() end if - i2c.start() + si2c_start() - if i2c.state <> I2C_STARTED then + if si2c_is_busy()=NO then tbt36_error() end if - i2c.write(TBT36_READ_CODE) - tmp=i2c.read(NACK) + si2c_write(TBT36_READ_CODE) + tmp=si2c_read(NACK) - if i2c.state <> I2C_STARTED then + if si2c_is_busy()=NO then tbt36_error() end if - i2c.stop() - if i2c.state <> I2C_IDLE then + si2c_stop() + if si2c_is_busy()=YES then tbt36_error() end if diff --git a/tibbits/tbt40/tbt40.tbs b/tibbits/tbt40/tbt40.tbs index eef58eb..605a644 100644 --- a/tibbits/tbt40/tbt40.tbs +++ b/tibbits/tbt40/tbt40.tbs @@ -45,17 +45,12 @@ function tbt40_init(use_ssi as no_yes, pin_clk as byte, pin_data as byte, byref #endif channel=si2c_register("TBT40",pin_data,pin_clk,use_ssi) - i2c.num=channel - i2c.sdamap=pin_data - i2c.sclmap=pin_clk - i2c.enabled=YES #if TBT40_DEBUG_PRINT=1 tbt40_debug_print("i2c num:"+str(channel)) #endif - - i2c.num=channel + si2c_get(channel) if tbt40_reg_read(TBT40_STATUS,channel)<>&h01F0 then #if TBT40_DEBUG_PRINT=1 @@ -133,14 +128,13 @@ sub tbt40_reg_write(addr as tbt40_regs, data as word, channel as byte) else cmd=addr end if + si2c_get(channel) - i2c.num=channel - - i2c.start() - i2c.write(TBT40_WRITE_ADDR) - i2c.write(cmd) - i2c.write(data and &h00FF) - i2c.stop() + si2c_start() + si2c_write(TBT40_WRITE_ADDR) + si2c_write(cmd) + si2c_write(data and &h00FF) + si2c_stop() end sub function tbt40_reg_read(addr as tbt40_regs, channel as byte)as word @@ -151,16 +145,15 @@ function tbt40_reg_read(addr as tbt40_regs, channel as byte)as word #endif exit function end if - - i2c.num=channel - i2c.start() - i2c.write(TBT40_WRITE_ADDR) - i2c.write(addr+&hC) 'READ Command - i2c.start() - i2c.write(TBT40_READ_ADDR) - tbt40_reg_read=i2c.read(ACK)*256 - tbt40_reg_read=tbt40_reg_read+i2c.read(NACK) - i2c.stop() + si2c_get(channel) + si2c_start() + si2c_write(TBT40_WRITE_ADDR) + si2c_write(addr+&hC) 'READ Command + si2c_start() + si2c_write(TBT40_READ_ADDR) + tbt40_reg_read=si2c_read(ACK)*256 + tbt40_reg_read=tbt40_reg_read+si2c_read(NACK) + si2c_stop() end function #if TBT40_DEBUG_PRINT=1 diff --git a/tibbits/tbt41/tbt41.tbs b/tibbits/tbt41/tbt41.tbs index 7ecf079..7ed224e 100644 --- a/tibbits/tbt41/tbt41.tbs +++ b/tibbits/tbt41/tbt41.tbs @@ -57,10 +57,6 @@ function tbt41_init(byref signature as string, use_ssi as no_yes, pin_clk as byt #endif channel=si2c_register(signature,pin_data,pin_clk,use_ssi) - i2c.num=channel - i2c.sdamap=pin_data - i2c.sclmap=pin_clk - i2c.enabled=YES #if TBT41_DEBUG_PRINT=1 tbt41_debug_print("i2c num:"+str(channel)) @@ -71,7 +67,7 @@ function tbt41_init(byref signature as string, use_ssi as no_yes, pin_clk as byt #endif dim value as byte - i2c.num=channel + si2c_get(channel) 'Pins are configured as an input. tbt41_reg_write(TBT41_ADDR_IODIR,&hFF) if tbt41_reg_read(TBT41_ADDR_IODIR)<>&hFF then @@ -102,7 +98,7 @@ function tbt41_line_out_enable(num as ext_line_name,en as no_yes, channel as byt #endif exit function end if - i2c.num=channel + si2c_get(channel) value=tbt41_reg_read(TBT41_ADDR_IODIR) tbt41_bit_access(value,num,en) tbt41_reg_write(TBT41_ADDR_IODIR,value) @@ -121,7 +117,7 @@ function tbt41_line_pup_enable(num as ext_line_name, en as no_yes, channel as by #endif exit function end if - i2c.num=channel + si2c_get(channel) value=tbt41_reg_read(TBT41_ADDR_GPPU) tbt41_bit_access(value,num,en) tbt41_reg_write(TBT41_ADDR_GPPU,value) @@ -140,7 +136,7 @@ function tbt41_line_set(num as ext_line_name,state as low_high, channel as byte) #endif exit function end if - i2c.num=channel + si2c_get(channel) value=tbt41_reg_read(TBT41_ADDR_GPIO) if state=LOW then tbt41_bit_access(value,num,YES) @@ -163,7 +159,7 @@ function tbt41_line_get(num as ext_line_name, byref state as low_high, channel a #endif exit function end if - i2c.num=channel + si2c_get(channel) value=tbt41_reg_read(TBT41_ADDR_GPIO) dim tmp as byte select case num @@ -214,7 +210,7 @@ function tbt41_port_config_set(dir as byte,pullup as byte, channel as byte)as ok #endif exit function end if - i2c.num=channel + si2c_get(channel) tbt41_reg_write(TBT41_ADDR_IODIR,dir) tbt41_reg_write(TBT41_ADDR_GPPU,pullup) tbt41_port_config_set=OK @@ -234,7 +230,7 @@ function tbt41_port_config_get(byref dir as byte,byref pullup as byte, channel a #endif exit function end if - i2c.num=channel + si2c_get(channel) pullup=tbt41_reg_read(TBT41_ADDR_GPPU) dir=tbt41_reg_read(TBT41_ADDR_IODIR) tbt41_port_config_get=OK @@ -251,7 +247,7 @@ function tbt41_port_set(data as byte, channel as byte) as ok_ng #endif exit function end if - i2c.num=channel + si2c_get(channel) tbt41_reg_write(TBT41_ADDR_GPIO,data) tbt41_port_set=OK end function @@ -267,27 +263,27 @@ function tbt41_port_get(byref data as byte, channel as byte)as ok_ng #endif exit function end if - i2c.num=channel + si2c_get(channel) data=tbt41_reg_read(TBT41_ADDR_GPIO) tbt41_port_get=OK end function sub tbt41_reg_write(reg as tbt41_regs,data as byte) - i2c.start() - i2c.write(TBT41_WRITE_ADDR) - i2c.write(reg) - i2c.write(data) - i2c.stop() + si2c_start() + si2c_write(TBT41_WRITE_ADDR) + si2c_write(reg) + si2c_write(data) + si2c_stop() end sub function tbt41_reg_read(addr as tbt41_regs)as byte - i2c.start() - i2c.write(TBT41_WRITE_ADDR) - i2c.write(addr) - i2c.start() - i2c.write(TBT41_READ_CODE) - tbt41_reg_read=i2c.read(NACK) - i2c.stop() + si2c_start() + si2c_write(TBT41_WRITE_ADDR) + si2c_write(addr) + si2c_start() + si2c_write(TBT41_READ_CODE) + tbt41_reg_read=si2c_read(NACK) + si2c_stop() end function sub tbt41_bit_access(byref data as byte,bit as byte,act as tbt41_clr_set) diff --git a/tibbits/tbt52/tbt52.tbs b/tibbits/tbt52/tbt52.tbs index 41d6383..6dd83bd 100644 --- a/tibbits/tbt52/tbt52.tbs +++ b/tibbits/tbt52/tbt52.tbs @@ -39,10 +39,6 @@ function tbt52_init(use_ssi as no_yes,pin_clk as byte,pin_data as byte,pin_mclr tbt52_init_flag=TBT52_INIT_SIGNATURE channel=si2c_register("TBT52", pin_data, pin_clk,use_ssi) - i2c.num=channel - i2c.sdamap=pin_data - i2c.sclmap=pin_clk - i2c.enabled=YES io.num=pin_mclr io.enabled=YES @@ -64,23 +60,23 @@ function tbt52_init(use_ssi as no_yes,pin_clk as byte,pin_data as byte,pin_mclr io.enabled=NO - i2c.num=channel + si2c_get(channel) - i2c.start() - i2c.write(&h20) - i2c.write(&h03) - i2c.stop() + si2c_start() + si2c_write(&h20) + si2c_write(&h03) + si2c_stop() - i2c.start() - i2c.write(&h21) + si2c_start() + si2c_write(&h21) s="" for i=0 to 14 - s=s+chr(i2c.read(ACK)) + s=s+chr(si2c_read(ACK)) next i - s=s+chr(i2c.read(NACK)) + s=s+chr(si2c_read(NACK)) - i2c.stop() + si2c_stop() #if TBT52_DEBUG_PRINT=1 tbt52_debug_print("F/W : "+s) @@ -94,12 +90,12 @@ function tbt52_init(use_ssi as no_yes,pin_clk as byte,pin_data as byte,pin_mclr end if for tbt52_channel=ADC_1 to ADC_4 - i2c.start() - i2c.write(&h20) - i2c.write(&h02) - i2c.write(tbt52_channel) - i2c.write(&h1C) 'single mode + 16 bits + Gain = 1 - i2c.stop() + si2c_start() + si2c_write(&h20) + si2c_write(&h02) + si2c_write(tbt52_channel) + si2c_write(&h1C) 'single mode + 16 bits + Gain = 1 + si2c_stop() while (io.lineget(pin_int)=LOW) wend next tbt52_channel @@ -129,20 +125,20 @@ function tbt52_get_volts(pin_int as byte,channel as byte)as real const LSB_mV=0.00030517578125 f=NO busy_wait: - i2c.num=channel - i2c.start() - i2c.write(&h20) - i2c.write(&h01) - i2c.write(tbt52_channel) - i2c.stop() + si2c_get(channel) + si2c_start() + si2c_write(&h20) + si2c_write(&h01) + si2c_write(tbt52_channel) + si2c_stop() while (io.lineget(pin_int)=LOW) wend - i2c.start() - i2c.write(&h21) - hi_byte=i2c.read(ACK) - lo_byte=i2c.read(ACK) - config=i2c.read(NACK) - i2c.stop() + si2c_start() + si2c_write(&h21) + hi_byte=si2c_read(ACK) + lo_byte=si2c_read(ACK) + config=si2c_read(NACK) + si2c_stop() if (config and &h80) then goto busy_wait @@ -151,12 +147,12 @@ busy_wait: tmp=tmp+lo_byte else ' start a conversion. - i2c.start() - i2c.write(&h20) - i2c.write(&h02) - i2c.write(tbt52_channel) - i2c.write(&h9C) 'single mode + 16 bits + Gain = 1 - i2c.stop() + si2c_start() + si2c_write(&h20) + si2c_write(&h02) + si2c_write(tbt52_channel) + si2c_write(&h9C) 'single mode + 16 bits + Gain = 1 + si2c_stop() while (io.lineget(pin_int)=LOW) wend f=YES @@ -201,21 +197,21 @@ sub param_read(pin_int as byte,channel as byte) dim r,tmp as dword #endif - i2c.num=channel + si2c_get(channel) - i2c.start() - i2c.write(&h20) - i2c.write(&h06) - i2c.stop() + si2c_start() + si2c_write(&h20) + si2c_write(&h06) + si2c_stop() while (io.lineget(pin_int)=LOW) wend - i2c.start() - i2c.write(&h21) + si2c_start() + si2c_write(&h21) - value(0)=i2c.read(ACK) - value(1)=i2c.read(ACK) - value(2)=i2c.read(ACK) - value(3)=i2c.read(ACK) + value(0)=si2c_read(ACK) + value(1)=si2c_read(ACK) + value(2)=si2c_read(ACK) + value(3)=si2c_read(ACK) #if PLATFORM_TYPE_32 tmp=value(1)*&h10000 @@ -261,10 +257,10 @@ sub param_read(pin_int as byte,channel as byte) #endif end if - value(0)=i2c.read(ACK) - value(1)=i2c.read(ACK) - value(2)=i2c.read(ACK) - value(3)=i2c.read(ACK) + value(0)=si2c_read(ACK) + value(1)=si2c_read(ACK) + value(2)=si2c_read(ACK) + value(3)=si2c_read(ACK) #if PLATFORM_TYPE_32 tmp=value(1)*&h10000 r=tmp @@ -309,10 +305,10 @@ sub param_read(pin_int as byte,channel as byte) #endif end if - value(0)=i2c.read(ACK) - value(1)=i2c.read(ACK) - value(2)=i2c.read(ACK) - value(3)=i2c.read(ACK) + value(0)=si2c_read(ACK) + value(1)=si2c_read(ACK) + value(2)=si2c_read(ACK) + value(3)=si2c_read(ACK) #if PLATFORM_TYPE_32 tmp=value(1)*&h10000 r=tmp @@ -357,10 +353,10 @@ sub param_read(pin_int as byte,channel as byte) #endif end if - value(0)=i2c.read(ACK) - value(1)=i2c.read(ACK) - value(2)=i2c.read(ACK) - value(3)=i2c.read(NACK) + value(0)=si2c_read(ACK) + value(1)=si2c_read(ACK) + value(2)=si2c_read(ACK) + value(3)=si2c_read(NACK) #if PLATFORM_TYPE_32 tmp=value(1)*&h10000 r=tmp @@ -405,7 +401,7 @@ sub param_read(pin_int as byte,channel as byte) #endif end if - i2c.stop() + si2c_stop() while (io.lineget(pin_int)=LOW) wend end sub @@ -446,16 +442,16 @@ sub param_write(pin_int as byte,channel as byte) end if next i - i2c.num=channel - i2c.start() - i2c.write(&h20) - i2c.write(&h05) + si2c_get(channel) + si2c_start() + si2c_write(&h20) + si2c_write(&h05) for i=0 to 3 for j= 0 to 3 - i2c.write(data(i,j)) + si2c_write(data(i,j)) next j next i - i2c.stop() + si2c_stop() while (io.lineget(pin_int)=LOW) wend end sub @@ -483,20 +479,20 @@ sub tbt52_compensation_calibrate(pin_int as byte,channel as byte) next i busy_wait: - i2c.num=channel - i2c.start() - i2c.write(&h20) - i2c.write(&h01) - i2c.write(tbt52_channel) - i2c.stop() + si2c_get(channel) + si2c_start() + si2c_write(&h20) + si2c_write(&h01) + si2c_write(tbt52_channel) + si2c_stop() while (io.lineget(pin_int)=LOW) wend - i2c.start() - i2c.write(&h21) - hi_byte=i2c.read(ACK) - lo_byte=i2c.read(ACK) - config=i2c.read(NACK) - i2c.stop() + si2c_start() + si2c_write(&h21) + hi_byte=si2c_read(ACK) + lo_byte=si2c_read(ACK) + config=si2c_read(NACK) + si2c_stop() if (config and &h80) then goto busy_wait if f=YES then @@ -504,12 +500,12 @@ busy_wait: tmp=tmp+lo_byte else ' start a conversion. - i2c.start() - i2c.write(&h20) - i2c.write(&h02) - i2c.write(tbt52_channel) - i2c.write(&h9C) 'single mode + 16 bits + Gain = 1 - i2c.stop() + si2c_start() + si2c_write(&h20) + si2c_write(&h02) + si2c_write(tbt52_channel) + si2c_write(&h9C) 'single mode + 16 bits + Gain = 1 + si2c_stop() while (io.lineget(pin_int)=LOW) wend f=YES diff --git a/tibbits/tbt53/tbt53.tbs b/tibbits/tbt53/tbt53.tbs index 268710a..9d82b56 100644 --- a/tibbits/tbt53/tbt53.tbs +++ b/tibbits/tbt53/tbt53.tbs @@ -34,23 +34,19 @@ function tbt53_init(use_ssi as no_yes, pin_clk as byte, pin_data as byte, byref tbt53_init_flag = TBT53_INIT_SIGNATURE channel = si2c_register("TBT53", pin_data, pin_clk,use_ssi) - i2c.num = channel - i2c.sdamap=pin_data - i2c.sclmap=pin_clk - i2c.enabled=YES - - i2c.num=channel - i2c.start() - i2c.write(TBT53_WRITE_ADDR) - i2c.write(&h0C) - i2c.stop() - - i2c.start() - i2c.write(TBT53_READ_ADDR) - hi_byte = i2c.read(ACK) - lo_byte = i2c.read(ACK) - config = i2c.read(NACK) - i2c.stop() + + si2c_get(channel) + si2c_start() + si2c_write(TBT53_WRITE_ADDR) + si2c_write(&h0C) + si2c_stop() + + si2c_start() + si2c_write(TBT53_READ_ADDR) + hi_byte = si2c_read(ACK) + lo_byte = si2c_read(ACK) + config = si2c_read(NACK) + si2c_stop() #if TBT53_DEBUG_PRINT = 1 tbt53_debug_print("config : " + hex(config)) @@ -72,12 +68,12 @@ function tbt53_get_current(byref ma as real, channel as byte) as ok_ng tbt53_get_current = NG if tbt53_init_flag <> TBT53_INIT_SIGNATURE then exit function - i2c.num=channel - i2c.start() - i2c.write(TBT53_READ_ADDR) - hi_byte = i2c.read(ACK) - lo_byte = i2c.read(ACK) - i2c.stop() + si2c_get(channel) + si2c_start() + si2c_write(TBT53_READ_ADDR) + hi_byte = si2c_read(ACK) + lo_byte = si2c_read(ACK) + si2c_stop() tmp = hi_byte * 256 tmp = tmp + lo_byte diff --git a/tibbits/tbt62/tbt62.tbs b/tibbits/tbt62/tbt62.tbs index 21f3700..49263b2 100644 --- a/tibbits/tbt62/tbt62.tbs +++ b/tibbits/tbt62/tbt62.tbs @@ -69,16 +69,14 @@ function tbt62_init(signature as string, data_pin as byte, clk_pin as byte, rese #endif tbt_channel = si2c_register(signature, data_pin, clk_pin, use_ssi) - i2c.num=tbt_channel - i2c.sdamap=data_pin - i2c.sclmap=clk_pin - i2c.enabled=YES if tbt_channel = 255 then tbt62_init = TBT62_INIT_ERROR_SI2C_NO_EMPTY_CHANNEL exit function end if + si2c_get(tbt_channel) + tbt62_reset_pin(tbt_channel) = reset_pin tbt62_busy_pin(tbt_channel) = busy_pin tbt62_use(tbt_channel) = YES @@ -103,7 +101,7 @@ sub tbt62_send_string(data as string) dim i as byte for i = 1 to len(data) - i2c.write(asc(mid(data, i, 1))) + si2c_write(asc(mid(data, i, 1))) next i end sub @@ -121,13 +119,13 @@ function tbt62_send_command(command as byte, tbt_channel as byte) as boolean tbt62_mode(tbt_channel, tbt62_channel(tbt_channel)) = command AND &h01 end if - i2c.num=tbt_channel + si2c_get(tbt_channel) - i2c.start() 'I2C START + si2c_start() 'I2C START tbt62_send_string(chr(TBT62_REGISTER_COMMAND_ADDRESS) + chr(command)) ' Send Command - i2c.stop() 'I2C STOP + si2c_stop() 'I2C STOP tbt62_send_command = true @@ -139,14 +137,14 @@ function tbt62_send_data(command as byte, rom as string(8), data as string(16), if not tbt62_check_library(tbt_channel) then exit function if len(data) > 0 and len(data) < 17 then - i2c.num=tbt_channel + si2c_get(tbt_channel) - i2c.start() 'I2C START + si2c_start() 'I2C START ' Send tbt62_send_string(chr(TBT62_REGISTER_COMMAND_ADDRESS) + chr(command + len(data) - 1) + rom + data) ' Send Command - i2c.stop() 'I2C STOP + si2c_stop() 'I2C STOP tbt62_send_data = true @@ -169,25 +167,25 @@ function tbt62_read_data(byref data as string, data_len as byte, tbt_channel as if data_len = 0 then exit function - i2c.num=tbt_channel + si2c_get(tbt_channel) - i2c.start() 'I2C START + si2c_start() 'I2C START ' Send address for read register tbt62_send_string(chr(TBT62_REGISTER_DATA_ADDRESS)) ' Send Command i = 1 do if i < data_len then - tmp = tmp + chr(i2c.read(ACK)) + tmp = tmp + chr(si2c_read(ACK)) else - tmp = tmp + chr(i2c.read(NACK)) + tmp = tmp + chr(si2c_read(NACK)) end if i = i + 1 loop until i > data_len data = tmp - i2c.stop() 'I2C START + si2c_stop() 'I2C START tbt62_read_data = true @@ -356,28 +354,28 @@ function tbt62_checkTibbit(tbt_channel as byte) as EN_TBT62_INIT_RESULT ' delay 100 ms for RESET in PIC uPC tbt62_delayMS(100) - i2c.num=tbt_channel + si2c_get(tbt_channel) - i2c.start() 'I2C START + si2c_start() 'I2C START ' Send tbt62_send_string(chr(TBT62_REGISTER_COMMAND_ADDRESS) + chr(TBT62_CMD_GETVERSION)) ' Send Command for Get Version ' Read data from PIC ' Send START - i2c.start() + si2c_start() ' Send Address tbt62_send_string(chr(TBT62_REGISTER_DATA_ADDRESS)) ' Send data register address ' Read version version = "" for i = 1 to 5 - version = version + chr(i2c.read(ACK)) + version = version + chr(si2c_read(ACK)) next i - version = version + chr(i2c.read(NACK)) + version = version + chr(si2c_read(NACK)) ' Send STOP - i2c.stop() + si2c_stop() if version <> "TBT" + chr(&h62) + chr(&h00) + chr(&h01) then tbt62_checkTibbit = TBT62_INIT_ERROR_NO_VALID_VERSION