这个是我的1343的spi 初始化,我是跑起来的,不知道对你有用没有
void SSPInit( void )
{
uint8_t i, Dummy=Dummy;
LPC_SYSCON->PRESETCTRL |= (0x1<<0);
LPC_SYSCON->SYSAHBCLKCTRL |= (1<<11);
LPC_SYSCON->SSPCLKDIV = 0x06; /* Divided by 6 =12M */
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 */
//P0-10设置为SCK功能
LPC_IOCON->SCKLOC = 0x00;
LPC_IOCON->JTAG_TCK_PIO0_10 = 0x02;
//USE_CS
LPC_IOCON->PIO0_2 &= ~0x07; /* SSP SSEL is a GPIO pin */
GPIOSetDir( PORT0, 2, 1 );
GPIOSetValue( PORT0, 2, 1 );
//serial baud =200kbp/s
// (72M/6)/[(cpdvsr==2)*((scr==29)+1)] =200k
/* Set DSS data to 8-bit, Frame format SPI, CPOL = 0, CPHA = 0, and SCR is 29 */
LPC_SSP->CR0 = 0x1d07;
/* SSPCPSR clock prescale register, master mode, minimum divisor is 0x02 */
LPC_SSP->CPSR = 0x2;
for ( i = 0; i < FIFOSIZE; i++ )
{
Dummy = LPC_SSP->DR; /* clear the RxFIFO */
}
// 采用查询方式,中断 禁止
/* Enable the SSP Interrupt */
//NVIC_EnableIRQ(SSP_IRQn);
/* Device select as master, SSP Enabled */
//#if LOOPBACK_MODE
#if 0
LPC_SSP->CR1 = SSPCR1_LBM | SSPCR1_SSE;
#else
//#if SSP_SLAVE
#if 0
/* Slave mode */
if ( LPC_SSP->CR1 & SSPCR1_SSE )
{
/* The slave bit can't be set until SSE bit is zero. */
LPC_SSP->CR1 &= ~SSPCR1_SSE;
}
LPC_SSP->CR1 = SSPCR1_MS; /* Enable slave bit first */
LPC_SSP->CR1 |= SSPCR1_SSE; /* Enable SSP */
#else
/* Master mode */
LPC_SSP->CR1 = SSPCR1_SSE;
#endif
#endif
/* Set SSPINMS registers to enable interrupts */
/* enable all error related interrupts */
//LPC_SSP->IMSC = SSPIMSC_RORIM | SSPIMSC_RTIM;
return;
} |