2013-05-15 04:32 AM
2013-05-15 06:45 AM
You need to make sure the clock edges are configured appropriately for your device.
You should verify the data is sent by the device correctly using a scope or analyzer. You need to ensure that RXNE is cleared for prior data, so you read the right data in sequence. The SPI SD implementation routines look like this/**
* @brief Write a byte on the SD.
* @param Data: byte to send.
* @retval None
*/
uint8_t SD_WriteByte(uint8_t Data)
{
/*!< Wait until the transmit buffer is empty */
while(SPI_I2S_GetFlagStatus(SD_SPI, SPI_I2S_FLAG_TXE) == RESET);
/*!< Send the byte */
SPI_I2S_SendData(SD_SPI, Data);
/*!< Wait to receive a byte*/
while(SPI_I2S_GetFlagStatus(SD_SPI, SPI_I2S_FLAG_RXNE) == RESET);
/*!< Return the byte read from the SPI bus */
return SPI_I2S_ReceiveData(SD_SPI);
}
/**
* @brief Read a byte from the SD.
* @param None
* @retval The received byte.
*/
uint8_t SD_ReadByte(void)
{
/*!< Wait until the transmit buffer is empty */
while(SPI_I2S_GetFlagStatus(SD_SPI, SPI_I2S_FLAG_TXE) == RESET);
/*!< Send the byte */
SPI_I2S_SendData(SD_SPI, SD_DUMMY_BYTE);
/*!< Wait until a data is received */
while(SPI_I2S_GetFlagStatus(SD_SPI, SPI_I2S_FLAG_RXNE) == RESET);
/*!< Return the byte read from the SPI bus */
return SPI_I2S_ReceiveData(SD_SPI);
}
2013-05-15 11:27 PM
Hi,
I have attached signals to read a data from the slave device. First write a index(0x74) to the slave, and then theslave ouputa data(0xff) like as the attached image. But DR of the SPI don't have 0xff, it has always 0x00. My code for this operation is like belows. I think that it is the same as clive1's.uint8_t SPI_rx_data(void)
{ uint8_t data;/* Tx a dummy data */
while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);SPI_I2S_SendData(SPI1, 0x00);
while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET) ;/* Wait for SPI1 data reception */
while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET); data = SPI_I2S_ReceiveData(SPI1); return data; } What's wrong? Please help me. Thanks ________________ Attachments : SIG.PNG : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I0xo&d=%2Fa%2F0X0000000bgJ%2FURXB7QHAcQczjPGtnwww8wdAFPbDEG.SbpJ1EWtaV_g&asPdf=false