cancel
Showing results for 
Search instead for 
Did you mean: 

USART2 makes trouble

primagen23
Associate II
Posted on September 19, 2011 at 21:24

Hi,

i own an stm32f103 Board. USART1 is configured as TX via DMA and RX Polling.

I tried to configure the USART2 port TX polling and RX polling.

Confusing thing is that after sending on char to console the board resets in loop and the Console of USART2 prints after each reset a square symbol.

Configuration of USART2:

RCC->APB2ENR |= (RCC_APB2ENR_IOPAEN | RCC_APB2ENR_AFIOEN); RCC->APB1ENR |= RCC_APB1ENR_USART2EN; GPIO_CONF_OUTPUT_PORT(A,2,ALT_PUSH_PULL,50); GPIO_CONF_INPUT_PU_PD(A,GPIO_CM3); GPIOA->BSRR = GPIO_BSRR_BS3; USART2->CR1 = USART_CR1_UE; //Enable USART ((u16)0x2000) USART2->CR2 = 0; //Stopbits USART2->CR1 |= USART_CR1_TE; // Transmitter Enable ((u16)0x0008) USART2->BRR= 0x45; //Baudrate 115200 USART2->CR1 |= USART_CR1_RE; USART2->CR1 |= USART_CR1_RXNEIE; NVIC_SET_PRIORITY(USART2_IRQChannel, 2); NVIC_ENABLE_INT(USART2_IRQChannel); send routine:

int u2_putchar(int c) { while (!(USART2->SR & USART_SR_TXE)); USART2->DR = (c & 0xFF); return(c); } and in main i call u2_putchar(4); Without this call evrything works.

6 REPLIES 6
Andrew Neil
Evangelist
Posted on September 20, 2011 at 12:38

''i own an stm32f103 Board''

What board, exactly?

USART2->CR1 |= USART_CR1_RE;

 

USART2->CR1 |= USART_CR1_RXNEIE;

 

You didn't comment those lines - what do you think they do...?

NVIC_SET_PRIORITY(USART2_IRQChannel, 2);

 

NVIC_ENABLE_INT(USART2_IRQChannel);

You've enabled the interrupt - but you haven't shown your handler...

primagen23
Associate II
Posted on September 20, 2011 at 13:00

What board, exactly?

TN100 Modul from Dizic. Quite unknown i think.

USART2->CR1 |= USART_CR1_RE;

USART2->CR1 |= USART_CR1_RXNEIE;

You didn't comment those lines - what do you think they do...?

i didnt comment them because RX is needed too. Below the handler for RX/TX

void USART2_handler(void)__attribute__((interrupt));

void uart2_rx_interrupt(void);

void USART2_handler(void)

{

uart2_rx_interrupt();

}

void uart2_rx_interrupt(void)

{

uint8_t c;

c = USART2->DR;

if(uart2_input_handler != NULL)

{

uart2_input_handler(c);

}

}

int u2_putchar(int c)

{

while (!(USART2->SR & USART_SR_TXE));

USART2->DR = (c & 0xFF);

return(c);

NVIC_SET_PRIORITY(USART2_IRQChannel, 2);

 

NVIC_ENABLE_INT(USART2_IRQChannel);

You've enabled the interrupt - but you haven't shown your handler...

i think now i shown evry handler. But where is now the problem

________________

Attachments :

TN100_Demo_rev_A_Schematic.pdf : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I0bd&d=%2Fa%2F0X0000000bb5%2F4PZ.5P98giHa_dqhV_shsNrtu.wfZQm9r_oiIZRFvJI&asPdf=false
trevor23
Associate III
Posted on September 20, 2011 at 14:40

You havn't shown ''uart2_input_handler''.

Where do you clear the interrupt?

Please include everything otherwise it takes a long time to ''extract'' the information required to help you.

Regards

Trevor
primagen23
Associate II
Posted on September 26, 2011 at 22:24

No one an Idea?

Posted on September 26, 2011 at 23:08

No one an Idea?

It's a forum, it's more probable that no one is interested. There are far more people who contribute problems, than contribute solutions.

I've have 3 USART's running with DMA and interrupts, works fine. You might however want to actually confirm/qualify the source of the interrupt, or if RXNE is actually set before randomly reading the data register.

Confusing thing is that after sending on char to console the board resets in loop and the Console of USART2 prints after each reset a square symbol.

I'm confused by this description. You get odd random square characters when you reset the board? Getting some unframed junk at reset is not a unique phenomena. The board resets when it receives a character? Please restate the problem clearly.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
primagen23
Associate II
Posted on April 13, 2012 at 12:28

Problem is solved. How can i close this thread?

In Debugger i see that rx interrupt loops.

I checked the soldering and see that pin rx is contacting an jtag line.