Forum: Mikrocontroller und Digitale Elektronik LPC1769 SSP0 (SPI) läuft nicht


von tronik (Gast)


Lesenswert?

Hallo,

ich bin schon seit einiger Zeit dabei den SPI bus auf einem LpcXpresso 
Board ans laufen zu bringen.
Ich möchte später einmal mit dem SPI Bus ein Display ansteuern.
Das Xpresso Board ist mit einem LPC1769 bestückt.
Für Testzwecke habe ich erst einmal ein Soundkarten Oszilloskop an SCK 
gehängt, aber ich schaffe es nicht den SPI zu initialisieren. Ich habe 
schon alle register gesetzt verändert, ausprobiert, doch die Soundkarten 
Oszilloskop Software zeigt mir kein Signal an.

Hier ist der Code:
1
#ifdef __USE_CMSIS
2
#include "LPC17xx.h"
3
#endif
4
5
#include <cr_section_macros.h>
6
#include <NXP/crp.h>
7
8
__CRP const unsigned int CRP_WORD = CRP_NO_CRP ;
9
10
int main(void)
11
{
12
    LPC_SC->PCONP |= (1<<21); //PCSSP0 = 1 Enable AHB clock
13
    LPC_SC->PCLKSEL1 &= ~(1<<10); //PCLK_peripheral = CCLK/4
14
    LPC_SC->PCLKSEL1 &= ~(1<<11);
15
    LPC_SSP0->CPSR = 4; //Clock Prescale
16
17
    LPC_PINCON->PINSEL0 &= ~(1 << 30);          // P0.15: SCK0
18
    LPC_PINCON->PINSEL0 |=  (1 << 31);
19
    LPC_PINCON->PINSEL1 &= ~((1<<2) | (1<<4));    // P0.17: MISO0, P0.18: MOSI0
20
    LPC_PINCON->PINSEL1 |=  (1<<3) | (1<<5);
21
22
    LPC_SSP0->CR0 &= ~(1<<0); //8 Bit
23
    LPC_SSP0->CR0 |= (1<<1) | (1<<2) | (1<<3); //8 Bit
24
    LPC_SSP0->CR0 &= ~(1<<6); //CPOL = 0 SCK high zwischen frame
25
26
    LPC_SSP0->CR1 &= ~(1<<2); //SSP Master
27
    LPC_SSP0->CR1 |= (1<<1); //SSP Enable
28
    
29
    while(1)
30
    {
31
        LPC_SSP0->DR = 0x88; //Test senden
32
    }
33
    return 0 ;
34
}
(CodeRed Develop)

Übersehe ich vielleicht ein Register oder setze ich sie falsch.
Mit dem Debugger habe ich die Register ausgelesen, scheint eigentlich 
alles in Ordnung zu sein.

LG tronik

von Gerhard G. (g_g)


Lesenswert?

Hallo,

teste mal meinen Code:

void SSP0Init( void )
{
  uint8_t i, Dummy=Dummy;

  /* Enable AHB clock to the SSP0. */
  LPC_SC->PCONP |= (0x1<<21);

  /* Further divider is needed on SSP0 clock. Using default divided by 4 
*/
  LPC_SC->PCLKSEL1 &= ~(0x3<<10);

  /* P0.15~0.18 as SSP0 */
  LPC_PINCON->PINSEL0 &= ~(0x3UL<<30);
  LPC_PINCON->PINSEL0 |= (0x2UL<<30);
  LPC_PINCON->PINSEL1 &= ~((0x3<<0)|(0x3<<2)|(0x3<<4));
  LPC_PINCON->PINSEL1 |= ((0x2<<0)|(0x2<<2)|(0x2<<4));


 // LPC_PINCON->PINSEL1 &= ~(0x3<<0);
 // LPC_GPIO0->FIODIR |= (0x1<<16);    /* P0.16 defined as GPIO and 
Outputs */


  /* Set DSS data to 8-bit, Frame format SPI, CPOL = 0, CPHA = 0, and 
SCR is 15 */
  LPC_SSP0->CR0 = 0x0707;

  /* SSPCPSR clock prescale register, master mode, minimum divisor is 
0x02 */
  LPC_SSP0->CPSR = 0x2;

  for ( i = 0; i < FIFOSIZE; i++ )
  {
  Dummy = LPC_SSP0->DR;    /* clear the RxFIFO */
  }


  /* Master mode */
  LPC_SSP0->CR1 = SSPCR1_SSE;

    return;
}

void SSPSend( uint8_t data )
{

     LPC_SSP0->DR = data;

    /* Wait until the Busy bit is cleared. */
    while ( LPC_SSP0->SR & SSPSR_BSY );

}


Gruß G.G.

von tronik (Gast)


Lesenswert?

Danke G.G. ,

Den Code hast du wahrscheinlich aus einem Beispiel entnommen,
welches ich auch schon ausprobiert hatte.
Trtozdem super vielen Dank ;)

Ich glaube ich habe jetzt den Fehler gefunden:
Das Ozi schaft nur ein Zeitintervall von 5ms in der ein Spanungswechel 
gemessen werden kann. Und der Fehler liegt wahrscheinlich an der 
Falschen Initialisierung des Displays obwohl ich diese aus einem 
Beispiel entnommen hatte. Aber naja, damit ist jetzt wohl der Thread 
hier erst einmal abgeschlossen.

MfG Tronik

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.