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)); } }
main.h:
#ifndef __main_h__ #define __main_h__ /* Clock Definitions */ #define CPU_CLOCK 72000000 // CPU Clock #define TICKS_ONE_MS CPU_CLOCK/7400 // approp. one millisecond // Bit_on, bit_off definitions #define bit_on(BYTE, BIT) { BYTE |= 1 << BIT; } #define bit_off(BYTE, BIT) { BYTE &= ~(1 << BIT); } // TRUE/FALSE #define TRUE 1 #define FALSE 0 // prototypes void delay_ms(int ms); #endif
gpio.h:
#ifndef __GPIO_H__ #define __GPIO_H__ // AF enable #define AFIO_EN 0 // Alternate Function Enable // GPIO enable #define IOPA_EN 2 // GPIO A enable #define IOPB_EN 3 // GPIO B enable #define IOPC_EN 4 // GPIO C enable #define IOPD_EN 5 // GPIO D enable #define IOPE_EN 6 // GPIO E enable #define IOPF_EN 7 // GPIO F enable #define IOPG_EN 8 // GPIO G enable // DAC Enable #define DAC_EN 29 #define GPIO_CONF_BIT(BIT) ((BIT>7? BIT-8 : BIT) << 2) // 4Bits per port pin // Mode and Conf Bits #define MODE0 (unsigned int)0 #define MODE1 (unsigned int)1 #define CONF0 (unsigned int)2 #define CONF1 (unsigned int)3 // Port Mode #define GPIO_MODE_INPUT (((unsigned int)0<<MODE0) | ((unsigned int)0<<MODE1)) // GPIO is input #define GPIO_SPEED_2MHZ (((unsigned int)0<<MODE0) | ((unsigned int)1<<MODE1)) // Max output Speed 2MHz #define GPIO_SPEED_10MHZ (((unsigned int)1<<MODE0) | ((unsigned int)0<<MODE1)) // Max output Speed 10MHz #define GPIO_SPEED_50MHZ (((unsigned int)1<<MODE0) | ((unsigned int)1<<MODE1)) // Max output Speed 50MHz // Port Conf #define GPIO_OUT_PUSH_PULL (((unsigned int)0<<CONF0) | ((unsigned int)0<<CONF1)) // general purpose output push-pull #define GPIO_AF_PUSHPULL (((unsigned int)0<<CONF0) | ((unsigned int)1<<CONF1)) // alternate function push-pull #define GPIO_IN_FLOATING (((unsigned int)1<<CONF0) | ((unsigned int)0<<CONF1)) // input floating #define GPIO_IN_ANALOG (((unsigned int)0<<CONF0) | ((unsigned int)0<<CONF1)) // input analog #define GPIO_IN_PULL_DOWN (((unsigned int)0<<CONF0) | ((unsigned int)1<<CONF1)) // alternate function push-pull #define GPIO_IN_PULL_UP (((unsigned int)0<<CONF0) | ((unsigned int)1<<CONF1)) // alternate function push-pull // prototypes void port0_init(void); #endif
TABs went a bit wrong :-)
There is only one certain thing about interpreting TABs: they will go wrong!
Therefore, never use TABs - especially not on an internet forum!
Set your editor for "insert spaces for TABs"
I do not use Tabs anymore, but this code is old ...