[STM32 Cotex-M3 processor series programming] serial port debugging

Publisher:LogicLeaperLatest update time:2015-09-22 Source: eefocusKeywords:STM32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
#include "stm32f10x.h"
//#include "stm32f10x_lib.h"
 
void Delay(unsigned int x);
void UART_Init(void);
 
int main(void)
 
  
  
  while (1)
  {
    Delay(300000);
    UART_Init();    //Initialize the serial port
    USART_SendData(USART1,0x1A);    //Send data from the serial port to the computer
    while(USART_GetFlagStatus(USART1,USART_FLAG_TXE)==RESET); //RESET is 0, waiting for sending to complete
   // if(USART_GetFlagStatus(USART1,USART_FLAG_TC)==RESET)
    GPIO_SetBits(GPIOC, GPIO_Pin_6 );    //Light up the D1 diode after sending.
 
   }
}
 
 
void UART_Init(void)
{
  SystemInit(); //Configure system clock
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE | RCC_APB2Periph_USART1,ENABLE); //IO port enable setting
  GPIO_InitTypeDef GPIO_InitStructure;    //Define I/O port structure
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3;   
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(GPIOA, &GPIO_InitStructure);
  
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
  GPIO_Init(GPIOC, &GPIO_InitStructure);
  
  USART_InitTypeDef USART_InitStructure; //Define the serial port structure
  //RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); //Enable serial port 1
  USART_InitStructure.USART_BaudRate=38400;
  USART_InitStructure.USART_WordLength=USART_WordLength_8b;
  USART_InitStructure.USART_StopBits=USART_StopBits_1;
  USART_InitStructure.USART_Parity=USART_Parity_No;
  USART_InitStructure.USART_HardwareFlowControl=USART_HardwareFlowControl_None;
  USART_InitStructure.USART_Mode=USART_Mode_Rx | USART_Mode_Tx;
  USART_Init(USART1,&USART_InitStructure);
  USART_Cmd(USART1,ENABLE);
}
 
 
 
void Delay(unsigned int x)
{
unsigned int t;
t=x;
while(t--);
}
Keywords:STM32 Reference address:[STM32 Cotex-M3 processor series programming] serial port debugging

Previous article:[STM32 Cotex-M3 processor series programming] Timer output PWM wave
Next article:[STM32 Cotex-M3 processor series programming] Button light is on

Recommended ReadingLatest update time:2024-11-16 14:28

stm32 --- Flexible static memory controller FSMC
All external memories share the address, data and control signals output by the controller, and each external device can be distinguished by a unique chip select signal. The FSMC only accesses one external device at any one time. Devices with static memory interfaces include: 1.   Static random access memory (SRAM)
[Microcontroller]
STM32 key interrupt learning record
I am used to searching the Internet when I encounter problems in debugging programs. I can often get inspiration from the records or replies of experts. I didn’t expect that one day I would start writing a blog to record my learning bits and pieces. The month of learning STM32 was a bit like working in isolation, beca
[Microcontroller]
STM32 study notes: Bootloader upgrade Ymodem protocol introduction
YModem Protocol The YModem protocol evolved from the XModem protocol. Each data packet can reach 1024 bytes and is a very efficient file transfer protocol. Source code macro definition #define SOH (0x01) /* start of 128-byte data packet / #define STX (0x02) / start of 1024-byte data packet / #define EOT (0x04) / end
[Microcontroller]
STM32 study notes: Bootloader upgrade Ymodem protocol introduction
STM32 drives ST7920's 12864 LCD (serial mode)
/********************************************************************************************** * File name: 12864.c * Copyright: * Module name: Serial working mode driver program of 12864 LCD driven by st7920 * cpu: stm32f103rct6 Main frequency: 72M * Author: * Creation date: 2009-10-15 * Function summary: *---------
[Microcontroller]
Analysis of TCP/IP protocol stack code ARP (STM32 platform)
1. Introduction to ARP Address Resolution Protocol ARP provides dynamic mapping between IP addresses and corresponding hardware addresses. A translation is required from the logical Internet address to the corresponding physical hardware address. This is the function of ARP. The function of ARP is to provide dynamic m
[Microcontroller]
Analysis of TCP/IP protocol stack code ARP (STM32 platform)
STM32 learning EXTI
EXTI has two functions: one is to generate an interrupt, the purpose is to pass the input signal to NVIC, further run the interrupt service function, realize the function, at the software level; the other is to generate an event, the purpose is to generate a pulse signal for other peripherals to use, this is the circu
[Microcontroller]
Design of wireless communication terminal system based on STM32
       1. Introduction   Currently, most instruments and equipment use RS232 interfaces to communicate with computers. However, with the development of computer technology, the hot-swappable USB standard interface will replace the RS232 interface. Therefore, computers will be less and less equipped with RS232 interf
[Microcontroller]
Design of wireless communication terminal system based on STM32
STM32 MCU GPIO register
Each GPIO port has two 32-bit configuration registers (GPIOx_CRL, GPIOx_CRH) to control the high and low eight bits of each port respectively. If the IO port is 0-7, write the CRL register, if the IO port is 8-15, write the CRH register, two 32-bit data registers (GPIOx_IDR, GPIOx_ODR), one is read-only as input dat
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号