问答

汇集网友智慧,解决技术难题

21ic问答首页 - GD32F103VC替换ST32F103VC后,SPI读出的数全是0xff

spi ST gd32F103 TE While se

GD32F103VC替换ST32F103VC后,SPI读出的数全是0xff

win12345688992021-06-03
用ST芯片,SPI读取正常。换成GD芯片后,按照官方提供的GD和ST差异表,修改了程序,u8 SPI_FLASH_SendByte(u8 byte) 返回值全是0xff,有人遇到过这种情况吗?

u8 SPI_FLASH_SendByte(u8 byte)   //  
{

/* Loop while DR register in not emplty */
        while ((SPI1->SR & SPI_I2S_FLAG_TXE) == 0);
  /* Send byte through the SPI1 peripheral */
        SPI1->DR =byte;
  /* Wait to receive a byte */
        while ((SPI1->SR & SPI_I2S_FLAG_RXNE) == 0);
  /* Return the byte read from the SPI bus */
        return SPI1->DR;
}
回答 +关注 15
2279人浏览 1人回答问题 分享 举报
1 个回答
  • void SPI_FLASH_BufferRead(u8* pBuffer, u32 ReadAddr, u16 NumByteToRead)
    {
            //Select the FLASH: Chip Select low
            //GPIOA->BRR = FLASH_CS;
            SPI_FLASH_CS_LOW();

            /* Send "Read from Memory " instruction */
            SPI_FLASH_SendByte(READ);

            /* Send ReadAddr high nibble address byte to read from */
            SPI_FLASH_SendByte((ReadAddr & 0xFF0000) >> 16);
            /* Send ReadAddr medium nibble address byte to read from */
            SPI_FLASH_SendByte((ReadAddr& 0xFF00) >> 8);
            /* Send ReadAddr low nibble address byte to read from */
            SPI_FLASH_SendByte(ReadAddr & 0xFF);

            while(NumByteToRead--) /* while there is data to be read */
            {
            /* Read a byte from the FLASH */
                    *pBuffer = SPI_FLASH_SendByte(Dummy_Byte);
            /* Point to the next location where the byte read will be saved */
                    pBuffer++;
            }

            //Deselect the FLASH: Chip Select high
    //        GPIOA->BSRR = FLASH_CS;
            SPI_FLASH_CS_HIGH();
           
    }

    SPI_FLASH_SendByte(Dummy_Byte)读到的全是0xff

您需要登录后才可以回复 登录 | 注册