PIGPIO Lib (i2c Funktionen)

Fragen zu Raspberry, FritzBox, Microcontroller, UART, etc...
Antworten
Fileplayer
Foriker
Beiträge: 8
Registriert: Mi 10. Jan 2018, 18:11
Kontaktdaten:

PIGPIO Lib (i2c Funktionen)

Beitrag von Fileplayer » Di 23. Jan 2018, 13:46

Hallo, wer kann helfen ??

Es geht um die pigpio Lib. Die IOs funktonieren perfekt, nur die I2C Funktionen gehen nich so wie ich will.

Kann mir jemand ein Beispiel geben, ich will den ADS1115 AD Baustein auslesen ?

Also es geht nicht um die eigendlichen Parameter die zum ansprechen des Bausteins notwendig sind, sondern vielmehr um die Start bzw. Stop Sequenzen und soweiter. Ich hoffe ich habe euch nicht zu sehr generft

Mein Code bis jetzt :
gambas code
' Gambas class file

'==================

Library "/usr/local/lib/libpigpio"                  ' Name der Library

Public Extern gpioInitialise() As Integer           ' Initialisieren

Public Extern gpioTerminate() As Integer            ' Terminieren

Public Extern gpioVersion() As Integer              ' Version

Public Extern gpioHardwareRevision() As Integer     ' Hardware

Public Extern gpioSetMode(iPin As Integer, iMode As Integer) As Integer
' INPUT oder OUTPUT des Pins

Public Extern gpioRead(iPin As Integer) As Integer
' Pin lesen

Public Extern gpioWrite(iPin As Integer, iLevel As Integer) As Integer
' Pin schreiben
'#####################################################################

Public Extern i2cOpen(BusNr As Integer, i2cAdr As Integer, i2cFlags As Integer) As Integer

Public Extern i2cWriteByte(handle As Integer, Wert As Integer) As Integer

Public Extern i2cReadByte(handle As Integer) As Integer

Public Extern i2cClose(Handle As Integer) As Integer


