PIC24 MMC init

OP #1710599
Lesenswert?

Hi Jungs,
ich muss eine SD Karte mit nem PIC24FJ64Gb004 ansprechen und nen paar 
Daten darauf spreichern..also quasi als Datenlogger.
Ich verwende den C30 Compiler und habe mir eclipse so eingerichtet das 
er mir das hex file erzeugt.
Da die Hardware noch nicht da ist, simmuliere ich zur Zeit noch in 
Proteus.
Dazu habe ich das MMC Model genommen und da es dort den GB004 nicht gibt 
den GA004. Sollte aber von der Funktion mit der Karte das gleiche sein.


Soweit so gut.
Problem ist nur Ich habe keine Ahnung ;)

Vielleicht könnt ihr mir ja weiter helfen.
Mit dem Oszilloskop sehe ich jetzt die änderungen der Tacktleitung und 
DO
Habe eine leere datei als mmc file gespeichert darin würde ich nun gerne 
meine Daten sehen.
Wie würdet ihr vorgehen? Macht das alles Sinn so oder bin ich da aufm 
Holzweg?

Grüße
Sascha
1
/*
2
 * my_spi.c
3
 *
4
 *  Created on: 13.05.2010
5
 *      Author: Sascha
6
 */
7
#include "my_spi.h"
8
#include "PIC24F_periph_features.h"
9

10
char SPIsend(char d) // Über SPI-Schnittstelle senden
11
{ 
12
  SPI1BUF = d;
13
  while (!SPI1STATbits.SPIRBF)
14
    ;
15
  return SPI1BUF;
16

17
}
18

19

20
void init_spi(void) {
21

22
  int i =  0 ;
23

24
  //from Datasheet pic24fj
25
  /*  To set up the SPI module for the Standard Master mode
26
   of operation:
27
   1. If using interrupts:
28
   a) Clear the SPIxIF bit in the respective IFSx
29
   register.
30
   b) Set the SPIxIE bit in the respective IECx
31
   register.
32
   c) Write the SPIxIP bits in the respective IPCx
33
   register to set the interrupt priority.
34
   2. Write the desired settings to the SPIxCON
35
   register with MSTEN (SPIxCON1<5>) = 1.
36
   3. Clear the SPIROV bit (SPIxSTAT<6>).
37
   4. Enable SPI operation by setting the SPIEN bit
38
   (SPIxSTAT<15>).
39
   5. Write the data to be transmitted to the SPIxBUF
40
   register. Transmission (and reception) will start
41
   as soon as data is written to the SPIxBUF
42
   register.
43

44

45
   */
46
  //Set Data Direction in TrisC
47

48
  TRISCbits.TRISC7 = 0;
49
  TRISCbits.TRISC8 = 1;
50
  TRISCbits.TRISC9 = 0;
51

52
  //Initialize the SPI
53
  RPINR20bits.SDI1R = 24; //SDI at RP24  Input RC8
54

55
  RPOR11bits.RP23R = 7;//SDO  at RP23 output RC7
56
  RPOR12bits.RP25R = 8; //SCK at RP25  output RC9
57

58

59
//Init SPI 
60
  SPI1CON1bits.CKE = 1;
61
  SPI1CON1bits.MSTEN = 1; // Master
62
  SPI1CON1bits.SPRE = 0; // Divide by 8
63
  SPI1CON1bits.PPRE = 0; // Divide by 64
64
  SPI1CON2 = 0x0000;
65
  SPI1STATbits.SPIEN = 1;//enable SPI
66

67
  //warten
68
  spiDelay(10000);
69
  //74+ Takte an Karte
70
  for (i = 0; i <= 74; i++) {
71

72
    SPIsend(0xFF);
73
  }
74
  SPIsend(0x40);
75
  SPIsend(0x00);
76
  SPIsend(0x00);
77
  SPIsend(0x00);
78
  SPIsend(0x95);
79

80
  //nochmal nen paar Takte senden
81
  for (i = 0; i <= 74; i++) {
82

83
      SPIsend(0xFF);
84
    }
85
}
86

87
void spiDelay(int wait) {
88
  int i = 0;
89
  for (i = 0; i < wait; ++i) {
90

91
  }
92

93
}
Angehängte Dateien:

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