|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
大家好,
我现在用的是XC7A35T,用microblaze软核做8位spi flash驱动 spi clk居然是7位的!
代码:
while(1)
{
// Control = XSpi_ReadReg(XPAR_FLASH_SPI_BASEADDR, XSP_SR_OFFSET) ;
spiWriteEna(XPAR_FLASH_SPI_BASEADDR);//spiWrite(XPAR_FLASH_SPI_BASEADDR,0,WriteBuffer,BUFFER_SIZE);
for(i=0;i<100000;i++)
{;}
}
void spiWriteEna(u32 BaseAddress)
{
u8 op_code = WREN, data;
SPI_FLASH_CS_LOW();
// 发送写使能命令
spi_transfer(BaseAddress, &op_code, &data, 1);
SPI_FLASH_CS_HIGH();
}
void spi_transfer (Xuint32 BaseAddress, Xuint8 *send, Xuint8 *recv, Xuint8 num_bytes)
{
Xuint8 NumBytesRcvd = 0;
Xuint8 NumBytesSent = 0;
// 把发送的数据写入到SPI控制器的发送FIFO中
while(num_bytes--)
{
XSpi_WriteReg(BaseAddress, XSP_DTR_OFFSET, *send++);
NumBytesSent++;
}
// 设置SPICR寄存器,使能Master Transactions
XSpi_Clear_Inhibit(BaseAddress);
// 等待发送FIFO为空
while (!(XSpi_ReadReg(BaseAddress, XSP_SR_OFFSET) & XSP_SR_TX_EMPTY_MASK));
// 从接收FIFO中接收数据
while ((XSpi_ReadReg(BaseAddress, XSP_SR_OFFSET) & XSP_SR_RX_EMPTY_MASK) == 0)
{
*recv++ = XSpi_ReadReg(BaseAddress,XSP_DRR_OFFSET);
NumBytesRcvd++;
}
// 设置SPICR寄存器,Master Transactions 不使能
XSpi_Set_Inhibit(BaseAddress);
} |
|