Forum: Mikrocontroller und Digitale Elektronik MPC5554 externer EEPROM über SPI


von Flo H. (flohaase)


Lesenswert?

Hallo zusammen,

ich habe einen MPC5554 und will über SPI einen ganz einfach 
EEPROM-Speicherbaustein (Mircochip 25LC040) beschrieben und wieder 
lesen.

Für den MPC5554 gibt es ein C-Code-Beispiel, um Daten zwischen zwei 
SPI-Modulen auf dem MPC554 zu übertragen. Das Kapitel in der Doku von 
Freescale heißt "MPC555x (DSPI_C master, DSPI_D slave)". Mein Slave soll 
nun der 25LC040 von Microchip werden.

Hier ist ein Aufbaue der C-Datei aus der Doku:
1
int main(void) {
2
    initSysclk();
3
    initDSPI_C();
4
    initDSPI_D();
5
    DPSI_D.PURSHR.R = 0x00001234;
6
    DSPI_C.PUSHHR.R = 0x00005678;
7
    ReadDataDSPI_D();
8
    ReadDataDSPI_C();
9
    while(1) {};
10
}

D = Master, C = Slave.

initSysclk: Bleibt unterverändert, weil ich so dem MPC5554 sage, wie 
schnell er die Daten rausschicken soll.

initDSPI_C(): Bleibt auch unverändert, weil ihm dem MPC554 sage, dass 
dieses SPI-Module derMaster ist.

initDSPI_D(): Kann ich diese Funktion weglassen, weil ich auf dem 
MPC5554 ja kein zweites SPI-Modul benutze und der externe EEPROM muss 
nicht konfiguiert werden. Der bekommt die Clock, Versorgungsspannung, 
GND und ein Chip Selet Signal, das er weiß, wann er dran ist. Sobald 
alle Signale anliegen, beginnt er mit dem Senden der Daten.

DSPI_D.PUSHR.R: Fällt weg, weil der Slave keine Antwort senden soll.

DPSI_C.PRUSH.R: Bleibt, weil das von Master an den Slave geht.

ReadDataDSPI_D: Fällt weg, weil der Slave nichts vom Master lesen soll.

ReadDataDPSI_C: Bleibt, weil hier der Master lesen soll, was im Slave 
steht.

Meine Frage ist jetzt, woher weiß ich, in welchem Format der Slave die 
Daten habem will und in welchem Format der Master diese dann wieder 
lesen kann?

Danke, Gruß Flo

