15 volatile uint32_t interruptRxStat = 0;
16 volatile uint32_t interruptOverRunStat = 0;
17 volatile uint32_t interruptRxTimeoutStat = 0;
33 void SSP_IRQHandler(
void)
37 regValue = LPC_SSP->MIS;
38 if ( regValue & SSPMIS_RORMIS )
40 interruptOverRunStat++;
41 LPC_SSP->ICR = SSPICR_RORIC;
43 if ( regValue & SSPMIS_RTMIS )
45 interruptRxTimeoutStat++;
46 LPC_SSP->ICR = SSPICR_RTIC;
53 if ( regValue & SSPMIS_RXMIS )
71 uint8_t i, Dummy=Dummy;
73 LPC_SYSCON->PRESETCTRL |= (0x1<<0);
74 LPC_SYSCON->SYSAHBCLKCTRL |= (1<<11);
75 LPC_SYSCON->SSPCLKDIV = 0x0f;
76 LPC_IOCON->PIO0_8 &= ~0x07;
77 LPC_IOCON->PIO0_8 |= 0x01;
78 LPC_IOCON->PIO0_9 &= ~0x07;
79 LPC_IOCON->PIO0_9 |= 0x01;
80 #ifdef __JTAG_DISABLED
81 LPC_IOCON->SCKLOC = 0x00;
82 LPC_IOCON->JTAG_TCK_PIO0_10 &= ~0x07;
83 LPC_IOCON->JTAG_TCK_PIO0_10 |= 0x02;
89 LPC_IOCON->SCKLOC = 0x01;
90 LPC_IOCON->PIO2_11 = 0x01;
93 LPC_IOCON->SCKLOC = 0x02;
94 LPC_IOCON->PIO0_6 = 0x02;
99 LPC_IOCON->PIO0_2 &= ~0x07;
100 LPC_IOCON->PIO0_2 |= 0x01;
102 LPC_IOCON->PIO0_2 &= ~0x07;
104 LPC_GPIO0->DIR |= (0x1<<2);
105 LPC_GPIO0->DATA |= (0x1<<2);
110 LPC_SSP->CR0 = 0x0707;
120 for ( i = 0; i < FIFOSIZE; i++ )
126 NVIC_EnableIRQ(SSP_IRQn);
130 LPC_SSP->CR1 = SSPCR1_LBM | SSPCR1_SSE;
134 if ( LPC_SSP->CR1 & SSPCR1_SSE )
137 LPC_SSP->CR1 &= ~SSPCR1_SSE;
139 LPC_SSP->CR1 = SSPCR1_MS;
140 LPC_SSP->CR1 |= SSPCR1_SSE;
143 LPC_SSP->CR1 = SSPCR1_SSE;
148 LPC_SSP->IMSC = SSPIMSC_RORIM | SSPIMSC_RTIM;
163 void SSPSend( uint8_t *buf, uint32_t Length )
166 uint8_t Dummy = Dummy;
168 for ( i = 0; i < Length; i++ )
171 while ( (LPC_SSP->SR & (SSPSR_TNF|SSPSR_BSY)) != SSPSR_TNF );
175 while ( (LPC_SSP->SR & (SSPSR_BSY|SSPSR_RNE)) != SSPSR_RNE );
182 while ( LPC_SSP->SR & SSPSR_BSY );
197 void SSPReceive( uint8_t *buf, uint32_t Length )
201 for ( i = 0; i < Length; i++ )
210 while ( !(LPC_SSP->SR & SSPSR_RNE) );
214 while ( (LPC_SSP->SR & (SSPSR_BSY|SSPSR_RNE)) != SSPSR_RNE );
217 while ( !(LPC_SSP->SR & SSPSR_RNE) );
230 uint8_t send_data[2];
231 uint8_t receive_data[10];
237 LPC_GPIO0->DATA &= ~(0x1<<2);
239 SSPSend( &send_data[0], 1 );
240 SSPReceive( &receive_data[0], 2 );
242 LPC_GPIO0->DATA |= (0x1<<2);
244 myPrintfUSB(
"whoAmI %d %d %d \n",receive_data[0],receive_data[1],receive_data[2] );