STM32 VL DISCOVERY - USART HABERLEŞMESİ TX YouTube Videom
STM32 VL DISCOVERY - USART HABERLEŞMESİ RX YouTube Videom ve KODLARI
#include "stm32f10x.h" #include "delay.h" #include "stdio.h" int i=0; char str[50]; uint16_t data=0; void USART_Puts(USART_TypeDef* USARTx , volatile char *s) { while(*s) { while(!(USARTx -> SR & 0x00000040)); USART_SendData(USARTx, *s); *s++; } } void all_init() { GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE); GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; // USART1 TX GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; GPIO_Init(GPIOC, &GPIO_InitStructure); USART_InitStructure.USART_BaudRate = 9600; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx; USART_InitStructure.USART_Parity = USART_Parity_No; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_Init(USART1, &USART_InitStructure); USART_Cmd(USART1,ENABLE); } int main() { delay_init(); all_init(); sprintf(str,"\f"); while(1) { data=USART_ReceiveData(USART1); if(data=='1') { GPIO_SetBits(GPIOC,GPIO_Pin_8); } if(data=='0') { GPIO_ResetBits(GPIOC,GPIO_Pin_8); } delay_ms(50); } }
Hiç yorum yok:
Yorum Gönder