We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi, I'm trying to set up an SPI for an LPC1114. I don't have my slave chip just yet, so I just want to be able to read a clk of off PIO0_6, but I'm having a hard time doing this. This is my first time using MCUs in general, so I'm not too comfortable.
For some reason, I can't get any output to display, and I'm not sure what to try anymore. This is the code I have so far:
/* included libraries */ #include <stdio.h> #include "LPC11xx.h" //#include "ssp.h" /* SSP Status register */ #define SSPSR_TFE (0x1<<0) #define SSPSR_TNF (0x1<<1) #define SSPSR_RNE (0x1<<2) #define SSPSR_RFF (0x1<<3) #define SSPSR_BSY (0x1<<4) /* SSP CR1 register */ #define SSPCR1_LBM (0x1<<0) #define SSPCR1_SSE (0x1<<1) #define SSPCR1_MS (0x1<<2) #define SSPCR1_SOD (0x1<<3) /* FIFO Register size */ #define FIFOSIZE 8 /* macro definitions */ #define MY_PIO0_0 0x01 #define MY_PIO0_1 0x02 #define MY_PIO0_2 0x04 #define MY_PIO0_3 0x08 #define MY_PIO0_4 0x10 #define MY_PIO0_5 0x20 #define MY_PIO0_6 0x40 #define MY_PIO0_7 0x80 #define MY_PIO0_8 0x100 #define MY_PIO0_9 0x200 #define CS 0x00 #define SCLK 0x00 #define SDATA 0x00 void config_SSP(void) { uint8_t i, Dummy = Dummy; //enable clocks for the SSP LPC_SYSCON->PRESETCTRL |= (0x1<<0); LPC_SYSCON->SYSAHBCLKCTRL |= (1UL << 11); LPC_SYSCON->SSP0CLKDIV = 0xFF; //Orig clk is 3MHz?? LPC_IOCON->PIO0_8 &= ~0x07; //SSP I/O config LPC_IOCON->PIO0_8 |= 0x01; //SSP MISO LPC_IOCON->PIO0_9 &= ~0x07; LPC_IOCON->PIO0_9 |= 0x01; //SSP MOSI LPC_IOCON->SCK_LOC = 0x02; LPC_IOCON->PIO0_6 = 0x02; LPC_IOCON->PIO0_2 &= ~0x07; LPC_IOCON->PIO0_2 |= 0x01; //Set DSS data to 8-bit, Frame format SPI, CPOL = 0, CPHA = 0, and SCR is 7 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; //Master mode LPC_SSP0->CR1 = 0; LPC_SSP0->CR1 = SSPCR1_SSE; } void config_GPIO(void) { //enable clocks to GPIO block LPC_SYSCON->SYSAHBCLKCTRL |= (1UL << 6); //set port 0_7 to output (high current drain in LPC1114) LPC_GPIO0->DIR |= MY_PIO0_7; } void SPISend( uint8_t Radd, uint8_t Rval) { uint8_t Dummy=Dummy; Radd&=0x7F; /* Move on only if NOT busy and TX FIFO not full. */ while ( (LPC_SSP1->SR & (SSPSR_TNF|SSPSR_BSY)) != SSPSR_TNF ); LPC_SSP1->DR = Radd; //while ( (LPC_SSP1->SR & (SSPSR_BSY|SSPSR_RNE)) != SSPSR_RNE ); Dummy = LPC_SSP1->DR; while(!(LPC_SSP0->SR & SSPSR_BSY)); while ( (LPC_SSP1->SR & (SSPSR_TNF|SSPSR_BSY)) != SSPSR_TNF ); LPC_SSP1->DR = Rval; //while ( (LPC_SSP1->SR & (SSPSR_BSY|SSPSR_RNE)) != SSPSR_RNE ); while(!(LPC_SSP0->SR & SSPSR_BSY)); Dummy = LPC_SSP1->DR; return; } unsigned char SPIReceive(uint8_t Radd) { unsigned char SPIRECV; Radd|=0x80; //LPC_GPIO2->MASKED_ACCESS[(1<<SPI_CS)] = (0<<SPI_CS); // cs=0 LPC_SSP1->DR = Radd; while ( LPC_SSP1->SR & SSPSR_BSY ); LPC_SSP1->DR = 0xFF; while ( (LPC_SSP1->SR & (SSPSR_BSY|SSPSR_RNE)) != SSPSR_RNE ); SPIRECV = LPC_SSP1->DR; return SPIRECV; } /* MAIN!!!!!!! */ int main() { int i, j, tmp; //init GPIO and SSP SystemInit(); config_GPIO(); config_SSP(); while (1) { SPIReceive((uint8_t)tmp); //SPISend(j, j); //ledOn(); for (i = 0; i < 0x0007FFFF; i++) { } //ledOff(); for (i = 0; i < 0x0007FFFF; i++) { } j++; } }
I really appreciate your help :)
Hi,
i have same problem, have you found the solution?
Br,
Norbert