cancel
Showing results for 
Search instead for 
Did you mean: 

How to use the for loop in a simple sequence with STM32H7 in a SPI transmission?

ABlum.2
Associate III

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

12 REPLIES 12

Hello Alan,

Great !! I think the SPI was afraid about us 🙂 ! Have a nice day and a lot of fun with STM32.

Best regards,

Christophe

In order to give better visibility on the answered topics, please click on 'Select as Best' on the reply which solved your issue or answered your question. See also 'Best Answers'

ABlum.2
Associate III

Quick update

I have changed all global variables to volatile and now everything works as intended.

Regards!