Atmega1284p SPI

Gast #2833234
Lesenswert?

Hallo,
ich habe ein Problem. Ich möchte eigentlich nur ein paar Bytes über den 
SPI senden im Mastermode. Prozessor ist Mega1284p.
Code unten.
Eigentlich sollte im SPCR 0x51 sein. Gelesen wird aber 0x60. Gibt es 
irgendeinen Fehler, den ich mache??

Danke im voraus

freddyv.95
1
.include "m1284pdef.inc"
2
.def temp1 = r16
3
.def temp2 = r17
4

5
.equ F_CPU = 18432000                            ; Systemtakt in Hz
6
.equ BAUD  = 19200                             ; Baudrate
7
 
8
; Berechnungen
9
.equ UBRR_VAL   = ((F_CPU+BAUD*8)/(BAUD*16)-1)  ; clever runden
10
.equ BAUD_REAL  = (F_CPU/(16*(UBRR_VAL+1)))     ; Reale Baudrate
11
.equ BAUD_ERROR = ((BAUD_REAL*1000)/BAUD-1000)  ; Fehler in Promille
12
 
13
.if ((BAUD_ERROR>10) || (BAUD_ERROR<-10))       ; max. +/-10 Promille Fehler
14
  .error "Systematischer Fehler der Baudrate grösser 1 Prozent und damit zu hoch!"
15
.endif
16

17
.equ PinXCS = 3
18
.equ PinXDCS= 4
19
.equ VSselect = PORTB
20
.equ VSselectddr = DDRB
21

22
.org 0000
23
Reset:
24
  CLI
25
  ldi     temp1, HIGH(RAMEND)
26
    out     SPH, temp1
27
    ldi     temp1, LOW(RAMEND)
28
    out     SPL, temp1
29

30
  CLR    temp1
31
  STS    PRR0, temp1
32
  
33
  ldi     temp1, HIGH(UBRR_VAL)
34
    STS     UBRR0H, temp1
35
    ldi     temp1, LOW(UBRR_VAL)
36
    STS     UBRR0L, temp1
37

38
  ldi   temp1, (1<<TXEN0) | (1<<RXEN0)
39
  sts   UCSR0B, temp1
40
  ldi   temp1, (1<<UCSZ01) | (1<<UCSZ00)
41
  sts   UCSR0C, temp1
42
  ;Jetzt den SPI anschalten
43
  CLR    temp1
44
  OUT    SPSR, temp1
45
  LDI    temp1, (1<<5) | (1<<7)
46
  OUT    DDRB, temp1
47
  LDI    temp1, 0b01010001
48
  OUT    SPCR, temp1
49
  ;Die SS setzen
50
  LDI    temp1, (1<<PinXCS) | (1<PinXDCS)
51
  OUT    VSselectddr, temp1
52
  OUT    VSselect, temp1
53

54
Main:
55
  rcall   serin
56
  CPI    temp2, 'C'
57
  BRNE  Main
58
Main2:
59
  rcall   serin
60
  CPI    temp2, 0x0A
61
  BRNE  Main2
62
Main3:
63
  rcall serout
64
  rcall serin
65
  CPI    temp2, 'G'
66
  BRNE  Main3
67
  rcall serout
68
  LDS    temp2, SPCR
69
  rcall  uart_number_hex
70
  LDI    temp2, 0b01010001
71
  rcall  uart_number_hex

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