我看了pyznq的代码,你用spi_open_device这上函数打开应该就可以实现slave,
spi spi_open_device(unsigned int device) {
int status;
u16 dev_id;
unsigned int base_address;
u32 control;
if (device < XPAR_XSPI_NUM_INSTANCES) {
dev_id = (u16) device;
}
else {
int found = 0;
for (u16 i = 0; i < XPAR_XSPI_NUM_INSTANCES; ++i) {
if (XSpi_ConfigTable[i].BaseAddress == device) {
found = 1;
dev_id = i;
break;
}
}
if (!found)
return -1;
}
status = XSpi_Initialize(&xspi[dev_id], dev_id);
if (status != XST_SUCCESS) {
return -1;
}
base_address = xspi[dev_id].BaseAddr;
// Soft reset SPI
XSpi_WriteReg(base_address, XSP_SRR_OFFSET, 0xA);
// Master mode
control = XSpi_ReadReg(base_address, XSP_CR_OFFSET);
// Master Mode
control |= XSP_CR_MASTER_MODE_MASK;
// Enable SPI
control |= XSP_CR_ENABLE_MASK;
// Slave select manually
control |= XSP_INTR_SLAVE_MODE_MASK;
// Enable Transmitter
control &= ~XSP_CR_TRANS_INHIBIT_MASK;
// Write configuration word
XSpi_WriteReg(base_address, XSP_CR_OFFSET, control);
return (spi) dev_id;
}
首先目录下的inst1_eval.do文件
注意下面的路径以及diamond的版本改为你自己的
然后启动modelsim键入以下命令进入仿真所在目录,注意替换成你对应的目录
然后键入以下命令运行仿真
可以看到仿真波形以及输出的调试信息