AT45DB161D Status Code anfrage bleibt hängen?

Gast #1979987
Lesenswert?

Hallo,
ich finde den Fehler in Code leider nicht.

Aus irgend einen Grund bleibt das Programm bei

result = DF_SPI_RW(0x00); in der Funktion Read_DF_status() hängen...

Kommentiere ich diese Zeile aus läuft das Programm zwar weiter ab nur 
erhalte ich dann 0x00 als Statuscode zurück...

Wo liegt der Fehler? Ich sehe leider gerade gar nichts mehr.

Frohes Fest euer Max ;)


Link zur Schaltung:
http://www.lochraster.org/rumpus/data/rumpus-v2-schematic.pdf
1
#include <stdint.h>
2

3
#include <avr/io.h>
4

5
#include <avr/pgmspace.h>
6

7
//mtE
8

9

10

11
#include "dataflash.h"
12

13

14

15
const uint8_t DF_pagebits[] PROGMEM ={  9,  9,  9,  9,  9,  10,  10,  11};      //index of internal page address bits
16

17
const uint16_t DF_pagesize[] PROGMEM ={264,264, 264, 264, 264, 528, 528,1056};  //index of pagesizes
18

19

20

21

22

23

24

25
unsigned char PageBits = 0;
26

27
unsigned int  PageSize = 0;
28

29

30

31
void DF_SPI_init (void)
32

33
{
34

35
  PORTB |= (1<<PB1) | (1<<PB3) | (1<<PB4) | (1<<PB5);
36

37
  DDRB |= (1<<DDB1) | (1<<DDB3) | (1<<DDB5);    //Set MOSI, SCK AND SS as outputs
38

39
  // mtE
40

41
  SPSR = (1<<SPI2X);                                      //SPI double speed settings
42

43
  SPCR = (1<<SPE) | (1<<MSTR) | (1<<CPHA) | (1<<CPOL);  //Enable SPI in Master mode, mode 3, Fosc/4
44

45
}
46

47

48

49
unsigned char DF_SPI_RW (unsigned char output)
50

51
{
52

53
  unsigned char input;
54

55
  
56

57
  SPDR = output;              //put byte 'output' in SPI data register
58

59
  while(!(SPSR & 0x80));          //wait for transfer complete, poll SPIF-flag
60

61
  input = SPDR;              //read value in SPI data reg.
62

63
  
64

65
  return input;              //return the byte clocked in from SPI slave
66

67
}
68

69

70

71

72

73

74

75
unsigned char Read_DF_status (void)
76

77
{
78

79
  unsigned char result,index_copy;
80

81
  DF_CS_inactive;              //make sure to toggle CS signal in order
82

83
  DF_CS_active;              //to reset dataflash command decoder
84

85
  result = DF_SPI_RW(0x57);      //send status register read op-code
86

87
  result = DF_SPI_RW(0x00);        //dummy write to get result ### Hier hängt er###
88

89
  
90

91
  index_copy = ((result & 0x38) >> 3);  //get the size info from status register
92

93

94

95
  PageBits   = pgm_read_byte(&DF_pagebits[index_copy]);  //get number of internal page address bits from look-up table
96

97
  PageSize   = pgm_read_word(&DF_pagesize[index_copy]);   //get the size of the page (in bytes)
98

99

100

101
  return result;              //return the read status register value
102

103
}
104

105
int main(void)
106

107
{   
108

109
    unsigned char puffer[10];
110

111

112

113

114

115
    uart_init();
116

117
    uart_puts("Hallo");
118

119

120

121
    DF_SPI_init();              // init the SPI interface to communicate with the DataFlash
122

123
    
124

125
    char result = Read_DF_status();
126

127

128
    sprintf(puffer,"%.2x\r\n",result);
129

130
    uart_puts("DF-Status 0x");
131
    uart_puts(puffer);
132

133
    
134

135

136

137
    while(1) {
138

139
        
140

141
    }
142

143

144

145
    return 0;
146

147
}
Gast #1979992
Lesenswert?

sorry leider hab ich noch ein paar Zeilen vergessen:
1
 #define sbiDF(port,bit)  (port |=  (1<<bit))
2

3
#define cbiDF(port,bit)  (port &= ~(1<<bit))
4
#define DF_CS_active  cbiDF(PORTB,1)
5

6
#define DF_CS_inactive  sbiDF(PORTB,1)
Gast #1981118
Lesenswert?

der Eigentlich SS Pin ist schon anderweitig in Benutzung.
Kann ich mit meinen Code oben nicht auch PB1 verwenden?



Ein teil des Problems hab ich schon gelöst --> Kalte Lötstelle

Er Spuckt mir nun auch Teils 0xAC aus wie er soll.
Aber manchmal auch ein 0xFF und das Programm bleibt an besagter Stelle 
hängen.


Wie kann es denn zu so etwas kommen?
Gast #1981148
Lesenswert?

>Wie kann es denn zu so etwas kommen?

Wenn PB2 ein Eingang ist dann wird
der SPI Master zum Slave wenn der Pin low ist.
Als Eingang darf PB2 hier also nur high gehalten
werden. Als Ausgang ist PB2 frei verwendbar. Warum
also nicht gleich als CS für den SPI Slave nehmen?

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