Hier ist noch der ganze Code:
1
/* main.c: performs a single transfer from DSPI_C to DSPI_D on MPC555x*/
2
/* Rev 1.0 Sept 14 2004 S.Mihalik */
3
/* Rev 2.0 Jan 3 2007 S. Mihalik - Modified to use two SPIs */
4
/* Rev 2.1 July 20 2007 SM - Modified for MPC551x, changed sysclk (50 MHz) */
5
/* Rev 2.2 Aug 13 2007 SM - Modified for sysclk of 64 MHz & lenghened CSSCK, ASC*/
6
/* Rev 2.3 Jun 04 2008 SM - initSysclk changed for MPC5633M support */
7
/* Rev 2.4 Aug 15 2008 SM - removed lines for MPC551x, MPC563x */
8
/* Rev 2.5 Aug 18 2008 D McKenna- Kept DSPI_MCR[HALT] set during initialization*/
9
/* Copyright Freescale Semiconductor, Inc. 2007 All rights reserved. */
10
/* Notes: */
11
/* 1. MMU not initialized; must be done by debug scripts or BAM */
12
/* 2. SRAM not initialized; must be done by debug scripts or in a crt0 type file */
13
14
#include "mpc5554.h" /* Use proper include file like mpc5510.h or mpc5554.h */
15
16
vuint32_t i = 0; /* Dummy idle counter */
17
uint16_t RecDataMaster = 0; /* Data recieved on master SPI */
18
uint16_t RecDataSlave = 0; /* Data received on slave SPI */
19
20
void initSysclk (void) {
21
  FMPLL.SYNCR.R = 0x16080000; /* 8 MHz xtal: 0x16080000; 40MHz: 0x46100000 */
22
  while (FMPLL.SYNSR.B.LOCK != 1) {}; /* Wait for FMPLL to LOCK */
23
  FMPLL.SYNCR.R = 0x16000000; /* 8 MHz xtal: 0x16000000; 40MHz: 0x46080000 */
24
}
25
26
void initDSPI_C(void) {
27
  DSPI_C.MCR.R = 0x80010001; /* Configure DSPI_C as master */
28
  DSPI_C.CTAR[0].R = 0x780A7727; /* Configure CTAR0 */
29
  DSPI_C.MCR.B.HALT = 0x0; /* Exit HALT mode: go from STOPPED to RUNNING state*/
30
  SIU.PCR[107].R = 0x0A00; /* MPC555x: Config pad as DSPI_C SOUT output */
31
  SIU.PCR[108].R = 0x0900; /* MPC555x: Config pad as DSPI_C SIN input */
32
  SIU.PCR[109].R = 0x0A00; /* MPC555x: Config pad as DSPI_C SCK output */
33
  SIU.PCR[110].R = 0x0A00; /* MPC555x: Config pad as DSPI_C PCS0 output */
34
}
35
36
void initDSPI_D(void) {
37
  DSPI_D.MCR.R = 0x00010001; /* Configure DSPI_D as slave */
38
  DSPI_D.CTAR[0].R = 0x780A7727; /* Configure CTAR0 */
39
  DSPI_D.MCR.B.HALT = 0x0; /* Exit HALT mode: go from STOPPED to RUNNING state*/
40
  SIU.PCR[98].R = 0x0900; /* MPC555x: Config pad as DSPI_D SCK input */
41
  SIU.PCR[99].R = 0x0900; /* MPC555x: Config pad as DSPI_D SIN input */
42
  SIU.PCR[100].R = 0x0A00; /* MPC555x: Config pad as DSPI_D SOUT output*/
43
  SIU.PCR[106].R = 0x0900; /* MPC555x: Config pad as DSPI_D PCS0/SS input */
44
}
45
46
void ReadDataDSPI_D(void) {
47
  while (DSPI_D.SR.B.RFDF != 1){} /* Wait for Receive FIFO Drain Flag = 1 */
48
  RecDataSlave = DSPI_D.POPR.R; /* Read data received by slave SPI */
49
  DSPI_D.SR.R = 0x80020000; /* Clear TCF, RDRF flags by writing 1 to them */
50
}
51
52
void ReadDataDSPI_C(void) {
53
  while (DSPI_C.SR.B.RFDF != 1){} /* Wait for Receive FIFO Drain Flag = 1 */
54
  RecDataMaster = DSPI_C.POPR.R; /* Read data received by master SPI */
55
  DSPI_C.SR.R = 0x90020000; /* Clear TCF, RDRF, EOQ flags by writing 1 */
56
}
57
58
int main(void) {
59
  SIU.DISR.R = 0x0000C0FC; /* MPC555x only: Connect DSPI_C, DSPI_D internally */
60
  initSysclk(); /* Set sysclk = 64MHz running from PLL */
61
  initDSPI_C(); /* Initialize DSPI_C as master SPI and init CTAR0 */
62
  initDSPI_D(); /* Initialize DSPI_D as Slave SPI and init CTAR0 */
63
  DSPI_D.PUSHR.R = 0x00001234; /* Initialize slave DSPI_D's response to master */
64
  DSPI_C.PUSHR.R = 0x08015678; /* Transmit data from master to slave SPI with EOQ */
65
  ReadDataDSPI_D(); /* Read data on slave DSPI */
66
  ReadDataDSPI_C(); /* Read data on master DSPI */
67
  while (1) {i++; } /* Wait forever */
68
}

: Bearbeitet durch User
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.