' INT i2cOpen(unsigned i2cBus, unsigned i2cAddr, unsigned i2cFlags)
' This returns a handle For the device at the address On the I2C bus.
' 
'   i2cBus: >= 0
'  i2cAddr: 0 - 0 x7F
' i2cFlags: 0
' 
' 
' No flags are currently defined.This parameter should be set To zero.
' 
' Physically buses 0 And 1 are available On the Pi.Higher numbered buses will be available If a kernel supported bus multiplexor Is Being used.
' 
' Returns a handle( >= 0) If OK, otherwise PI_BAD_I2C_BUS, PI_BAD_I2C_ADDR, PI_BAD_FLAGS, PI_NO_HANDLE, Or PI_I2C_OPEN_FAILED.
' 
' For the SMBus commands the low level transactions are shown at the End Of the function description.The following abbreviations are used.
' 
' S(1 bit): Start bit
' P(1 bit): Stop bit
' Rd / Wr(1 bit): Read / Write bit.Rd equals 1, Wr equals 0.
' A, NA(1 bit): Accept And Not accept bit.
' 
' Addr(7 bits): I2C 7 bit address.
' i2cReg(8 bits): Command byte, a byte which often selects a register.
' Data(8 bits): A data byte.
' Count(8 bits): A byte defining the length Of a block operation.
' 
' [..]: Data sent by the device.
' `----------------------------------------------------------
' int i2cClose(unsigned handle)
' This closes the I2C device associated With the handle.
' 
' handle: >= 0, As Returned by a call To i2cOpen
' 
' 
' Returns 0 If OK, otherwise PI_BAD_HANDLE.
' `----------------------------------------------------------
' int i2cWriteQuick(unsigned handle, unsigned bit)
' This sends a single bit( In the Rd / Wr bit) To the device associated With handle.
' 
' handle: >= 0, As Returned by a call To i2cOpen
'    bit: 0 - 1, the value To Write
' 
' 
' Returns 0 If OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, Or PI_I2C_WRITE_FAILED.
' 
' Quick command.SMBus 2.0 5.5.1
' S Addr bit[A]P
' `----------------------------------------------------------
' int i2cWriteByte(unsigned handle, unsigned bVal)
' This sends a single byte To the device associated With handle.
' 
' handle: >= 0, As Returned by a call To i2cOpen
'   bVal: 0 - 0 xFF, the value To Write
' 
' 
' Returns 0 If OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, Or PI_I2C_WRITE_FAILED.
' 
' Send byte.SMBus 2.0 5.5.2
' S Addr Wr[A]bVal[A]P
' `----------------------------------------------------------
' int i2cReadByte(unsigned handle)
' This reads a single byte From the device associated With handle.
' 
' handle: >= 0, As Returned by a call To i2cOpen
' 
' 
' Returns the byte Read ( >= 0) If OK, otherwise PI_BAD_HANDLE, Or PI_I2C_READ_FAILED.
' 
' Receive byte.SMBus 2.0 5.5.3
' S Addr Rd[A][Data]NA P
' `----------------------------------------------------------
' int i2cWriteByteData(unsigned handle, unsigned i2cReg, unsigned bVal)
' This writes a single byte To the specified register Of the device associated With handle.
' 
' handle: >= 0, As Returned by a call To i2cOpen
' i2cReg: 0 - 255, the register To Write
'   bVal: 0 - 0 xFF, the value To Write
' 
' 
' Returns 0 If OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, Or PI_I2C_WRITE_FAILED.
' 
' Write byte.SMBus 2.0 5.5.4
' S Addr Wr[A]i2cReg[A]bVal[A]P
' `----------------------------------------------------------
' int i2cWriteWordData(unsigned handle, unsigned i2cReg, unsigned wVal)
' This writes a single 16 bit word To the specified register Of the device associated With handle.
' 
' handle: >= 0, As Returned by a call To i2cOpen
' i2cReg: 0 - 255, the register To Write
'   wVal: 0 - 0 xFFFF, the value To Write
' 
' Returns 0 If OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, Or PI_I2C_WRITE_FAILED.
' 
' Write word.SMBus 2.0 5.5.4
' S Addr Wr[A]i2cReg[A]wValLow[A]wValHigh[A]P
' `----------------------------------------------------------
' int i2cReadByteData(unsigned handle, unsigned i2cReg)
' This reads a single byte From the specified register Of the device associated With handle.
' 
' handle: >= 0, As Returned by a call To i2cOpen
' i2cReg: 0 - 255, the register To Read
' 
' 
' Returns the byte Read ( >= 0) If OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, Or PI_I2C_READ_FAILED.
' 
' Read byte.SMBus 2.0 5.5.5
' S Addr Wr[A]i2cReg[A]S Addr Rd[A][Data]NA P
' `----------------------------------------------------------
' int i2cReadWordData(unsigned handle, unsigned i2cReg)
' This reads a single 16 bit word From the specified register Of the device associated With handle.
' 
' handle: >= 0, As Returned by a call To i2cOpen
' i2cReg: 0 - 255, the register To Read
' 
' 
' Returns the word Read ( >= 0) If OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, Or PI_I2C_READ_FAILED.
' 
' Read word.SMBus 2.0 5.5.5
' S Addr Wr[A]i2cReg[A]S Addr Rd[A][DataLow]A[DataHigh]NA P
' `----------------------------------------------------------
' int i2cProcessCall(unsigned handle, unsigned i2cReg, unsigned wVal)
' This writes 16 bits Of data To the specified register Of the device associated With handle And reads 16 bits Of data In return.
' 
' handle: >= 0, As Returned by a call To i2cOpen
' i2cReg: 0 - 255, the register To Write / Read
'   wVal: 0 - 0 xFFFF, the value To Write
' 
' 
' Returns the word Read ( >= 0) If OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, Or PI_I2C_READ_FAILED.
' 
' Process call.SMBus 2.0 5.5.6
' S Addr Wr[A]i2cReg[A]wValLow[A]wValHigh[A]
'    S Addr Rd[A][DataLow]A[DataHigh]NA P
' `----------------------------------------------------------
' int i2cWriteBlockData(unsigned handle, unsigned i2cReg, char * buf, unsigned count)
' This writes up To 32 bytes To the specified register Of the device associated With handle.
' 
' handle: >= 0, As Returned by a call To i2cOpen
' i2cReg: 0 - 255, the register To Write
'    buf: an array With the data To send
'  count: 1 - 32, the number Of bytes To Write
' 
' 
' Returns 0 If OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, Or PI_I2C_WRITE_FAILED.
' 
' Block write.SMBus 2.0 5.5.7
' S Addr Wr[A]i2cReg[A]count[A]
'    buf0[A]buf1[A]...[A]bufn[A]P
' `----------------------------------------------------------
' int i2cReadBlockData(unsigned handle, unsigned i2cReg, char * buf)
' This reads a block Of up To 32 bytes From the specified register Of the device associated With handle.
' 
' handle: >= 0, As Returned by a call To i2cOpen
' i2cReg: 0 - 255, the register To Read
'    buf: an array To receive the Read data
' 
' 
' The amount Of returned data Is Set by the device.
' 
' Returns the number Of bytes Read ( >= 0) If OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, Or PI_I2C_READ_FAILED.
' 
' Block read.SMBus 2.0 5.5.7
' S Addr Wr[A]i2cReg[A]
'    S Addr Rd[A][Count]A[buf0]A[buf1]A...A[bufn]NA P
' `----------------------------------------------------------
' int i2cBlockProcessCall(unsigned handle, unsigned i2cReg, char * buf, unsigned count)
' This writes data bytes To the specified register Of the device associated With handle And reads a device specified number Of bytes Of data In return.
' 
' handle: >= 0, As Returned by a call To i2cOpen
' i2cReg: 0 - 255, the register To Write / Read
'    buf: an array With the data To send And To receive the Read data
'  count: 1 - 32, the number Of bytes To Write
' 
' 
' Returns the number Of bytes Read ( >= 0) If OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, Or PI_I2C_READ_FAILED.
' 
' The SMBus 2.0 documentation states that a minimum Of 1 byte may be sent And a minimum Of 1 byte may be received.The total number Of bytes sent / received must be 32 Or less.
' 
' Block Write - block read.SMBus 2.0 5.5.8
' S Addr Wr[A]i2cReg[A]count[A]buf0[A]...bufn[A]
'    S Addr Rd[A][Count]A[buf0]A...[bufn]A P
' `----------------------------------------------------------
' int i2cReadI2CBlockData(unsigned handle, unsigned i2cReg, char * buf, unsigned count)
' This reads count bytes From the specified register Of the device associated With handle.The count may be 1 - 32.
' 
' handle: >= 0, As Returned by a call To i2cOpen
' i2cReg: 0 - 255, the register To Read
'    buf: an array To receive the Read data
'  count: 1 - 32, the number Of bytes To Read
' 
' 
' Returns the number Of bytes Read ( > 0) If OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, Or PI_I2C_READ_FAILED.
' 
' S Addr Wr[A]i2cReg[A]
'    S Addr Rd[A][buf0]A[buf1]A...A[bufn]NA P
' `----------------------------------------------------------
' int i2cWriteI2CBlockData(unsigned handle, unsigned i2cReg, char * buf, unsigned count)
' This writes 1 To 32 bytes To the specified register Of the device associated With handle.
' 
' handle: >= 0, As Returned by a call To i2cOpen
' i2cReg: 0 - 255, the register To Write
'    buf: the data To Write
'  count: 1 - 32, the number Of bytes To Write
' 
' 
' Returns 0 If OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, Or PI_I2C_WRITE_FAILED.
' 
' S Addr Wr[A]i2cReg[A]buf0[A]buf1[A]...[A]bufn[A]P
' `----------------------------------------------------------
' int i2cReadDevice(unsigned handle, char * buf, unsigned count)
' This reads count bytes From the raw device into buf.
' 
' handle: >= 0, As Returned by a call To i2cOpen
'    buf: an array To receive the Read data bytes
'  count: > 0, the number Of bytes To Read
' 
' 
' Returns count( > 0) If OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, Or PI_I2C_READ_FAILED.
' 
' S Addr Rd[A][buf0]A[buf1]A...A[bufn]NA P
' `----------------------------------------------------------
' int i2cWriteDevice(unsigned handle, char * buf, unsigned count)
' This writes count bytes From buf To the raw device.
' 
' handle: >= 0, As Returned by a call To i2cOpen
'    buf: an array containing the data bytes To Write
'  count: > 0, the number Of bytes To Write
' 
' 
' Returns 0 If OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, Or PI_I2C_WRITE_FAILED.
' 
' S Addr Wr[A]buf0[A]buf1[A]...[A]bufn[A]P
' `----------------------------------------------------------
' void i2cSwitchCombined(int setting)
' This sets the I2C(i2c - bcm2708)module "use combined transactions" parameter On Or off.
' 
' setting: 0 To set the parameter off, non - zero To set it On
' 
' 
' NOTE: when the flag Is On a Write followed by a Read To the same slave address will Use a repeated start(rather than a Stop / start).
' `----------------------------------------------------------
' int i2cSegments(unsigned handle, pi_i2c_msg_t * segs, unsigned numSegs)
' This function executes multiple I2C segments In one transaction by calling the I2C_RDWR ioctl.
' 
'  handle: >= 0, As Returned by a call To i2cOpen
'    segs: an array Of I2C segments
' numSegs: > 0, the number Of I2C segments
' 
' 
' Returns the number Of segments If OK, otherwise PI_BAD_I2C_SEG.
' `----------------------------------------------------------
' int i2cZip(unsigned handle, char * inBuf, unsigned inLen, char * outBuf, unsigned outLen)
' This function executes a sequence Of I2C operations.The operations To be performed are specified by the contents Of inBuf which contains the concatenated command codes And associated data.
' 
' handle: >= 0, As Returned by a call To i2cOpen
'  inBuf: pointer To the concatenated I2C commands, see below
'  inLen: size Of command buffer
' outBuf: pointer To buffer To hold returned data
' outLen: size Of Output buffer
' 
' 
' Returns >= 0 If OK(the number Of bytes Read ), otherwise PI_BAD_HANDLE, PI_BAD_POINTER, PI_BAD_I2C_CMD, PI_BAD_I2C_RLEN.PI_BAD_I2C_WLEN, Or PI_BAD_I2C_SEG.
' 
' The following command codes are supported:
' 
' Name Cmd & Data Meaning
' End 0 No more commands
' Escape 1 Next P Is Two bytes
' On 2 Switch combined flag On
' Off 3 Switch combined flag off
' Address 4 P Set I2C address To P
' Flags 5 lsb msb Set I2C flags To lsb + (msb < < 8)
' Read 6 P Read P bytes Of data
' Write 7 P... Write P bytes Of data
' 
' 
' The address, Read , And Write commands take a parameter P.Normally P Is One byte(0 - 255).If the command Is Preceded by the Escape command Then P Is Two bytes(0 - 65535, least significant byte first).
' 
' The address defaults To that associated With the handle.The flags Default To 0. The address And flags maintain their previous value Until updated.
' 
' The returned I2C data Is Stored In consecutive locations Of outBuf.
' 
' Example
' 
' Set address 0 x53, Write 0 x32, Read 6 bytes
' Set address 0 x1E, Write 0 x03, Read 6 bytes
' Set address 0 x68, Write 0 x1B, Read 8 bytes
' End
' 
' 0 x04 0 x53 0 x07 0 x01 0 x32 0 x06 0 x06
' 0 x04 0 x1E 0 x07 0 x01 0 x03 0 x06 0 x06
' 0 x04 0 x68 0 x07 0 x01 0 x1B 0 x06 0 x08
' 0 x00
' `----------------------------------------------------------
' int bbI2COpen(unsigned SDA, unsigned SCL, unsigned baud)
' This function selects a pair Of GPIO For bit banging I2C at a specified baud rate.
' 
' Bit banging I2C allows For certain operations which are Not possible With the standard I2C driver.
' 
' o baud rates As Low As 50
' o repeated starts
' o clock stretching
' o I2C On any pair Of spare GPIO
' 
'  SDA: 0 - 31
'  SCL: 0 - 31
' baud: 50 - 500000
' 
' 
' Returns 0 If OK, otherwise PI_BAD_USER_GPIO, PI_BAD_I2C_BAUD, Or PI_GPIO_IN_USE.
' 
' NOTE:
' 
' The GPIO used For SDA And SCL must have pull - ups To 3 V3 connected.As a guide the hardware pull - ups On pins 3 And 5 are 1 k8 In value.
' int bbI2CClose(unsigned SDA)
' This function stops bit banging I2C On a pair Of GPIO previously opened With bbI2COpen.
' 
' SDA: 0 - 31, the SDA GPIO used In a prior call To bbI2COpen
' 
' 
' Returns 0 If OK, otherwise PI_BAD_USER_GPIO, Or PI_NOT_I2C_GPIO.
' `----------------------------------------------------------
' int bbI2CZip(unsigned SDA, char * inBuf, unsigned inLen, char * outBuf, unsigned outLen)
' This function executes a sequence Of bit banged I2C operations.The operations To be performed are specified by the contents Of inBuf which contains the concatenated command codes And associated data.
' 
'    SDA: 0 - 31( As Used In a prior call To bbI2COpen)
'  inBuf: pointer To the concatenated I2C commands, see below
'  inLen: size Of command buffer
' outBuf: pointer To buffer To hold returned data
' outLen: size Of Output buffer
' 
' 
' Returns >= 0 If OK(the number Of bytes Read ), otherwise PI_BAD_USER_GPIO, PI_NOT_I2C_GPIO, PI_BAD_POINTER, PI_BAD_I2C_CMD, PI_BAD_I2C_RLEN, PI_BAD_I2C_WLEN, PI_I2C_READ_FAILED, Or PI_I2C_WRITE_FAILED.

'#####################################################################
'Konstanten
Const PI_INPUT As Integer = 0
Const PI_OUTPUT As Integer = 1


Static Public intOut As Integer

Public Sub Form_Open()

  Dim IntReply As Integer

  IntReply = gpioInitialise()

  If IntReply < 0 Then
    Label1.Text = "Fehler, Bitte als ROOT starten!"
    Button1.Enabled = False

  Else

    Label1.Text = "OK, pigpio Version: " & IntReply
    Me.Text = "Pi Hardware Rev: " & Hex$(gpioHardwareRevision())
    Me.Text &= ", piogpio Version: " & gpioVersion()
  Endif

End

Public Sub Form_Close()

  gpioTerminate()

End

Public Sub Button1_Click()


  Dim intPin As Integer
  Dim intMode As Integer
  Dim intLevel As Integer
  Dim INT_RET As Integer
  
  Label1.Text = ""
  Label2.Text = ""

  

  If intOut = 1 Then
     intOut = 0
  Else
     intOut = 1  
   Endif
   
   
   For intPin = 0 To 31
     IntMode = gpioSetMode(IntPin, PI_OUTPUT)
   
     INT_RET = gpioWrite(intPin, intOut)
     
     IntLevel = gpioRead(intPin)
     
     Label2.Text &= intLevel & ", "
       
  Next   

    
