AnsweredAssumed Answered

STM32 SPI port

Question asked by wooller.david on Feb 6, 2012
Latest reply on Feb 8, 2012 by Clive One
I am trying to interface with an SPI port device which requires a 24bit transfer, I have successfully managed to achieve this using the example code and standard peripheral library but I am seeing gaps between byte transfers. It appears that these are down to the software waiting for a receive byte prior to sending the next byte in the tx data packet. the code used is as follows:
  * @brief  write data width bytes from SPI interface.
  * @param  passed address & data  
  * @retval None
void Cspi::write(uint8_t address, uint16_t data )
uint8_t * txdata = (uint8_t*)&data;
uint16_t dummy = 0;
   /* Transfer procedure */

    if (Spi_port == SPI1) {
        GPIO_WriteBit( Spi_gpio,SPI1_PIN_NSS,Bit_RESET );      // drive the CS line low
        GPIO_WriteBit( Spi_gpio,SPI2_PIN_NSS,Bit_RESET );      // drive the CS line low
    /* Wait for SPIy Tx buffer empty */
    while (SPI_I2S_GetFlagStatus(Spi_port, SPI_I2S_FLAG_TXE) == RESET);
    /* Send SPI address */
    SPI_I2S_SendData(Spi_port, address);
    while (SPI_I2S_GetFlagStatus(Spi_port, SPI_I2S_FLAG_RXNE) == RESET);
    dummy = SPI_I2S_ReceiveData(Spi_port);      /* Read SPI received data */

    for (int8_t x = 1; x >= 0 ; x-- ) {
        while (SPI_I2S_GetFlagStatus(Spi_port, SPI_I2S_FLAG_TXE) == RESET);
        /* Send SPI data high */
        SPI_I2S_SendData(Spi_port, txdata[x]);
        while (SPI_I2S_GetFlagStatus(Spi_port, SPI_I2S_FLAG_RXNE) == RESET);
        dummy = SPI_I2S_ReceiveData(Spi_port);  /* Read SPI received data */
    if (Spi_port == SPI1) {
        GPIO_WriteBit( Spi_gpio, SPI1_PIN_NSS,Bit_SET );      // drive the CS line high
        GPIO_WriteBit( Spi_gpio, SPI2_PIN_NSS,Bit_SET );      // drive the CS line high

when trying to use the BSY flag to determine if the last byte has been sent instead of the receive flag, the CS line goes high before the last byte has been sent. The state of the BSY flag is a bit vague in the data sheet but it appears to be cleared after the byte has been loaded into the TX buffer not when the TX buffer has completed its output. Is this correct or have I missed something?
Any help would be appreciated