cancel
Showing results for 
Search instead for 
Did you mean: 

USART check flags and assert failure

russ
Associate II
Posted on July 29, 2008 at 23:50

USART check flags and assert failure

3 REPLIES 3
russ
Associate II
Posted on May 17, 2011 at 12:40

This is weird:

I am getting two processors to communicate with each other without flow control. The communication I am getting seems to work, but there appears to be some strangeness with receive characters. About half of the time my incoming datastream is recognized as good (including CRC checks). The other half of the time the incoming characters are all shifted (as if the null character signals are not getting read).

I don't know if this relates, but I'm getting assert failures every time I check my USART flags. I changed my assert routine so that it no long has a while loop in it and things seem to be okay (as detailed as above). Can anyone see why my assertions might fail?

My code that is generating the failed assertion:

u8 uart_check_for_char(void)

{

u8 Status;

Status = USART_GetFlagStatus(USARTx, USART_FLAG_RXNE);

USART_ClearFlag(USARTx, USART_FLAG_RXNE);

return (Status);

}

Defines:

#define USE_USART1

#ifdef USE_USART1

#define USARTx USART1

#define GPIOx GPIOA

#define RCC_APB2Periph_GPIOx RCC_APB2Periph_GPIOA

#define GPIO_RxPin GPIO_Pin_10

#define GPIO_TxPin GPIO_Pin_9

The assertion failure is being generated by the USARTx input, I believe.

16-32micros
Associate III
Posted on May 17, 2011 at 12:40

Hi russ1,

I think, that the failure you are seeing is coming from : USART_ClearFlag(USARTx, USART_FLAG_RXNE); because The RXNE bit is automaticaly cleared when you read ''USART_DR'' register to get your previous character. ( refer to RM0008, section 24.6). so clearing it manually again in your checking routine we may loose some extra bytes. Could you please check and let me know ?.

Cheers, ST1 :-?

russ
Associate II
Posted on May 17, 2011 at 12:40

I don't think that clearing the flag is the problem (I have since fixed that).

I am now using interrupts and my USART interrupt configuration routine is giving me the same grief:

/* Enable USART1 Receive interrupts */

USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);

This function takes me to this assembly code (it errors out on the final assertion check on the ''USART1'' parameter. This is weird because I am no longer using defines for this (i.e. USARTx). I don't expect anyone to go through the assembly to figure out the issue. I merely post it to verify exactly where the assertion failure is generated.

->

B570 push {r4-r6, lr}

B081 sub sp, 0x004

{

B28C uxth r4, r1

u32 usartreg = 0x00, itpos = 0x00, itmask = 0x00;

u32 usartxbase = 0x00;

/* Check the parameters */

assert_param(IS_USART_ALL_PERIPH(USARTx));

4B49 ldr r3, [pc, 0x124]

9900 ldr r1, [sp, 0x000]

{

4616 mov r6, r2

u32 usartreg = 0x00, itpos = 0x00, itmask = 0x00;

u32 usartxbase = 0x00;

/* Check the parameters */

assert_param(IS_USART_ALL_PERIPH(USARTx));

4A48 ldr r2, [pc, 0x120]

1ACB subs r3, r1, r3

BF18 it ne

2301 movne r3, 0x01

{

AD01 add r5, sp, 0x004

u32 usartreg = 0x00, itpos = 0x00, itmask = 0x00;

u32 usartxbase = 0x00;

/* Check the parameters */

assert_param(IS_USART_ALL_PERIPH(USARTx));

4291 cmp r1, r2

BF0C ite eq

2300 moveq r3, 0x00

F0030301 andne r3, r3, 0x00000001

{

F8450D04 str r0, [r5, -0x04]!

u32 usartreg = 0x00, itpos = 0x00, itmask = 0x00;

u32 usartxbase = 0x00;

/* Check the parameters */

assert_param(IS_USART_ALL_PERIPH(USARTx));

B17B cbz r3 0x0800488E

4B43 ldr r3, [pc, 0x10C]

4299 cmp r1, r3

D00C beq 0x0800488E

F5036380 add.w r3, r3, 0x00000400

4299 cmp r1, r3

D008 beq 0x0800488E

F5036380 add.w r3, r3, 0x00000400

4299 cmp r1, r3

D004 beq 0x0800488E

483E ldr r0, [pc, 0x0F8]

F44F71B4 mov.w r1, 0x00000168

F7FBFDF1 bl 0x08000470

-> FAILURE HERE ^^^^^