ARM STM32F103 USART - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

ARM STM32F103 USART

Hi all,

I am new to keil programming. I facing some problems when I use USART communication with STM32F103, I am using J-Link debugger to link with the controller.Please help :)

Below is the source I have modify,

#include
#include
#include "STM32_Init.h"

#define enter 0x000D

int SendChar (int ch) {

while (!(USART1->SR & USART_FLAG_TXE));
USART1->DR = (ch & 0x1FF);

return (ch);
}

int GetKey (void) {

while (!(USART1->SR & USART_FLAG_RXNE));

return ((int)(USART1->DR & 0x1FF));
}

int main (void)
{
stm32_Init();

while (1)
{ int i = 0;
unsigned char c[100];

printf ("Press a key...
");
while(1)
{ c[i] = getchar();
i++;
if (c[i-1] == enter )
{ printf("You pressed %s

", c);
printf("Press a key...
");
i = 0;
}
}
}
}

Below is the error:

Press a key...
You pressed

Press a key... // input words overwrite the message 'You pressed '
You pressed 123 // at right hand side of the keyboard
// was use.
Press a key...
23u pressed

Press a key...
You pressed 23

Press a key...
3ou pressed

Press a key...
You pressed 1

Press a key...
You pressed

Press a key...


Sign In or Register to comment.