BASCOM TWI-Master Library - Problem

Gast #206996
Lesenswert?

Hallo,

ich versuche mich gerade in die I2C Programmierung in Bascom
einzuarbeiten. Zum testen habe ich einen PCF8574 am Mega16 an den
Hardware-Twi angeschlossen. Das folgende Programm erzeugt ein
(Knight-Rider :-))Lauflicht am PCF8574. Der I2C-Bus wird dabei von
Bascom softwaremässig realisiert.

$regfile = "m16def.dat"
$crystal = 8000000

Config Scl = Portc.0
Config Sda = Portc.1

I2cinit

Dim Pcfadresse5 As Byte

Pcfadresse5 = &B01001000

Dim A As Integer
A = 17

Do

Gosub Linie1

Loop

Linie1:
  I2csend Pcfadresse5 , 254 : Waitms A
  I2csend Pcfadresse5 , 253 : Waitms A
  I2csend Pcfadresse5 , 251 : Waitms A
  I2csend Pcfadresse5 , 247 : Waitms A
  I2csend Pcfadresse5 , 239 : Waitms A
  I2csend Pcfadresse5 , 223 : Waitms A
  I2csend Pcfadresse5 , 191 : Waitms A
  I2csend Pcfadresse5 , 127 : Waitms A
  I2csend Pcfadresse5 , 191 : Waitms A
  I2csend Pcfadresse5 , 223 : Waitms A
  I2csend Pcfadresse5 , 239 : Waitms A
  I2csend Pcfadresse5 , 247 : Waitms A
  I2csend Pcfadresse5 , 251 : Waitms A
  I2csend Pcfadresse5 , 253 : Waitms A
  I2csend Pcfadresse5 , 254 : Waitms A
  I2csend Pcfadresse5 , 255
Return

Wenn ich jedoch die Harware-TWI Library "i2c_twi.lbx" benutze
funktioniert das ganze zwar auch noch, jedoch vieeel (geschätzt- um den
Faktor 5)langsamer.


$regfile = "m16def.dat"
$crystal = 8000000
$lib "i2c_twi.lbx"


Config Scl = Portc.0
Config Sda = Portc.1

I2cinit

Config Twi = 100000

Dim Pcfadresse5 As Byte

Pcfadresse5 = &B01001000

Dim A As Integer
A = 17

Do

Gosub Linie1

Loop

Linie1:
  I2csend Pcfadresse5 , 254 : Waitms A
  I2csend Pcfadresse5 , 253 : Waitms A
  I2csend Pcfadresse5 , 251 : Waitms A
  I2csend Pcfadresse5 , 247 : Waitms A
  I2csend Pcfadresse5 , 239 : Waitms A
  I2csend Pcfadresse5 , 223 : Waitms A
  I2csend Pcfadresse5 , 191 : Waitms A
  I2csend Pcfadresse5 , 127 : Waitms A
  I2csend Pcfadresse5 , 191 : Waitms A
  I2csend Pcfadresse5 , 223 : Waitms A
  I2csend Pcfadresse5 , 239 : Waitms A
  I2csend Pcfadresse5 , 247 : Waitms A
  I2csend Pcfadresse5 , 251 : Waitms A
  I2csend Pcfadresse5 , 253 : Waitms A
  I2csend Pcfadresse5 , 254 : Waitms A
  I2csend Pcfadresse5 , 255 :
Return

Wende ich die Library falsch an ? Hat schon jemand mit der Library
gearbeitet?

Torsten
Gast #2067827
Lesenswert?

Ist schon ein alter Thread, aber vieleicht hilft es jemanden.

>Config Scl = Portc.0
>Config Sda = Portc.1

Config scl und config sda ist nicht notwendig bzw nicht erlaubt, weil 
die µC mit Harware TWI nur an diesem Hardware Twi auch Hardware TWI 
machen können. ;-)

Diese Angeaben soltten reichen

$regfile = "m2560def.dat"
$crystal = 16000000
$lib "i2c_twi.lbx"           'für echte Hardware TWI
Config Twi = 100000          'wanted clock frequency

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren