Forum: Mikrocontroller und Digitale Elektronik Attiny2313 USI als TWI


von Matthias (Gast)


Lesenswert?

Hallo,

ich versuche jetzt schon einen Tag lang, die USI als TWI zu 
initialisieren.
Ich bekomme es einfach nicht hin einen Takt an SCL auszugeben.

hier mein Code. (Sind auch Testsachen dabei)
1
.include "tn2313def.inc"
2
3
4
5
6
.def temp1 = r16
7
.def temp2 = r17
8
.def temp3 = r18
9
10
11
    
12
.org 0x0000
13
    rjmp main
14
15
.org 0x000D
16
    rjmp timer0compare64
17
18
.org 0x000E
19
    rjmp timer0compare128
20
21
main:
22
23
    ldi temp1, LOW(RAMEND)
24
    out SPL, temp1
25
26
    ldi  temp1, 0b00100000
27
    out DDRD, temp1
28
29
30
    ldi temp1, 0b00000001
31
    out TCCR0B, temp1    ;Timer 0 Voreiler 1
32
    
33
    ldi temp1, 0b01000000
34
    out OCR0A, temp1    ;Timer 0 Compare 128
35
  
36
    ldi temp1, 0b10001000
37
    out OCR0B, temp1    ;Timer 0 Compare 128
38
39
    ldi temp1, 0b00000111
40
    out TIMSK, temp1    ;Timer 0 Interrupt enable
41
42
43
    ldi temp1, 0b00100100
44
    out USICR, temp1
45
    
46
  
47
48
49
50
    sei
51
52
53
54
55
    
56
loop:
57
58
59
60
rjmp loop
61
62
timer0compare64:
63
64
    cbi PORTD, 5  
65
66
  
67
    reti
68
69
timer0compare128:
70
71
    sbi PORTD,5 
72
  
73
74
  ;  ldi temp1, 0b00000000
75
  ;  out TCNT0, temp1
76
    reti

Könnt ihr mir ein par Denkanstöße geben.Komme auch mit googlen nicht 
weiter.

Danke!
mfg, Matthias

von Floh (Gast)


Lesenswert?

Matthias schrieb:
> ich versuche jetzt schon einen Tag lang, die USI als TWI zu
> initialisieren.

> ldi temp1, 0b00100100
>     out USICR, temp1

ist das alles?
z.b. im tiny26
"Since the clock also increments the counter, a counter overflow can be 
used to indicate
that the transfer is completed. The clock is generated by the master by 
toggling the PB2
pin via the PORTB Register."
Also toggel mal schön 16mal die Clockleitung.

von Floh (Gast)


Lesenswert?

Nachtrag:
> Also toggel mal schön 16mal die Clockleitung.
Im Sinne von einfach mal:
sbi
nop
cbi
nop
...
Und schauen obs da funktioniert.
Wenn ja stimmt was mit dem Timer nicht.
:-)

von Matthias (Gast)


Lesenswert?

Danke!

hatte ich vorher schon mal probiert (babe das falsche bit als Ausgang 
gesetzt).

Jetzt habe ich meinen Takt.

Wenn ich die USI als SPI initialisiere, ist der Takt schön.
Wenn ich die USI als TWI initialisiere, ist die ecke beim Takt vom
wechsel von 0 auf 1 leicht abgrundet.

Hat dazu jemand eine Idee.

mfg
Matthias

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.