cancel
Showing results for 
Search instead for 
Did you mean: 

SPI interruption problem

love-peace2001
Associate II
Posted on April 04, 2014 at 16:43

Hi all,

I

would like to know

if anyone has a problem when

enabling the Tx buffer empty interrupt. In fact, when i put SPI_I2S_ITConfig(SPI1, SPI_I2S_IT_TXE, ENABLE);  , the code coming after can't be executed

switch (USBButton)

    {

      /* BUTTON_USER button pressed */

     case 0x01:    

          SendMode=0x01;

          ReceveMode=0x00;

          CmdTransmitted = 0x01;

     break;

     .

     .

     .

}

if (CmdTransmitted != 0x00)

{    

    /* Enable the Tx buffer empty interrupt */

   SPI_I2S_ITConfig(SPI1, SPI_I2S_IT_TXE, ENABLE);    

            

    /* Transmission mode */

   if(SendMode==0x01)

    {    

    STM_EVAL_LEDOn(LED7);

   while(CmdStatus==0x00);

            

   while(Tx_Idx < DATA_SIZE);

   /* Waiting until TX FIFO is empty */

  while (SPI_GetTransmissionFIFOStatus(SPI1) != SPI_TransmissionFIFOStatus_Empty)

  {}

    

   /* Wait busy flag */

    while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET)

  {}

 }

/*------SPI handler --------*/

void SPI1_IRQHandler(void)

{

    

 /* SPI in Master Tramitter mode--------------------------------------- */

  if (SPI_I2S_GetITStatus(SPI1, SPI_I2S_IT_TXE) == SET)

  {

   if (CmdStatus == 0x00)

   {

      SPI_SendData8(SPI1, CmdTransmitted);

      CmdStatus = 0x01;

       Tx_Idx=0x00;

        STM_EVAL_LEDOn(LED5);

   }

   else

   {

        if(SendMode)

        {  

          SPI_SendData8(SPI1, CommandRegister_Tx[Tx_Idx++]);

          STM_EVAL_LEDOn(LED3);

          if (Tx_Idx == 4)

          {

                STM_EVAL_LEDOn(LED10);

               /* Disable the Tx buffer empty interrupt */

              SPI_I2S_ITConfig(SPI1, SPI_I2S_IT_TXE, DISABLE);

          }

     } 

  }

}     

This code is for the master. In the slave side, i can receive what the master sends but it doesn't enter to if(SendMode==0x01). Any suggestion.

I hope that it's clear enough to understand the issue.
7 REPLIES 7
love-peace2001
Associate II
Posted on April 04, 2014 at 17:35

It seems that when  i enable TX SPI interrupt, the program doesn't exit from the SPI handler

love-peace2001
Associate II
Posted on April 09, 2014 at 17:04

Could you tell please what would be the issue if you have an idea  ?

I can't fix this problem.

stm322399
Senior
Posted on April 09, 2014 at 17:13

There is no initialization of CmdStatus, little wonder that your ISR is running endlessly.

love-peace2001
Associate II
Posted on April 09, 2014 at 18:22

Thanks Laurent for you replay.

No, i have initialized it in the beginning before the switch (USBButton)

CmdTransmitted = 0x00;

CmdStatus = 0x00;

Tx_Idx = 0x00;

 Rx_Idx = 0x00;

stm322399
Senior
Posted on April 09, 2014 at 19:55

Tell us a bit more about LED, how they behave ...

Did you enable another SPI interrupt, somewhere else ?

love-peace2001
Associate II
Posted on April 16, 2014 at 17:57

The original post was too long to process during our migration. Please click on the provided URL to read the original post. https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I6oM&d=%2Fa%2F0X0000000bvy%2FCtkwtXSI7ptD.BcT7N.6Au6Is2NHVBo.CGoaEBJQZWc&asPdf=false
michaelk
Associate
Posted on June 18, 2014 at 10:23

Hi,Franck

Can you please tell us how have you solved the problem ?

Thank You