cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4 UART IRQ issue

vivek23
Associate II
Posted on January 22, 2015 at 10:07

Hi,

I am trying to receive RF packet using USART1 IRQ, using below code. But packets are missing in the receive end.

My point here is sometimes i will receive packets and the received packet is completely valid, i mean all received bytes are perfect.

But I am expecting interrupt IRQ to be called many times. but thats not happening here.

Can any one please suggest me is my IRQ function is valid ?

void USART

1

_IRQHandler(void)

{

char c;

uint

8

_t rByte=

0

,lsb=

0

,msb=

0

,rCnt=

0

;

c=USART_ReceiveData(USART

1

);

switch(rByte)

{

case

0:

if(c==PACKET_DELIMETER)

{

received_String[rCnt++]=c; //first byte copied to array

rByte=

1

;

}

break;

case

1:

msb=c; //Second byte copied to array

received_String[rCnt++]=msb;

rByte=

2

;

break;

case

2:

lsb=c; //

3

rd byte copied to array

received_String[rCnt++]=lsb;

rByte=

3

;

break;

case

3:

if(c==ZB_API_RECEIVEPACKET)

{

received_String[rCnt]=c;

for(rCnt=

4

;rCnt<lsb+

1

;rCnt++)

{

received_String[rCnt]=c; // whole packet will be received at this point

}

rByte=

4

;

}

break;

case

4:

if(received_String[

15

]==g_ch_indx && received_String[

16

]==g_frame_Id)

{

g_bOK=

1

;

g_nei_id = received_String[

17

];

}

break;

default

:

break;

}

}

4 REPLIES 4
Posted on January 22, 2015 at 11:07

Unreadable wall of code here, please try again with the code, and explanation of the problem.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
vivek23
Associate II
Posted on January 22, 2015 at 11:48

Sorry for the wrong format. Now I have corrected it. Please suggest is the code can work as expected.

Posted on January 22, 2015 at 11:48

You assume that the variables you use are static, i.e. don't change between successive invocations of the routine, but you don't declare them as such.

JW

vivek23
Associate II
Posted on January 23, 2015 at 02:26 Hi, Thanks for your reply. But I tried even declaring my variables as static. Still i cannot receive my data packets contentiously. Many packets are missing in between. All the packets are reaching my receiving device. But interrupt IRQ happening very few times.

volatile char c; // tried by declaring c as volatile char and char
uint
8
_t lsb=
0
,msb=
0
;
static
uint
8
_t rByte=
0
,rCnt=
0
; // 
static
variables