Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Easy problems on usart STM32

Status
Not open for further replies.

draaknar

Newbie level 3
Joined
Oct 1, 2013
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
45
Hello guys!

I have two functions where i have a RX-INTERRUPT and i send data via TX.
But i cannot understand a simple problems ive come accross.

  1. Why cant i write printf("%d",index_rx) in my void USART1_IRQHandler(void) function?;---> is it because "uint8_t" and "int" are not the same?? ,I know that we have to use "%d" when its an "int" declaration.
  2. Why doesnt it work when i write int index_rx=0;, and compile, whats the difference between static and int ?


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
void USART1_IRQHandler(void){
static uint8_t index_rx=0;
if(USART_GetITStatus(USART1, USART_IT_RXNE)!=RESET);
{
StringLoop[index_rx++]=USART_ReceiveData(USART1);
}
void send_data(USART_TypeDef* USARTx, volatile char *str){
while (*str)
{
while(USART_GetFlagStatus(USARTx, USART_FLAG_TXE) == RESET);
USART_SendData(USARTx, *(str++));
}
}

 
Last edited by a moderator:

DTFT

Newbie level 6
Joined
Feb 18, 2014
Messages
11
Helped
4
Reputation
8
Reaction score
4
Trophy points
3
Activity points
79
I can't answer all your questions, but here is how I would go about figuring out the answers:

* Try doing a printf() call in the handler function, but without referencing any variable. If that works but it fails with the uint_8 type, you know your issue is with the variable.
* Cast index_rx as an int when you call printf:
Code:
printf("%d", (int)index_rx);(

*The difference between statically declared variables and locally declared variables is that static variables are basically stored 'permanently' in memory, i.e. they persist even after your function has returned to its caller. Non-static variables are called local variables, and exist only on the stack while that particular instance of the function is running. When the function returns, that local variable is thrown away. So if you declare static int x and let x=5, and then return, next time your function is called, x will still be 5. Local variables don't do that.

It would seem weird to me that the compiler isn't letting you declare a local variable. There can be issues with stacks overwriting data, etc., but you should still be able to create local variables and use them, even in an interrupt handler. Can you confirm that the code will compile and run with the variable declared as static, but not without the static keyword?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top