- 3D-Druck Einstieg und Tipps         
Seite 1 von 2 12 LetzteLetzte
Ergebnis 1 bis 10 von 13

Thema: Interrupts vom i2c_TWI-slave.LBX stören (if Then) im Hauptpr

  1. #1
    Benutzer Stammmitglied
    Registriert seit
    15.09.2004
    Beiträge
    30

    Interrupts vom i2c_TWI-slave.LBX stören (if Then) im Hauptpr

    Anzeige

    Powerstation Test
    Hallo,
    brauch mal Hilfe ...

    Habe mir jetzt die Bascom I2cslav.lib gekauft
    und habe seit ich die
    i2c_TWI-slave.LBX
    verwend Probleme im Hauptprogramm die zeigen sich bei den
    If Then Befehlen .

    Bei :
    Dim Test_w As Word
    Dim Test As Byte

    Do
    Test = 250
    Test_w = 250
    If Test <> Test_w Then Print "Fehler <> "
    If Test > 250 Then Print "Fehler > 250 " ; Test
    If Test < 250 Then Print "Fehler <250 " ; Test
    If Test_w > 250 Then Print "Fehler W > 250 " ; Test_w
    If Test_w < 250 Then Print "Fehler W <250 " ; Test_w

    Loop


    Erhalte ich immer mal wieder eine Fehlerhafte Auswertung
    im Slave AVR (immer dann wenn der Master Daten Anfordert) ,
    es wird also geprintet zB: Fehler > 250 250

    Warum aber ???

    setze ich vor die IF Then Auswertung ein
    Disable Interrupts und danach ein Enable Interrupts
    zeigt sich die Fehler nicht ,(dann hat aber der Master Aussetzer)



    Bascom 1.11.8.3
    Slave M8 mit 8 Mhz (M88 20 Mhz gleiche Fehler)
    Master M32
    i2c_TWI-slave.LBX - - > 1.11.7.5 30.June2004

    Wie oft : Bei ca.50 Abfragen vom Master (je 5 Byte) zum Slave kommen
    3 Fehler

    wie ich das ganze noch ohne die Lib so wie im Wiki
    https://www.roboternetz.de/wissen/index.php/TWI_Praxis
    gemacht habe hatte ich diese Fehler nicht


    Bitte eine Hilfe in welche Richtung muß ich suchen ?

    Gruß HansHans

  2. #2
    Erfahrener Benutzer Robotik Einstein
    Registriert seit
    22.05.2005
    Ort
    12°29´ O, 48°38´ N
    Beiträge
    2.731
    Hallo,
    von der Slave-Lib werden doch verschiedene Subroutinen aufgerufen, die man selber erstellen muss, evtl. werden da nicht alle Register gesichert, aber verändert, und deshalb kommt das Hauptprogramm durcheinender

  3. #3
    Benutzer Stammmitglied
    Registriert seit
    15.09.2004
    Beiträge
    30
    Wenn ich die Hilfe zum CONFIG TWISLAVE
    richtig verstehe, müssten aber alle Register gesichert werden
    da ich bei der CONFIG TWISLAVE = address , BTR = value , BITRATE = value SAVE=option
    eben nicht SAVE = NOSAVE schreibe

    aber so was in die Richtung muß es wohl sein.......

    Wie ist da eigentlich wenn man einen Interrupt
    für kurze Zeit sperrt (mit Disable TWI)
    wird dann ein Aufgetretener Interrupt beim wieder freigeben nachgeholt oder geht der verloren ?

  4. #4
    Erfahrener Benutzer Robotik Einstein
    Registriert seit
    22.05.2005
    Ort
    12°29´ O, 48°38´ N
    Beiträge
    2.731
    Ein IRQ wird normalerweise nachgeholt, weil das entsprechende Flag gesetzt bleibt, es kann aber sein, wenns zulange dauert, das das Ereignis schon überholt ist, und nicht mehr richtig darauf reagiert werden kann, dann kommt Chaos raus, in der Subroutine.

    Was hast Du schon in den Subroutinen stehen, bzw. was darf darin vorkommen bis der Fehler mit dem IF auftritt ?

    PS:
    Ich hab diese Slave-Lib nicht, interessiert mich halt was die so treibt.

  5. #5
    Benutzer Stammmitglied
    Registriert seit
    15.09.2004
    Beiträge
    30
    Was hast Du schon in den Subroutinen stehen, bzw. was darf darin vorkommen bis der Fehler mit dem IF auftritt ?
    ..schon fast nicht‘s mehr, habe schon fast alles wieder rausgestrichen

    Nur noch ein minimum ist jetzt drinnen
    Code:
    Config Twislave = 64 , Btr = 5 , Bitrate = 100000      
    .
    .
    .
    
    
    'the following labels are called from the library
    Twi_stop_rstart_received:
     ' Print "Master sent stop or repeated start"
    Return
    
    
    Twi_addressed_goread:
      'Print "We were addressed and master will send data"
    Return
    
    
    Twi_addressed_gowrite:
      'Print "We were addressed and master will read data"
    Return
    
    'this label is called when the master sends data and the slave has received the byte
    'the variable TWI holds the received value
    Twi_gotdata:
       'Print "Empf: " ; Twi
    
        Twi_daten = Twi                                         ' neue Daten merken
        Neuesbyte = 1                                           ' merken das ein neues Byte da ist
    
    
    Return
    
    'this label is called when the master receives data and needs a byte
    'the variable twi_btr is a byte variable that holds the index of the needed byte
    'so when sending multiple bytes from an array, twi_btr can be used for the index
    
    Twi_master_needs_byte:
    
                 Select Case Twi_btr
                    Case 1 : Twi = Low(liter)
                    Case 2 : Twi = High(liter)
                    Case 3 : Twi = Low(menge)
                    Case 4 : Twi = High(menge)
                    Case 5 : Twi = Liter_soll
    
                  End Select
    
        'Print "Sende = " ; Twi
    
    Return
    
    'when the mast has all bytes received this label will be called
    Twi_master_need_nomore_byte:
      'Print "Master does not need anymore bytes"
    Return

    kann mir mal bitte einer betätigen das die
    i2c_TWI-slave.LBX - - > 1.11.7.5 30.June2004 die
    "Neuste" ist ?
    oder wo bekommt man für die zusätzlich erworbenen Lib‘s die Updats?

    Werde es dann mal andersrum testen, und die
    if then's in das Beispielprogramm von MCS einfugen

  6. #6
    Benutzer Stammmitglied
    Registriert seit
    15.09.2004
    Beiträge
    30
    So jetzt habe ich die Demo's abgeändert und habe auch wieder
    „Fehler“ im Hauptprogramm vom Slave M88 wenn der Master
    Daten holt.
    (Die Datenübertragung klappt fehlerfrei )

    Ich bin Rat los .................


    Kann man die lib nur Ohne Hauptprogramm nutzen ?

    Master (Original nur f. M32 abgeändert ) :

    Code:
    '-------------------------------------------------------------------------------
    '                            (c) 2004 MCS Electronics
    '                        This demo shows an example of the M8 TWI
    '                       Not all AVR chips have TWI (hardware I2C)
    '-------------------------------------------------------------------------------
    
    'The chip will work in TWI/I2C master mode
    'Connected is another Mega8 in TWI-slave mode
     $regfile = "m32def.dat"
    $crystal = 6144000
    $programmer = 13
    
    $loadersize = 2048
    
    
    $hwstack = 64
    $swstack = 64
    $framesize = 64
    
    Config Lcdpin = Pin , Db4 = Portb.4 , Db5 = Portb.5 , Db6 = Portb.6 , Db7 = Portb.7 , E = Portb.3 , Rs = Portb.2
    
    
    
    Config Lcd = 24 * 2
    
    $baud = 19200
    
    '$regfile = "M8def.dat"                                      ' the used chip
    '$crystal = 4000000                                          ' frequency used
    '$baud = 19200                                               ' baud rate
    
    $lib "i2c_twi.lbx"                                          ' we do not use software emulated I2C but the TWI
    
    Config Scl = Portc.5                                        ' we need to provide the SCL pin name
    Config Sda = Portc.4                                        ' we need to provide the SDA pin name
    
    'On the Mega8,          On the slave Mega8
    'scl=PC5 , pin 28            scl=PC5 , pin 28
    'sda=PC4 , pin 27            sda=PC4 , pin 27
    
    'the M8 slave uses a simple protocol
    'WRITE -> Start-address-B1-B2-STOP
    'READ  -> start-address-B1-B2-STOP
    'start -> I2CSTART
    'address-the slave address
    'B1 and B2 are 2 bytes that when written, write to B1
    '                           when read , return A/D converter value
    
    
    Dim B1 As Byte , B2 As Byte
    Dim W As Word At B1 Overlay
    
    
    I2cinit                                                     ' we need to set the pins in the proper state
    
    
    Twbr = 12                                                   'bit rate register
    Twsr = 0                                                    'pre scaler bits
    
    Dim B As Byte , X As Byte
    Print "Mega32 TWI master demo"
    
    Do
      I2cstart
      I2cwbyte &H70                                             ' slave address write
      I2cwbyte &B10101010                                       ' write command
      I2cwbyte 2
      I2cstop
      Print "Error : " ; Err                                    ' show error status
    
      I2cstart
      I2cwbyte &H71
      I2crbyte B1 , Ack
      I2crbyte B2 , Nack
      I2cstop
      Print "Error : " ; Err                                    ' show error
      Print "received A/D : " ; W
      Waitms 500                                                'wait a bit
    Loop
    End


    Slave (mit If Then f. M8:
    Code:
    '-------------------------------------------------------------------------------
    '                            (c) 2004 MCS Electronics
    '                This demo shows an example of the TWI in SLAVE mode
    '                       Not all AVR chips have TWI (hardware I2C)
    '  This demo is a Mega8 I2C A/D converter slave chip
    ' NOTICE that this demo will only work with the TWI slave library which is avaialble as an add on
    ' SDA pin is PORTC.4 (pin 27)
    ' SCL pin is PORTC.5 (pin 28)
    '-------------------------------------------------------------------------------
    $regfile = "M88def.dat"                                     ' the chip we use
    $crystal = 20000000                                         ' crystal oscillator value
    $baud = 19200                                               ' baud rate
    $hwstack = 64
    $swstack = 64
    $framesize = 32
    $programmer = 1
    
    $lib "i2c_twi-slave.lbx"
    
    Print "Fehler Test  M8 TWI-slave demo"
    Print "Use with M8-TWI master demo"
    
    Config Adc = Single , Prescaler = Auto
    'Now give power to the chip
    Start Adc
    
    Dim W As Word
    Config Portb = Output
    
    
    Dim Test As Byte
      Dim Test_w As Word
    
    
    Dim Status As Byte                                          'only for debug
    'Print Hex(status)
    
    Config Twislave = &H70 , Btr = 2 , Bitrate = 100000
    '                   ^--- slave address
    '                         ^---------- 2 bytes to receive
    '                                     ^--- bitrate is 100 KHz
    
    
    'The variables  Twi , Twi_btr and Twi_btw are created by the compiler. These are all bytes
    'The TWI interrupt is enabled but you need to enabled the global interrupt
    
    
    Enable Interrupts
    
    'this is just an empty loop but you could perform other tasks there
    Do
    
    
      Test = 250
      Test_w = 250
    If Test <> Test_w Then Print "Fehler <>  "
    If Test > 250 Then Print "Fehler > 250   " ; Test
    If Test < 250 Then Print "Fehler <250   " ; Test
    If Test_w > 250 Then Print "Fehler W > 250   " ; Test_w
    If Test_w < 250 Then Print "Fehler W <250   " ; Test_w
    
    
    
    
    
    
    
      'Print Getadc(0)
      'Waitms 500
      nop
    Loop
    End
    
    
    
    
    'The following labels are called from the library. You need to insert code in these subroutines
    'Notice that the PRINT commands are remarked.
    'You can unmark them and see what happens, but it will result in occasional errors in the transmission
    'The idea is that you write your code in the called labels. And this code must execute in as little time
    'as possible. So when you slave must read the A/D converter, you can best do it in the main program
    'then the data is available when the master needs it, and you do not need to do the conversion which cost time.
    
    
    'A master can send or receive bytes.
    'A master protocol can also send some bytes, then receive some bytes
    'The master and slave must match.
    
    'the following labels are called from the library  when master send stop or start
    Twi_stop_rstart_received:
     ' Print "Master sent stop or repeated start"
    Return
    
    'master sent our slave address and will not send data
    Twi_addressed_goread:
     ' Print "We were addressed and master will send data"
    Return
    
    
    Twi_addressed_gowrite:
     ' Print "We were addressed and master will read data"
    Return
    
    'this label is called when the master sends data and the slave has received the byte
    'the variable TWI holds the received value
    Twi_gotdata:
      ' Print "received : " ; Twi ; " byte no : " ; Twi_btw
       Select Case Twi_btw
         Case 1 : Portb = Twi                                   ' first byte
         Case 2:                                                'you can set another port here for example
       End Select
    Return
    
    'this label is called when the master receives data and needs a byte
    'the variable twi_btr is a byte variable that holds the index of the needed byte
    'so when sending multiple bytes from an array, twi_btr can be used for the index
    Twi_master_needs_byte:
      'Print "Master needs byte : " ; Twi_btr
      Select Case Twi_btr
        Case 1:                                                 ' first byte
                  W = Getadc(0)                                 'in this example the conversion is done here
                  ' but a better option would have been to just pass the value of W and do the conversion in the main loop
                  Twi = Low(w)
        Case 2                                                  ' send second byte
                  Twi = High(w)
      End Select
    Return
    
    
    'when the mast has all bytes received this label will be called
    Twi_master_need_nomore_byte:
     ' Print "Master does not need anymore bytes"
    Return
    Hat jemand die möglichkeit das zu Testen ?

    Danke
    Gruß HansHans

  7. #7
    Benutzer Stammmitglied
    Registriert seit
    15.09.2004
    Beiträge
    30
    Hallo,
    ich komme nicht weiter....
    Habe aber den Fehler etwas weiter eingekreist , der Fehler tritt auf wenn es vom der ISP :

    Twi_master_needs_byte nach dem Return
    zurück ins Hautprogramm geht

    Also doch was mit den Registern ?

    Hat den keiner diese "i2c_twi-slave.lbx" ?

    und kann mal schreiben ob
    Vers. 1.11.7.5 vom 30.June2004
    die aktuellste ist ??

    gehört zu der i2c_twi-slave.LBX nicht auch eine i2c_twi-slave.LIB Datei ?
    ich habe von MCS im Dez/06 nur diese:

    i2c_TWI-slave.LBX
    i2cslave.LBX
    i2cslave.lib
    i2cslave.pdf
    i2cslave_pcf8574.bas
    TWI-slave.bas

    bekommen und vermisse somit eigendlich eine i2c_TWI-slave.lib


    Danke für’s nachsehen
    Gruß
    HansHans

  8. #8
    Benutzer Stammmitglied
    Registriert seit
    15.09.2004
    Beiträge
    30
    ............ Erster Lichtblick ..............
    ................ Danke nach Texas ................

    (Fragen von oben aber noch offen)

  9. #9
    Hmm ja mit deinem eigentlichen Problem habe ich mich nicht befasst, aber hab mal kurz nachgelesen zu den libs.
    Zitat von mcselec:
    "Most new AVR chips have a so called TWI interface. As a customer of the I2C slave lib, you can get both libs.
    The TWI slave lib works in interrupt mode and is the best way as it adds less overhead and also less system resources."

    Also solltest du 2 libs bekommen haben. Eine für Software I2C und eine für Hardware I2C !! Wenn ichs richtig verstanden habe.

    oder zum selbernachlesen:
    http://avrhelp.mcselec.com/bascom-avr.html?I2CTWISlave

  10. #10
    Erfahrener Benutzer Roboter Genie
    Registriert seit
    16.04.2005
    Ort
    Aarau
    Alter
    41
    Beiträge
    982
    konntest du das problem mit der i2c_TWI-slave.LBX beheben?

    ich habe momentan genau das gleiche problem... sobld ich im hauptprogramm irgendwelche berechnungen mache werden die ergebnisse total verfälscht...

    gruss bluesmash

Seite 1 von 2 12 LetzteLetzte

Berechtigungen

  • Neue Themen erstellen: Nein
  • Themen beantworten: Nein
  • Anhänge hochladen: Nein
  • Beiträge bearbeiten: Nein
  •  

MultiPlus Wechselrichter Insel und Nulleinspeisung Conrad