Hi… I am transferring “TEST” string from the USART 1 to the hyper terminal. But at hyper terminal end I get only the char “T”. After that microcontroller unable to transfer the data. Please go through the following program, is there any problem in the code.This code is written for stm32 arm controller.
#include <stm32f10x_lib.h> #include <stdio.h> #include"stm32_reg.h"
int main() { unsigned char a[]="TEST",i; RCC->CFGR=0x001D8402; RCC->CR= 0x01010082; RCC->APB2ENR |= RCC_APB2ENR_AFIOEN ; AFIO->MAPR &= ~(1<<2) ; RCC->APB2ENR |= RCC_APB2ENR_IOPAEN; GPIOA->CRH &= ~(0xFFUL << 4); GPIOA->CRH |= (0x0BUL << 4); GPIOA->CRH |= (0x04UL << 8); RCC->APB2ENR |= RCC_APB2ENR_USART1EN; USART1->BRR |= 0x27<<4; USART1->BRR |=0x1; USART1->CR1= 0x0000; USART1->CR2=0x0000; USART1->CR3=0x0000; USART1->CR1|=0x8; USART1->CR1 |= USART_CR1_UE; for(i=0;i<7;i++) { USART1->DR=a[i] ; while (!(USART1->SR & USART_FLAG_TXE)); } }
Are you sure that you can read your own sourcecode ?!?!?
#include <stm32f10x_lib.h> #include <stdio.h> #include "stm32_reg.h" int main() { unsigned char a[]="TEST", i; RCC->CFGR = 0x001D8402; RCC->CR = 0x01010082; RCC->APB2ENR |= RCC_APB2ENR_AFIOEN; AFIO->MAPR &= ~(1<<2); RCC->APB2ENR |= RCC_APB2ENR_IOPAEN; GPIOA->CRH &= ~(0xFFUL << 4); GPIOA->CRH |= (0x0BUL << 4); GPIOA->CRH |= (0x04UL << 8); RCC->APB2ENR |= RCC_APB2ENR_USART1EN; USART1->BRR |= 0x27<<4; USART1->BRR |= 0x1; USART1->CR1 = 0x0000; USART1->CR2 = 0x0000; USART1->CR3 = 0x0000; USART1->CR1 |= 0x8; USART1->CR1 |= USART_CR1_UE; for(i=0;i<7;i++) { USART1->DR=a[i]; while (!(USART1->SR & USART_FLAG_TXE)); } }
. BR, /th.
Nice to see the reply!! Your reply contains the same source code that i put on the forum. Plz go through it.
With one important difference - did you notice...?!
"Plz go through it"
Have you gone through it?
Have you stepped through it with the debugger?
Have you verified it against the chip's datasheet, and the examples provided by ST?
The first error can be seen after max 5 seconds of looking at the code. If there are such obvious errors, it's quite likely to be more errors hidden there too.
This is an forum .Right. Where people get the solution. But you are critic's. Good!!!!!
To be precise, the scope & purpose of the forum are defined thus:
"The Keil Discussion Forum is an open forum where you may post questions and comments about Keil products."
See here: http://www.keil.com/forum/
"Where people get the solution"
Incorrect - see above.
If you just want someone to give (sic) you a solution, then you need a Consultant: http://www.keil.com/condb/
Thorsten kindly formatted your original post so others might be able to determine what was wrong with your code.
Andy gave you some sensible advice.
There is a clear fault in it your code. It may not be the problem you are seeing at the moment, but the fault is there.
I was going to tell you what that fault is, but the style of your responses make me feel that there is no point.
Your loss.
I know that my first posting of code on the forum is wrong.Go through following code.
View all questions in Keil forum