以下是我的AD7193 spi主机模式驱动(stm8s)
一直停在RDY口,就是MISO复用,一直不拉低,死循环
我怀疑是spi读写没写好,还有就是spi硬件调试的时候,gpio口需要设置嘛?
求看一看,找出原因
#define MISO_STATE GPIO_ReadInputPin(GPIOC, GPIO_PIN_7)
#define PMOD1_CS_LOW GPIO_WriteLow(GPIOE, GPIO_PIN_5)
#define PMOD1_CS_HIGH GPIO_WriteHigh(GPIOE, GPIO_PIN_5)
unsigned char SPI_Init7193(unsigned char lsbFirst, unsigned long clockFreq, unsigned char clockPol, unsigned char clockEdg)
{
SPI_DeInit();
SPI_Init(SPI_FIRSTBIT_MSB, SPI_BAUDRATEPRESCALER_16, SPI_MODE_MASTER, SPI_CLOCKPOLARITY_HIGH, SPI_CLOCKPHASE_1EDGE, SPI_DATADIRECTION_2LINES_FULLDUPLEX, SPI_NSS_SOFT, 0x07);
SPI_Cmd(ENABLE);
GPIO_Init(GPIOE, GPIO_PIN_5, GPIO_MODE_OUT_PP_LOW_FAST); //SPI CS/NSS
GPIO_WriteLow(GPIOE, GPIO_PIN_5);
return 1;
}
unsigned char SPI_Write7193(unsigned char slaveDeviceId, unsigned char* data, unsigned char n)
{
unsigned char byte = 0;
unsigned char read = 0;
for(byte = 0;byte < n;byte++)
{
while(SPI_SR_TXE==0);
SPI_SendData(data[byte]);
while(SPI_SR_RXNE==0);
read = SPI_ReceiveData();
}
return n;
}
unsigned char SPI_Read7193(unsigned char slaveDeviceId, unsigned char* data, unsigned char n)
{
unsigned char byte = 0;
for(byte = 0;byte < n;byte++)
{
while(SPI_SR_TXE==0);
SPI_SendData(data[byte]);
while(SPI_SR_RXNE==0);
data[byte] = SPI_ReceiveData();
}
return n;
}
|