This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

ISR and Function, using problem

Hello! I have same code

#define N_command 10
void Shift_query(struct query *spi_command_query);
struct query{unsigned char cmd;
                         unsigned char word;
                         unsigned char rw;
                        }query;
/************************/
struct query spi_command_query[N_command];
void SPI_ISR(void) interrupt 6 using 1
{
//same operation.....
Shift_query(spi_command_query);
}

void Shift_query(struct query *spi_command_query)
{
data unsigned char i = 0;
for(i = 1; i <N_command - 1; i++)
        {
         spi_command_query[i-1] = spi_command_query[i];
         if (!spi_command_query[i-1].cmd){break;}
        }
}
<!pre>
performs an array of structures shift to the left by one position, or rather should perform, but after performing the function of an array of structures remains unchanged, but the other functions produced by the interruption performed correctly.
where I'm wrong??
I suspect that the fault lies in the use of the interruption of another set of registers.
Thanks for the help.


  • Did the preview look good - didn't you notice that your code section did continue?

    Next thing. You have an array of 10 elements.

    Your look iterates from 1 to < 9.
    1,2,3,4,5,6,7,8 is only 8 elements.
    But when removing the first element, you have up to 9 elements to move.

    Another thing - your interrupt specifies the "using" clause. Why call a function that isn't specifying the same register bank?

  • Your look iterates from 1 to < 9.
    1,2,3,4,5,6,7,8 is only 8 elements.
    But when removing the first element, you have up to 9 elements to move.

    Oh.. thanks, its my mistake, but i have not moved more than one of the elements.


    Another thing - your interrupt specifies the "using" clause. Why call a function that isn't specifying the same register bank?

    correctly indicate whether it will be all the functions that are called from interrupt the same bank of registers.?
    I also tried using products directive #pragma NOAREGS, but it did not help.

  • On one hand, "using 1" for the shift function would be a good idea.

    On the other hand - you should keep your ISR fast. That function call with up to 9 iterations does take time. And having such a big difference in runtime between fastest and slowest makes it harder for you to test your application.

    Why can't you just use a traditional ring buffer with a read and a write position and let the "producer" update the "write" position and the "consumer" update the "read" position? You would get a fast constant-time implementation.

  • my application does not require a great speed, to the same frequency MCU 100Mhz, while the frequency of the order of SPI 200kHz.
    Thank for help.

  • Why can't you just use a traditional ring buffer with a read and a write position and let the "producer" update the "write" position and the "consumer" update the "read" position? You would get a fast constant-time implementation.

    I have a many devices on one SPI bus, and work with each in turn, and query each time different. My query contains structure (device, data, operation)and need to move by spi isr's

  • Are there more than one place that calls Shift_query()?

    That your processor is fast enough is a separate issue. A slow ISR can affect the response time for other ISR - such as serial processing.