USART Char Send problem

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)); } }

Parents
  • 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.

Reply
  • 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.

Children
More questions in this forum