- fchao-Sinus-Wechselrichter AliExpress         
Seite 2 von 2 ErsteErste 12
Ergebnis 11 bis 12 von 12

Thema: trotz I2Cslave Library zeigt Bascom fehler an

  1. #11
    Erfahrener Benutzer Roboter-Spezialist
    Registriert seit
    24.04.2005
    Ort
    Bayern
    Alter
    37
    Beiträge
    336
    Anzeige

    Powerstation Test
    Doch da war ein Beispielprogramm dabei, doch da zeigt Bascom mir auch nur fehler an.
    Code:
    '-------------------------------------------------------------------------------
    '                            (c) 2004 MCS Electronics
    '                This demo shows an example of the TWI in SLAVE mode
    '                       Not all AVR chips have TWI (hardware I2C)
    '-------------------------------------------------------------------------------
    $regfile = "M32def.dat"                         
    $crystal = 16000000                               
    $baud = 9600                                   
    
    Print "MCS Electronics TWI-slave demo"
    
    #if _build >= 11175
        Config Twislave = &H70 , Btr = 1 , Bitrate = 100000
        ' the code below #else is executed by the compiler when you use version 11175 or higher
    #else
        'as this is available in 1.11.7.5 some manual work mus tbe done
        $lib "i2c_twi-slave.lbx"                      ' include
        $external _twi_slave                          'include code from the lib
    
        Const _twisdaport = Portd
        Const _twisclport = Portd
        Const _twisdaddr = Ddrd
        Const _twisclddr = Ddrd
        Const _twisda = 1
        Const _twiscl = 0
    
        Const Twi_cbtr = 1                            'how many bytes we will receive
    
        Dim Twi As Byte , Twi_btr As Byte
        rcall _twi_init
    
        Twbr = 12                                     'bit rate register
        Twsr = 0
    
        Twar = &B01110000                             ' own slave address
        Twcr = &B01000101                             'general call not enabled
        On Twi _twi_slave_isr Nosave
        Enable Twi
    #endif
    
    
    'as you might need other interrupts as well, you need to enable them manual
    
    Enable Interrupts
    
    'this is just an empty loop but you could perform other tasks there
    Do
      nop
    Loop
    End
    
    '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
    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
    
    '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
    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
      Twi = 65                                        ' twi must be filled with a value
    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

  2. #12
    Erfahrener Benutzer Begeisterter Techniker
    Registriert seit
    17.02.2005
    Ort
    NRW-Bergisches Land
    Beiträge
    311
    Hi,
    schau mal unter:
    https://www.roboternetz.de/phpBB2/vi...3c667e62a79bba
    da steht ja ein Beispiel zum Slave.
    Die Slave LIB braucht man für die ganzen Tinys die ja kein hardware TWI haben. Der M8 Ist da irgendwie eine Ausnahme.
    Der M8 hat ja Hardware TWI, geht aber auch mit der Slave LIB.
    Die größeren Megas gehen wohl dann nur mit dem Hardware TWI als Slave.

    Gruß RePi!

Seite 2 von 2 ErsteErste 12

Berechtigungen

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

Labornetzteil AliExpress