STM32F722IEK6 processor not counting properly
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2018-04-20 5:41 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2018-04-20 6:11 PM
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 readywhile ((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;}- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2018-04-20 7:12 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2018-04-20 10:37 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2018-04-21 12:20 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2018-04-21 12:32 AM
if you have a scope, you could show us all...
there has to be another process interfering with your execution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2018-04-21 1:14 AM
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()?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2018-04-21 1:53 AM
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++);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2018-04-21 1:58 PM
Instruction cache enabled?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2018-04-21 5:37 PM
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.
