This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GPIO_InitStruct.GPIO_PIN = GPIO_Pin_9; | |
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz; | |
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP; | |
GPIO_Init(GPIOA , &GPIO_InitStruct); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
main() | |
{ | |
// configure button | |
// configure led | |
while (1) | |
{ | |
if (read(button)) | |
led = on; | |
else | |
led = off; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
USART_FLAG_TXE -- Transmit data register empty | |
USART_FLAG_RXNE -- Receive data register not empty |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int putchar(int c) { | |
while (USART_GetFlagStatus(USART1 , USART_FLAG_TXE) == RESET); | |
USART1 ->DR = (c & 0xff); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int getchar(void) { | |
while (USART_GetFlagStatus(USART1 , USART_FLAG_RXNE) == RESET); | |
return USART1 ->DR & 0xff; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stm32f10x.h> | |
#include <stm32f10x_gpio.h> | |
#include <stm32f10x_rcc.h> | |
#include <stm32f10x_usart.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | | |
RCC_APB2Periph_AFIO | | |
RCC_APB2Periph_GPIOA , ENABLE); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GPIO_InitTypeDef GPIO_InitStruct; | |
GPIO_StructInit (& GPIO_InitStruct); | |
// Initialize USART1_Tx | |
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_9; | |
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz; | |
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP; | |
GPIO_Init(GPIOA , &GPIO_InitStruct); | |
// Initialize USART1_RX | |
GPIO_InitStruct.GPIO_PIN = GPIO_Pin_10; | |
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// see stm32f10x_usart.h | |
USART_InitTypeDef USART_InitStructure; | |
// Initialize USART structure | |
USART_StructInit (& USART_InitStructure); | |
// Modify USART_InitStructure for non -default values , e.g. | |
// USART_InitStructure.USART_BaudRate = 38400; | |
USART_InitStructure.USART_BaudRate = 9600; | |
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; | |
USART_Init(USART1 ,& USART_InitStructure); | |
USART_Cmd(USART1 , ENABLE); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int uart_open(USART_TypeDef* USARTx , uint32_t baud , uint32_t flags); | |
int uart_close(USART_TypeDef* USARTx); | |
int uart_putc(int c, USART_TypeDef* USARTx); | |
int uart_getc(USART_TypeDef* USARTx); |