我采用SPI对外挂的flash(w25q256)读取ID,寄存器状态,但返回的都是0Xff,查找问题许久,但还是没有解决,我尝试把自动硬件从选关闭了、速率降低了,但还是不行因此想向各位前辈赐教,在此非常感谢各位前辈的斧正,关键代码如下:
void SYS_Init(void)
{
SYS_UnlockReg();
CLK_EnableXtalRC(CLK_PWRCTL_HIRCEN_Msk);
CLK_WaitClockReady(CLK_STATUS_HIRCSTB_Msk);
CLK_SetHCLK(CLK_CLKSEL0_HCLKSEL_HIRC, CLK_CLKDIV0_HCLK(1));
CLK->PCLKDIV = (CLK_PCLKDIV_APB0DIV_DIV2 | CLK_PCLKDIV_APB1DIV_DIV2);
/******硬件SPI控制器******/
CLK_SetModuleClock(SPI0_MODULE, CLK_CLKSEL2_SPI0SEL_PCLK1, MODULE_NoMsk);
CLK_EnableModuleClock(SPI0_MODULE);
SystemCoreClockUpdate();
//set PB mul
ti-function pins for PWM0 channel 0~5
SYS->GPA_MFPL = (SYS->GPA_MFPL ~(SYS_GPA_MFPL_PA2MFP_Msk |SYS_GPA_MFPL_PA1MFP_Msk |SYS_GPA_MFPL_PA0MFP_Msk)) |
(SYS_GPA_MFPL_PA2MFP_SPI0_CLK |SYS_GPA_MFPL_PA1MFP_SPI0_MISO |SYS_GPA_MFPL_PA0MFP_SPI0_MOSI);
SYS_LockReg();
}
void SPI_Init(void)
{
SPI_Open(SPI0, SPI_MASTER, SPI_MODE_0, 8, 4000000);
SPI_DisableAutoSS(SPI0);
}
uint8_t SpiReadWriteData(uint8_t SendData)
{
SPI_WRITE_TX(SPI0, SendData);
/***Check SPI0 busy status***/
while (SPI_IS_BUSY(SPI0));
/***Read received data***/
return SPI_READ_RX(SPI0);
}
void Read_Device_ID(void)
{
uint16_t ID;
SPI_CS_0();
SpiReadWriteData(Device_ID);
SpiReadWriteDatae(0x00);
SpiReadWriteData(0x00);
SpiReadWriteData(0x00);
ID = SpiReadWriteData(0XFF);
ID =( ID<<8)|SpiReadWriteData(0XFF);
SPI_CS_1();
printf("Device_ID:%x\r\n",ID);
}
在此,再次感谢各位前辈的赐教。
0