2018-07-12 11:02 PM
I cannot any thing on serial terminal (PUTTY) ,here i'm using usart2 communication.I posted code below please let me know anything wrong in the code.
#include 'stm32f7xx.h' // Device header
#include<stdint.h>#include <string.h>#include <stdio.h>int rec_data();void send_data(char s);void delay();void flash_led();void PutString( uint8_t * str);int main(){// int a, n;// float b; LED_Initialize(); //flash_led(); //usart_snd_str('\n\rHello, please type something\n\r'); //reset clock reg RCC -> AHB1ENR |= RCC_AHB1ENR_GPIODEN; //reset and clock control reg ,select USART2 for APB1, pin no 18 RCC -> APB1ENR =RCC_APB1ENR_USART2EN; // mode pd8- tx and pd9 - rx GPIOA -> MODER &= ~(GPIO_MODER_MODER1_0); GPIOA -> MODER |= GPIO_MODER_MODER1_1; //alternate function A7 // GPIOA->AFR[0] |= 0x77 << (4*5); //type of gpio alternate function GPIOA -> OTYPER &= ~(GPIO_OTYPER_OT_2); GPIOA -> OTYPER &= ~(GPIO_OTYPER_OT_3); //speed GPIOA -> OSPEEDR |= GPIO_OSPEEDER_OSPEEDR1; //push pull resisitor GPIOA -> PUPDR &= ~(GPIO_PUPDR_PUPDR1); //uart_configration(); // start bit //data word length 7 , 8 and 9 //stop 2 nd 1 //baud rate 9600 //parity bits //mode USART2 -> CR1 &= ~USART_CR1_M0; USART2 -> BRR = 9600; USART2 -> CR2 &= ~(USART_CR2_STOP_1); USART2 -> CR1 &= ~(USART_CR1_OVER8); USART2 -> CR1 |= (USART_CR1_TE | USART_CR1_RE ); USART2 -> CR1 |= USART_CR1_UE; uint8_t a= 12; PutString(&a); }void PutChar(int8_t ch)
{ while(!(USART2->ISR & USART_ISR_TXE)); USART2->TDR = ch; }void PutString( uint8_t * str)
{ while(*str != 0) { PutChar( *str); str++; }}int rec_data()
{ /* Wait until the data is ready to be received. */ while (!(USART2->ISR & USART_ISR_RXNE));// read RX data, combine with DR mask (we only accept a max of 9 Bits)
return ((uint8_t)(USART2->RDR & 0xFF));}