AnsweredAssumed Answered

Simple SPI problem

Question asked by lombardini.luca on Jul 11, 2012
Latest reply on Jul 12, 2012 by lombardini.luca
Hi all,

I have a simple routine called in TIMER_IRQ event that set GPIO and than set a DAC on SPI BUS. This routine must be quick as possible.
Regarding the GPIO setting there is no particular problem, while SPI has some trouble:

1) Obviously this code doesn't work because CS is rising during SPI Trasmission

  SPI1_CS1_LOW();

    SPI_I2S_SendData(SPI1, DacValue);

  SPI1_CS1_HIGH();

2) Using a simple delay make things working but the routine in not quick now

  SPI1_CS1_LOW();

    SPI_I2S_SendData(SPI1, DacValue);

  int i = 100;

  while(i--);

  SPI1_CS1_HIGH();

 3) I tried to use SPI IRQ but unfortunately the routine doesn't work. Could enyone give me some code sample to rise the CS after the SPI trasmission and without using delay cicle?
For your information below the code that doens't work:

  SPI1_CS1_LOW();

 

if (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) != RESET)

 

  SPI_I2S_SendData(SPI1, DacValue);

 

  SPI_I2S_ITConfig(SPI1, SPI_I2S_IT_TXE, ENABLE);

 

 

 

  void SPI1_IRQHandler(void){

 

  if (SPI_I2S_GetITStatus(SPI1, SPI_I2S_IT_TXE) != RESET){

 

//      SPI_I2S_ClearITPendingBit(SPI1, SPI_I2S_IT_TXE);

 

      if(SPI_I2S_GetFlagStatus(SPI1,SPI_I2S_FLAG_BSY) == RESET){

 

        SPI_I2S_ITConfig(SPI1, SPI_I2S_IT_TXE, DISABLE);

 

        SPI1_CS1_HIGH();

 

      }

 

    }

Thanks in advance
Luca Lombardini




Outcomes