芯片选用的是新唐20PIN的M058S
int main(void)
{
volatile uint32_t u32TxData, u32RxData, Time_count;
/* Unlock protected registers */
SYS_UnlockReg();
/* Init System, IP clock and multi-function I/O. */
SYS_Init();
/* Lock protected registers */
SYS_LockReg();
GPIO_SetMode(P1, BIT0 , GPIO_PMD_QUASI);
P10=0x00;
/* Init SPI */
SPI_Init();
Time_count=1000;
while(1)
{
if(SPI0->STATUS & SPI_STATUS_RX_EMPTY_Msk == 0)
P10=0x01;
}
}
void SYS_Init(void)
{
/*---------------------------------------------------------------------------------------------------------*/
/* Init System Clock */
/*---------------------------------------------------------------------------------------------------------*/
/* Enable internal 22.1184 MHz HIRC */
CLK_EnableXtalRC(CLK_PWRCON_IRC22M_EN_Msk);
/* Waiting for clock ready */
CLK_WaitClockReady(CLK_CLKSTATUS_IRC22M_STB_Msk);
CLK_EnablePLL(CLK_CLKSEL0_HCLK_S_HIRC, FREQ_25MHZ);//
/* Switch HCLK clock source to HIRC and set HCLK divider to 1 */
CLK_SetHCLK(CLK_CLKSEL0_HCLK_S_PLL, CLK_CLKDIV_HCLK(1));
//CLK_SetHCLK(CLK_CLKSEL0_HCLK_S_HIRC, CLK_CLKDIV_HCLK(1));
CLK_SetModuleClock(SPI0_MODULE, CLK_CLKSEL1_SPI0_S_PLL, MODULE_NoMsk);
/* Enable SPI0 clock */
CLK_EnableModuleClock(SPI0_MODULE);// S
/* Update System Core Clock */
/* User can use SystemCoreClockUpdate() to calculate PllClock, SystemCoreClock and CyclesPerUs automatically. */
SystemCoreClockUpdate();
/*---------------------------------------------------------------------------------------------------------*/
/* Init I/O Multi-function */
/*---------------------------------------------------------------------------------------------------------*/
//*******SET SWITCH;SPI_NSS************
//*******SPI_CLK;SPI_MISO;SPI_MOSI************
SYS->P0_MFP = SYS_MFP_P05_MOSI | SYS_MFP_P06_MISO | SYS_MFP_P07_SPICLK;
SYS->P1_MFP = SYS_MFP_P10_GPIO| SYS_MFP_P14_SPISS;
}
void SPI_Init(void)
{
/*---------------------------------------------------------------------------------------------------------*/
/* Init SPI */
SPI_Open(SPI0, SPI_SLAVE, SPI_MODE_3, 8, NULL);//
}
|