Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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.