cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F722IEK6 processor not counting properly

Brian D
Associate III
Posted on April 21, 2018 at 02:41

The original post was too long to process during our migration. Please click on the attachment to read the original post.
13 REPLIES 13
T J
Lead
Posted on April 21, 2018 at 03:11

this works

unsigned char SPI_t::transfer_receive(unsigned short data) {

    char RxSPI;

 //   Clear_SPI1_nSS_Out();

    while (!(hspi1.Instance->SR  & SPI_FLAG_TXE))

        ; // make sure we are ready

    while ((hspi1.Instance->SR  & SPI_FLAG_RXNE))

        RxSPI = hspi1.Instance->DR;  //clear out / read all the bytes left in the Rx register

    *((__IO uint8_t *)&hspi1.Instance->DR) = data;                // force the SPI to transceive 8 bit

    while (!(hspi1.Instance->SR  & SPI_FLAG_TXE))

        ;      //wait for buffer to start shifting

    while ((hspi1.Instance->SR  & SPI_FLAG_BSY))

        ;     // wait for all bits to completely leave the chip

    while ((hspi1.Instance->SR  & SPI_FLAG_RXNE))

        RxSPI = hspi1.Instance->DR;  //read all the bytes left in the Rx register, the last one is for your reading.

 //   Set_SPI1_nSS_Out();               

    return RxSPI;

}
Brian D
Associate III
Posted on April 21, 2018 at 04:12

TJ,

I don't have question for SPI -- it works fine.

My question is about the spi non-related delay loop: 

for(n=0; n<1500; n++); that it took too long but I don't know what had caused the problem.

Brian

Posted on April 21, 2018 at 05:37

I guess you already know that it is bad practice to use a counter delay like that.

that's why they installed timers in the first place, to be processor clock/cache/wait variable type, etc. independent.

a float would count much slower than an int.

Brian D
Associate III
Posted on April 21, 2018 at 07:20

This is just a simple test code to emulate a camera controlling the lens via a sort of SPI bus. The delay counting loop is a quick way for the test; without any interrupts the countering loop should be precise. No floating here; just unsigned int. I'd like to know where to look for the cause of this behavior.

Brian

Posted on April 21, 2018 at 07:32

if you have a scope, you could show us all...

there has to be another process interfering with your execution.

Brian D
Associate III
Posted on April 21, 2018 at 08:14

I had attached the delay timings. What other things you like to see? Even if there is other task that interrupted the counting loop, why it consistently only interrupted the delay loop in the canon_w but never the canon_read()?

Posted on April 21, 2018 at 08:53

You have a strange aberration ..

let me suggest that you create the new Variable in the FOR loop, they are just registers anyway.

for ( int I =0;I<1500;I++);

Joerg Wagner
Senior III
Posted on April 21, 2018 at 22:58

Instruction cache enabled?

Brian D
Associate III
Posted on April 22, 2018 at 00:37

Thanks for the suggestion. I started with variable n in all the loops, then changed to m in the troubled loop with no difference, then defined m as Static, but no difference.