AnsweredAssumed Answered

SPI Problems

Question asked by sandl.dave on Aug 16, 2013
Latest reply on Aug 17, 2013 by sandl.dave
I am using the STM32F103 to interface with a FPGA over SPI and I am having the following issue.

When I am reading a 32 bit variable from the FPGA (4 bytes) it seems to work fine with the first communication and then have a problem with the remaining time I read it.

It looks like it is still using data from the previous read in to the new one. If I reset the STM32 in debug (not doing anything to the FPGA) it will read correctly for 1 time again.

Here is an example read:
Data sent is 56787
First read : 00 00 DD C0 (correct)
Second read: C0 00 DD C0 (not right)

My SPI code is the following

uint32_t FPGASendVelocity(uint32_t velocityCommand )
{
  uint32_t i;
  uint32_t remaining = 0;
  uint8_t src_addr[5];
  uint8_t inBuff[5] = {0,0,0,0,0};
  uint8_t temp1, temp2, temp3, temp4;

  src_addr[0] = 2; // Send the set velocity command first
  // Send the 24 bit value
  src_addr[1] = velocityCommand >> 16; src_addr[2] = velocityCommand >> 8; src_addr[3] = velocityCommand;

  GPIO_WriteBit(GPIOC, GPIO_Pin_6, 0); // Set SSEL pin low
  for(delay=0; delay<SPIDELAY; delay++); // Delay due to timing issuse?

  for ( i = 0; i < 4; i++ )
  {
      // Data out
      while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);
      SPI_I2S_SendData(SPI1, src_addr[i]);

      // Data in
      while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET);
      inBuff[i] = SPI_I2S_ReceiveData(SPI1);

      for(delay=0; delay<SPIDELAY; delay++);
  }

  GPIO_WriteBit(GPIOC, GPIO_Pin_6, 1); // Set SSEL pin high

  remaining |= (inBuff[0] << 24);
  remaining |= (inBuff[1] << 16);
  remaining |= (inBuff[2] << 8);
  remaining |= (inBuff[3]);

  return remaining;
}

Any help would be appreciated


Dave

Outcomes