中级会员
 
- 积分
- 239
- 金钱
- 239
- 注册时间
- 2019-11-14
- 在线时间
- 59 小时
|
1金钱
STM32F401芯片,通过SPI读写外部芯片,单步操作可以正常运行,读写外部芯片都正常,当连续读的时候就会卡主,原因是SPI的SR寄存器为0;不知道怎么解决。用HAL库不存在问题,用寄存器操作就出现了。void SPIWriteDWord (UINT16 Address, UINT32 Val)
{
UINT32_VAL dwData;
UINT16_VAL wAddr;
UINT32_VAL command;
UINT8 none;
wAddr.Val = Address;
dwData.Val = Val;
//Assert CS line
CSLOW();
//Write Command
while((SPI1->SR & 2) ==0); //TXE
SPI1->DR = CMD_SERIAL_WRITE;
while((SPI1->SR & 2) ==0); //TXE
SPI1->DR = wAddr.v[1];
while((SPI1->SR & 2) ==0); //TXE
SPI1->DR = wAddr.v[0];
//Write Bytes
SPI_WRITE_DATA(dwData.v,4);
//De-Assert CS line
while((SPI1->SR & 2) == 0);
while((SPI1->SR & 80) == 0);
CSHIGH();
}
void SPI_WRITE_DATA(UINT8* data,int size)
{
int i;
for(i = 0;i < size;i++)
{
while((SPI1->SR & 1 << 1) ==0); //TXE
SPI1->DR = data;
}
}

|
|