Datum:
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:
#ifdef __USE_CMSIS #include "LPC17xx.h" #endif #include <cr_section_macros.h> #include <NXP/crp.h> __CRP const unsigned int CRP_WORD = CRP_NO_CRP ; int main(void) { LPC_SC->PCONP |= (1<<21); //PCSSP0 = 1 Enable AHB clock LPC_SC->PCLKSEL1 &= ~(1<<10); //PCLK_peripheral = CCLK/4 LPC_SC->PCLKSEL1 &= ~(1<<11); LPC_SSP0->CPSR = 4; //Clock Prescale LPC_PINCON->PINSEL0 &= ~(1 << 30); // P0.15: SCK0 LPC_PINCON->PINSEL0 |= (1 << 31); LPC_PINCON->PINSEL1 &= ~((1<<2) | (1<<4)); // P0.17: MISO0, P0.18: MOSI0 LPC_PINCON->PINSEL1 |= (1<<3) | (1<<5); LPC_SSP0->CR0 &= ~(1<<0); //8 Bit LPC_SSP0->CR0 |= (1<<1) | (1<<2) | (1<<3); //8 Bit LPC_SSP0->CR0 &= ~(1<<6); //CPOL = 0 SCK high zwischen frame LPC_SSP0->CR1 &= ~(1<<2); //SSP Master LPC_SSP0->CR1 |= (1<<1); //SSP Enable while(1) { LPC_SSP0->DR = 0x88; //Test senden } return 0 ; } |
(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
Datum:
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.
Datum:
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