End





Public Sub Button2_Click()

   READ_ADW() 

End
Public Sub READ_ADW()
' READ_ADW  = Lese_AnaloDigitalWandler
'=====================================
Dim Dev_Handle As Integer
 
Dim Int_RET As Integer

Dim Byte01 As Integer
Dim Byte02 As Integer
Dim Byte03 As Integer
Dim Byte04 As Integer
Dim Byte05 As Integer
Dim Byte06 As Integer
Dim Byte07 As Integer
Dim Byte08 As Integer

Dim Antwort01 As Integer
Dim Antwort02 As Integer
Dim Antwort03 As Integer
Dim Antwort04 As Integer
Dim Antwort05 As Integer
Dim Antwort06 As Integer
Dim Antwort07 As Integer
Dim Antwort08 As Integer

Dim High_Byte As Integer
Dim Low_byte As Integer

  
' BASCOM - Quellcode: ADS1115
' 
'     'ADS1115 16Bit A/D Wandler
'     $regfile = "m328pdef.dat"
'     $crystal = 16000000
'     $hwstack = 32
'     $swstack = 32
'     $framesize = 32
'          '
'     Dim N As Byte
'     Dim High_byte(4) As Byte
'     Dim Low_byte(4) As Byte
'     Dim Ads_high(4) As Byte
'     Dim Ads_low(4) As Byte
'     Dim Volt(4) As Single
'     Dim Wert(4) As Integer
'     Config Sda = Portc.4                                        'I2C-Pins definieren
'     Config Scl = Portc.5
'     Dim Lcd_backlight As Byte
'     $lib "YwRobot_Lcd_i2c.lIb"
'     Const Pcf8574_lcd = 64                                      'Adresse LCD
'     Config Lcd = 20 x4                                           '40x4,16x1, 16x2, 16x4, 16x4, 20x2, 20x4, 16x1a or 20x4A.
'     Config I2cdelay = 2
'     Initlcd                                                     'LCD initialisieren
'     Cursor Off Noblink                                          'Noblink , Blink, On, Off
'     Cls
'     Waitms 300
'     'Adresse ADS1115 Adresspin = low
'     Const Ads1115_write = &H90
'     Const Ads1115_read = &H91
'     'Const Ad_wert = 1.024 / 32767                               '1024
'     'Const Ad_wert = 2.048 / 32767                               '2048
'     'Const Ad_wert = 4.096 / 32767                               '4096
'     Const Ad_wert = 6.144 / 32767                               '6144
'     'High Byte
'     'Bit 15 Operational status
'     'When writing
'     'No effect                 = &B0xxxxxxx xxxxxxxx
'     'Start a single conversion = &B1xxxxxxx xxxxxxxx
'     'When reading
'     'Device is currently performing a conversion     = &B0xxxxxxx xxxxxxxx
'     'Device is not currently performing a conversion = &B1xxxxxxx xxxxxxxx
'     'Bit 14..12   Input Multiplexer configuration
'     'Ain0+Ain1= &Bx000xxxx xxxxxxxx default
'     'Ain0+Ain3= &bx001xxxx xxxxxxxx
'     'Ain1+Ain3= &Bx010xxxx xxxxxxxx
'     'Ain2+Ain3= &bx011xxxx xxxxxxxx
'     'Ain0+GND=  &Bx100xxxx xxxxxxxx
'     'Ain1+GND=  &Bx101xxxx xxxxxxxx
'     'Ain2+GND=  &Bx110xxxx xxxxxxxx
'     'Ain3+GND=  &Bx111xxxx xxxxxxxx
'     'Bit 11..9   Gain amplifier configuration
'      'FSR 6.144V= &Bxxxx000x xxxxxxxx
'      'FSR 4.096V= &Bxxxx001x xxxxxxxx
'      'FSR 2.048V= &Bxxxx010x xxxxxxxx  default
'      'FSR 1.024V= &Bxxxx011x xxxxxxxx
'      'FSR 0.512V= &Bxxxx100x xxxxxxxx
'      'FSR 0.256V= &Bxxxx101x xxxxxxxx
'      'FSR 0.256V= &Bxxxx110x xxxxxxxx
'      'FSR 0.256V= &Bxxxx111x xxxxxxxx
'      'Bit 8   Device operating mode
'     'Continuous-conversion mode = &Bxxxxxxx0 xxxxxxxx
'     'Single-Shot mode           = &Bxxxxxxx1 xxxxxxxx  default
'     '------------------------------------------------------------------------
'     'Low Byte
'     'Bit 7..5   Data Rate
'     '  8SPS= &Bxxxxxxxx 000xxxxx
'     ' 16SPS= &Bxxxxxxxx 001xxxxx
'     ' 32SPS= &Bxxxxxxxx 010xxxxx
'     ' 64SPS= &Bxxxxxxxx 011xxxxx
'     '128SPS= &Bxxxxxxxx 100xxxxx   default
'     '250SPS= &Bxxxxxxxx 101xxxxx
'     '475SPS= &Bxxxxxxxx 110xxxxx
'     '860SPS= &Bxxxxxxxx 111xxxxx
'     'Bit 4 Comparator Mode
'      'Traditonal  = &Bxxxxxxxx  xxx0xxxx   default
'      'Window      = &Bxxxxxxxx  xxx1xxxx
'     'Bit 3 Comparator polarity
'     'Active low = &Bxxxxxxxx xxxx0xxx default
'     'Active high= &Bxxxxxxxx xxxx1xxx
'     'Bit 2 Latching Comparator
'     'Nonlatching = &Bxxxxxxxx xxxxx0xx  default
'     'Latching    = &Bxxxxxxxx xxxxx1xx
'     'Bit 1.0 Comparator queue and disable
'     'Assert after one conversion   = &Bxxxxxxxx xxxxxx00
'     'Assert after two conversiosn  = &Bxxxxxxxx xxxxxx01
'     'Assert after four conversions = &Bxxxxxxxx xxxxxx10
'     'Disable Comparator             = &Bxxxxxxxx xxxxxx11  default
'     High_byte(1) = &B11000000
'     High_byte(2) = &B11010000
'     High_byte(3) = &B11100000
'     High_byte(4) = &B11110000
'     Low_byte(1) = &B00000000
'     Low_byte(2) = &B00000000
'     Low_byte(3) = &B00000000
'     Low_byte(4) = &B00000000
'     '******************* Hauptprogramm *************************************
'     Do
'        For N = 1 To 4
'           GoSub On_ads1115                                      'ADS1115 auslesen
'           Wert(n) = 256 * Ads_high(n): Wert(n) = Wert(n) + Ads_low(n)
'           Volt(n) = Ad_wert * Wert(n)
'           Locate N, 1: Lcd "              "
'           Locate N, 1: Lcd Fusing(volt(n), "#.######"); " Volt"
'           Waitms 250
'        Next
'     Loop
'     End
'     '***************** Ende Hauptprogramm **********************************
'     On_ads1115:
'        I2cstart
'        I2cwbyte Ads1115_write
'        I2cwbyte &B00000001                1 Byte
'        I2cwbyte High_byte(n)              2 Byte
'        I2cwbyte Low_byte(n)               3 Byte
'        I2cstop
'        I2cstart
'        I2cwbyte Ads1115_write
'        I2cwbyte 0
'        I2cstart
'        I2cwbyte Ads1115_read
'        I2crbyte Ads_high(n), Ack
'        I2crbyte Ads_low(n), Nack
'        I2cstop
'     Return

    High_byte = &B11000000
    Low_byte = &B00000000
    
    Dev_Handle = i2cOpen(1, 72, 0)  ' 72
    Label1.Text = Str$(Dev_Handle)
  
    'Int_RET = i2cWriteByte(handle As Integer, Wert As Integer) As Integer
    'Int_RET = i2cReadByte(handle As Integer) As Integer

     Byte01 = 1       '&B00000001 
     Label4.Text = Byte01
     Antwort01 = i2cWriteByte(Dev_Handle, Byte01)
     Label5.Text = Antwort01 
     
     Byte02 = 192     '&B11000000
     Label6.Text = Byte02
     Antwort02 = i2cWriteByte(Dev_Handle, Byte02)
     Label7.Text = Antwort02
     
     Byte03 = 0       '&B00000000
     Label8.Text = Byte03
     Antwort03 = i2cWriteByte(Dev_Handle, Byte03)
     Label9.Text = Antwort03
   
 
 
 
     Byte04 = 0       '&B00000000
     Label10.Text = Byte04
     Antwort04 = i2cWriteByte(Dev_Handle, Byte04)
     Label11.Text = Antwort04
 
 
      
     High_Byte = i2cReadByte(Dev_Handle)
     Low_Byte = i2cReadByte(Dev_Handle)
     Label3.Text = High_Byte & "," & Low_Byte

  
     Int_RET = i2cClose(Dev_Handle)
     Label2.Text = Str$(Int_RET)

  
  
End


Ich habe alle Ret Codes ausgegeben es waren keine Fehler dabei. Der Baustein hat die Adresse H48 !

Danke für eine Antwort !!

Gruss Günni

Benutzeravatar
gambi
Moderator
Beiträge: 322
Registriert: Mi 8. Mai 2013, 22:46
Kontaktdaten:

Re: PIGPIO Lib (i2c Funktionen)

Beitrag von gambi » Di 23. Jan 2018, 21:55

Hallo Günni,
ich habe deinen Beitrag nach Hardware verschoben.

gg

Antworten

Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 0 Gäste