Feco
Newbie level 6
- Joined
- May 13, 2013
- Messages
- 12
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,371
Hello. I'm a beginner at microcontroller programming. I have an STM32VL Discovery board and I made a simple program that counts up and sends the values via USART. I thought it's an easy task. Well the program is working, but I am getting wrong data. On the serial monitor I see the ASCII characters, not the numbers. How can I change it? I want it to show the numbers, not the ASCII.
Here is my code:
Well, it's working if I change n=0 to n=48 but it still only counts until 9, so it wouldn't be the best solution.
Thanks for the help.
Here is my code:
Code:
#include <stm32f10x.h>
int n = 0;
void usart_snd(int data) {
while(!(USART1->SR & USART_SR_TXE));
USART1->DR = data;
}
void usart_snd_str(char *str) {
while(*str != 0) {
usart_snd(*str);
str++;
}
}
int main() {
RCC->APB2ENR |= RCC_APB2ENR_USART1EN | RCC_APB2ENR_IOPAEN;
RCC->APB1ENR |= RCC_APB1ENR_TIM3EN;
GPIOA->CRH = 0x4B0;
USART1->BRR = (SystemCoreClock/9600);
USART1->CR1 = USART_CR1_UE | USART_CR1_TE;
TIM3->PSC = 23999;
TIM3->ARR = 1000;
TIM3->CR1 = TIM_CR1_CEN;
while(1) {
if (TIM3->SR & TIM_SR_UIF) {
TIM3->SR &= ~TIM_SR_UIF;
usart_snd_str("Count:\t");
usart_snd(n);
usart_snd_str("\n\r");
n++;
}
}
}
Well, it's working if I change n=0 to n=48 but it still only counts until 9, so it wouldn't be the best solution.
Thanks for the help.