芯片是NUC123 用到了SPI0和SPI2,打开SPI2之前,SPI0是正常工作的,打开SPI2后,spi0不能读写,SPI2还没有连接设备,还不知道SPI2是否工作正常int ddi_spi_Init(void){
/* Select HCLK as the clock source of SPI0 */
CLK_SetModuleClock(SPI2_MODULE, CLK_CLKSEL1_SPI2_S_HCLK, MODULE_NoMsk);
CLK_SetModuleClock(SPI0_MODULE, CLK_CLKSEL1_SPI0_S_PLL, MODULE_NoMsk);
/* Enable SPI0 peripheral clock */
CLK_EnableModuleClock(SPI2_MODULE);
CLK_EnableModuleClock(SPI0_MODULE);
/* Configure SPI0 as a slave, clock idle low, 32-bit transaction, drive output on falling clock edge and latch input on rising edge. */
/* Configure SPI0 as a low level active device. SPI peripheral clock rate is equal to system clock rate. */
SPI_Open(SPI2, SPI_SLAVE, SPI_MODE_3, 32, NULL);
SPI_Open(SPI0, SPI_MASTER, SPI_MODE_3, 8, NULL);
//SPI2->SSR = 0;
/* Enable the automatic hardware slave select function. Select the SPI0_SS0 pin and configure as low-active. */
SPI_EnableAutoSS(SPI2, SPI_SS0, SPI_SS_ACTIVE_LOW);
//SPI2->CNTRL2 |= SPI_CNTRL2_SS_INT_OPT_Msk;
//SPI2->CNTRL |= SPI_CNTRL_IE_Msk;
SPI_EnableInt(SPI2, SPI_FIFO_RXOV_INT_MASK|SPI_FIFO_RX_INT_MASK);
/* Enable FIFO mode, set TX FIFO threshold, enable TX FIFO threshold interrupt and RX FIFO time-out interrupt */
SPI_EnableFIFO(SPI2, 0, 7);
/*disableAutoss,SSO active low*/
SPI0->SSR &= ~1<<3;
SPI0->SSR &= ~1<<2;
SPI0->SSR |= 1<<4;
SPI_SET_MSB_FIRST(SPI0);
PF3=1;
SYS->GPF_MFP = ~(SYS_GPF_MFP_PF3_Msk);
GPIO_SetMode(PF, BIT3, GPIO_PMD_OUTPUT);
PC4 = 1;
PC5 = 0;
SYS->GPC_MFP &= ~(SYS_GPC_MFP_PC4_Msk| SYS_GPC_MFP_PC5_Msk);
SYS->GPC_MFP |= (SYS_GPC_MFP_PC4_GPIO| SYS_GPC_MFP_PC5_GPIO);
GPIO_SetMode(PC, BIT4|BIT5, GPIO_PMD_QUASI);
/* Setup SPI0 multi-function pins */
SYS->GPD_MFP = SYS_GPD_MFP_PD0_SPI2_SS0 | SYS_GPD_MFP_PD1_SPI2_CLK | SYS_GPD_MFP_PD2_SPI2_MISO0 | SYS_GPD_MFP_PD3_SPI2_MOSI0;
SYS->ALT_MFP1 = SYS_ALT_MFP1_PD0_SPI2_SS0 | SYS_ALT_MFP1_PD1_SPI2_CLK | SYS_ALT_MFP1_PD2_SPI2_MISO0 | SYS_ALT_MFP1_PD3_SPI2_MOSI0;
SYS->GPC_MFP = SYS_GPC_MFP_PC0_SPI0_SS0 | SYS_GPC_MFP_PC1_SPI0_CLK | SYS_GPC_MFP_PC2_SPI0_MISO0 | SYS_GPC_MFP_PC3_SPI0_MOSI0;
SYS->ALT_MFP = SYS_ALT_MFP_PC0_SPI0_SS0 | SYS_ALT_MFP_PC1_SPI0_CLK | SYS_ALT_MFP_PC2_SPI0_MISO0 | SYS_ALT_MFP_PC3_SPI0_MOSI0;
g_spiInBuf.fi = 0;
g_spiInBuf.fo = 0;
g_spiOutBuf.fi = 0;
g_spiOutBuf.fo = 0;
spiMasterAcked = 1;
spiRunning = 0;
SPI_Close(SPI2);
return 0;
}
是哪里出问题了 |