cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F411RET6 - Working with pointers

hackerli90
Associate II
Posted on September 16, 2015 at 15:48

Hello

Im working on a simple uController software to control a clock. Im working with a Nucleo controllerboard (STM32F411RET6) and uVision Keil V5.

To be able to manipulate acutal variables instead of copies, id like to work with pointers (and as far as i know, char array need to be handled as pointers anyway). 

I placed my questions 1-11 directly at the line where i dont know how to work with those values. thanks for advise.

Software:

// main.h prototypes:

void time_clock_management(int* ss, int* mm, int* hh);    // declare as pointers correct? Question 1

void USART_string_send(char* text);                       // declare as pointer correct? Question 2

// main.c private variables:

char TxOptions[] = ''\n\rOptions:\n\r\ts set time\n\r''; //!

uint8_t sec = 0;

uint8_t min = 0;

uint8_t hour = 0;

// main.c functions:

void time_clock_management(int* ss, int* mm, int* hh){    // declare as pointer correct? Question 3

/* Count */

*ss++;                                                  // work with variable (acutal value, pointer) instead of adress correct? Question 4

if(*ss==60){*ss=0; *mm++;}                              // work with variable (acutal value, pointer) instead of adress correct? Warning: expression result unused. Question 5

if(*mm==60){*mm=0; *hh++;}                              // work with variable (acutal value, pointer) instead of adress correct? Warning: expression result unused. Question 6 

if(*hh==13){*hh=1;}                                     // work with variable (acutal value, pointer) instead of adress correct? Question 7

}

void USART_string_send(char* text){                       // declare as pointer correct? Question 8

foo_func_where_param_charArr_is_required(*text);        // place as pointer into a function? Question 9

}

// main.c call functions:

time_clock_management(&sec, &min, &hour);                 // here *pointer, &reference or actual value?? Question 10

USART_string_send(TxOptions);                             // here *pointer, &reference or actual value?? Question 11

#pointers
3 REPLIES 3
qwer.asdf
Senior
Posted on September 16, 2015 at 16:12

Question 1:

No, your sec, min and hour variables are uint8_t type, so the pointers must also be uint8_t*, so the correct way is:

void time_clock_management(uint8_t* ss, uint8_t* mm, uint8_t* hh);

Question 2: Yes

Question 3: See Question 1

Question 4: Yes

Question 5: Yes

Question 6: Yes

Question 7: Yes

Question 8: Yes

Question 9:

where is foo_func_where_param_charArr_is_required definition?

You are passing one char to it (the first character of the string).

Maybe you wanted to pass the string, then

foo_func_where_param_charArr_is_required(text);

is the correct way of doing it.

Question 10, Question 11:

There are no references in C (you are using C not C++ right?)

time_clock_management(&sec, &min, &hour);

// It's OK, you are passing pointers which are being expected

USART_string_send(TxOptions);

// Also OK, you passing pointer which is expected by the function

You should read books on C, or some online tutorials at least, like http://pw1.netcom.com/~tjensen/ptr/pointers.htm (first thing in google)
Posted on September 16, 2015 at 17:17

Not sure that's right,

*ss++;  // Advances the pointer, reads the value to nowhere

(*ss)++; // Increments the value pointed too, not the pointer

These would be equivalent

USART_string_send(TxOptions);

USART_string_send(&TxOptions[0]);

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on September 16, 2015 at 17:20

The logic you're looking for

void time_clock_management(uint8_t* ss, uint8_t* mm, uint8_t* hh); // Proto type     void time_clock_management(uint8_t* ss, uint8_t* mm, uint8_t* hh)

{

/* Count */

(*ss)++;

if(*ss==60){*ss=0; (*mm)++;}

if(*mm==60){*mm=0; (*hh)++;}

if(*hh==13){*hh=1;}

}

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..