dsPIC33F SPI Problem

Gast #907087
Lesenswert?

Ich programmiere hier mit einem EXPLORER16 Evaluationboard einen 
dsPIC33F256GP710.

Sobald ich in den SPI1BUF schreibe, ändert sich nichts.
Im Debugger steht weiterhin 0x0000 drin, obwohl ich 0xFFFF reinschreibe.

Die anderen Register SPI1CON1 SPI1CON2 sehen normal aus.
Ich initialisiere das Modul im Master Mode, stelle die Clockphase und 
-pegel ein, die Taktfrequenz auch und versuche was zu senden, SPI1BUF 
bleibt bei 0x0000 ?

Vielleicht weiß jemand Rat ?
#907091
Lesenswert?

Thomas wrote:
> Ich programmiere hier mit einem EXPLORER16 Evaluationboard einen
> dsPIC33F256GP710.
>
> Sobald ich in den SPI1BUF schreibe, ändert sich nichts.
> Im Debugger steht weiterhin 0x0000 drin, obwohl ich 0xFFFF reinschreibe.

Das ist doch normal. SPIxBUF ist auch kein normales Register, sondern 
wird vom Sender/Empfänger gemeinsam genutzt.
Gast #907110
Lesenswert?

Hallo,

das habe ich vorher probiert, aber auch ohne Erfolg.

Hier meine Einstellungen:

[C]void init_SPI(void)      //Init SPI
{
  IFS0bits.SPI1IF = 0;     //Clear the Interrupt Flag
  IEC0bits.SPI1IE = 0;     //disable the Interrupt

  SPI1CON1bits.DISSCK = 0;  //Internal Serial Clock is Enabled.
  SPI1CON1bits.DISSDO = 0;  //SDOx pin is controlled by the module.
  SPI1CON1bits.MODE16 = 1;  //Communication is word-wide (16 bits)
  SPI1CON1bits.SMP = 0;     //Input Data is sampled at the
                                          middle of data output time.
  SPI1CON1bits.CKE = 1;


  SPI1CON1bits.CKP = 1;     //Idle state for clock is low
          //active  state is high
  SPI1CON1bits.SPRE = 7;    // Serial Clock = 4*Tcy (4MHz)
  SPI1CON1bits.PPRE = 2;

  SPI1CON1bits.MSTEN = 1;     //Master Mode Enabled
  SPI1STATbits.SPIEN = 1;     //Enable SPI Module
}[\C]
#907122
Lesenswert?

Das sollte eigentlich alles passen.

Meine Initialisierung sieht so aus:
  SPI1CON1bits.CKE=1;
  SPI1CON1bits.MSTEN=1;  // Master
  SPI1CON1bits.SPRE=0;  // Divide by 8
  SPI1CON1bits.PPRE=0;  // Divide by 64
  SPI1CON2 = 0x0000;
  SPI1STAT = 0x8000;

Und die Übertragung so:
  SPI1BUF = data;
  while (!SPI1STATbits.SPIRBF);
  data = SPI1BUF;

Dies funktioniert bei mir.
Gast #907151
Lesenswert?

Hallo,

wenn ich das gleiche im MPLAB Simulator mache, dann wird aber SPI1BUF 
beim schreiben aktualisiert !

Und noch was. Ich habe ständig den INT0 Interrupt ?
Das IF0 Bit ist gesetzt.
Der Clock (SCLK1) ist mit INT0 auf dem selben Pin.

Aber warum wird SPI1BUF nicht geschrieben ?
Ich verstehe es nicht.

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