How to use the for loop in a simple sequence with STM32H7 in a SPI transmission?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-07-06 6:16 AM
Hello everyone,
I am trying to replace a simple code in C inside a STM32H7 that goes like this:
function(0, &array[0]);
function(1, &array[1]);
function(2, &array[2]);
function(3, &array[3]);
function(4, &array[4]);
with
enum_variable_t index ;
for(index = FIRST_ENUM ; index < LAST_ENUM; index ++)
{
function((uint16_t)index , &array[index]);
}
However, some data is corrupted due to this simple change, I thought it might be an optimization problem but I can't solve it by including the (-O) flag. Any advice would be of great help.
Regards
Alan
Solved! Go to Solution.
- Labels:
-
SPI
-
STM32H7 Series
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-07-09 5:30 AM
Quick update
I have changed all global variables to volatile and now everything works as intended.
Regards!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-07-06 6:29 AM
Hello,
Does your SPI is master in transmission ?
Br,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-07-06 6:30 AM
Yes it is
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-07-06 6:35 AM
What data is corrupted? There's nothing wrong with the code you posted, assuming FIRST_ENUM=0 and LAST_ENUM=5.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-07-06 6:36 AM
And when you say data is corrupted, it means that all the next data are wrong or are they any recovery ? Is data shifted by some bits ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-07-06 6:47 AM
Hi @CPINA​ ,
When I read the values in array[0] without the for loop, I get these values (which are correct)
But when I replace the code with the for loop (nothing else changes) I get this data.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-07-06 6:48 AM
The blue line represent array[0]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-07-06 6:49 AM
Hi @TDK​
I explained in the topic avode what I mean with corrupted data.
Regards
Alan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-07-06 7:22 AM
Not sure to understand, for both blue line is your array[0) ? I was thinking it was the yellow one. what is supposed to be the data linked to array[0].
If the data line is supposed to be the blue one, it seems it is even not a data, looks like noise. Did you check that the SPI is well configured in debug just before writing the data into the data register ? Please confirm to me, you are master transmitter in such case ? If yes can you see the SPI going out after writing the Data register of the SPI ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-07-06 11:09 PM
Hello @CPINA​
After restarting my computer today morning it seems that the problem solves itself and now works without the error, some kind of magic I guess.
Regards
Alan
