下了官方的驱动,但是spi初始化以及读取自己写的,出现了问题,关于spi不太懂他的步骤看一下我哪里写错了?
unsigned char SPI_Read7193(unsigned char slaveDeviceId,
unsigned char* data,
unsigned char bytesNumber)
{
unsigned char byte = 0;
if(slaveDeviceId == AD7193_SLAVE_ID)PMOD1_CS_LOW;
for(byte = 0; byte < bytesNumber; byte++)
{
while(SPI_GetFlagStatus(SPI_FLAG_RXNE) == RESET);
*data++ = SPI_ReceiveData();
}
if(slaveDeviceId == AD7193_SLAVE_ID)PMOD1_CS_HIGH;
return bytesNumber;
}
unsigned char SPI_Write7193(unsigned char slaveDeviceId,
unsigned char* data,
unsigned char bytesNumber)
{
unsigned char byte = 0;
if(slaveDeviceId == AD7193_SLAVE_ID)PMOD1_CS_LOW;
for(byte = 0; byte < bytesNumber; byte++)
{
while(SPI_GetFlagStatus(SPI_FLAG_TXE) == RESET);
SPI_SendData(*data++);
}
if(slaveDeviceId == AD7193_SLAVE_ID)PMOD1_CS_HIGH;
return bytesNumber;
}
这个是官方给的别的单片机的例子,我不太了解这个单片机和寄存器,你们可以参考一下
unsigned char SPI_Read(unsigned char slaveDeviceId,
unsigned char* data,
unsigned char bytesNumber)
{
unsigned char byte = 0;
if(slaveDeviceId == 1)
{
PMOD1_CS_LOW;
}
if(slaveDeviceId == 2)
{
ST7579_CS_LOW;
}
for(byte = 0; byte < bytesNumber; byte++)
{
SIO10 = data[byte];
__no_operation();
__no_operation();
while(SSR02 & 0x0040);
data[byte] = SIO10;
}
if(slaveDeviceId == 1)
{
PMOD1_CS_HIGH;
}
if(slaveDeviceId == 2)
{
ST7579_CS_HIGH;
}
return bytesNumber;
}
/***************************************************************************//**
* @brief Writes data to SPI.
*
* @param slaveDeviceId - The ID of the selected slave device.
* @param data - Data represents the write buffer.
* @param bytesNumber - Number of bytes to write.
*
* @return Number of written bytes.
*******************************************************************************/
unsigned char SPI_Write(unsigned char slaveDeviceId,
unsigned char* data,
unsigned char bytesNumber)
{
unsigned char byte = 0;
unsigned char read = 0;
if(slaveDeviceId == 1)
{
PMOD1_CS_LOW;
}
if(slaveDeviceId == 2)
{
ST7579_CS_LOW; // Assert CS low
}
for(byte = 0; byte < bytesNumber; byte++)
{
SIO10 = data[byte];
__no_operation();
__no_operation();
while(SSR02 & 0x0040);
read = SIO10;
}
if(slaveDeviceId == 1)
{
PMOD1_CS_HIGH;
}
if(slaveDeviceId == 2)
{
ST7579_CS_HIGH; // Assert CS high
}
return bytesNumber;
}
|