Why I am not receive data with UART and without HAL?

0

I am using a stm32f407vg board. I am writing the program on atolic true. In addition, I use D-SUN USB TLL. I also use Termite to see the Data Receive and Send screen.

When I send a 1 or 0 on the termite, I can't get out of port B. But if I want to send data ("HelloGuys"), it works fine. What could be the reason for you?

 /* --------------------------- System Libraries --------------------------------------*/
 #include "stm32f4xx.h"
 #include "stm32f4_discovery.h"

 /* --------------------------- STRUCTURES--------------------------------------------*/
 GPIO_InitTypeDef       GPIO_InitStruct;
 USART_InitTypeDef      UART_InitStruct;
 NVIC_InitTypeDef       NVIC_InitStructure;

 /* --------------------------- Variables --------------------------------------------*/

 static char test[25] = "HelloGuys \r\n";
 static uint16_t  data = 0;



 /* --------------------------- System Clocks Configuration ---------------------------*/
 void RCC_Configuration()
 {
/* GPIOC clock enable */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC,ENABLE);
/* USART3 clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3,ENABLE);
/*LED clock enable */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB,ENABLE);
 }



 /* --------------------------- GPIO Configuration -----------------------------------*/
 void  GPIO_Config1(){

//UART 3 ___PC10 TX___PC11 RX

//TX Configure
GPIO_InitStruct.GPIO_Mode       =GPIO_Mode_AF;
GPIO_InitStruct.GPIO_OType      =GPIO_OType_PP;
GPIO_InitStruct.GPIO_Pin        =GPIO_Pin_10;
GPIO_Init(GPIOC,&GPIO_InitStruct);

//RX Configure
GPIO_InitStruct.GPIO_Mode       =GPIO_Mode_IN;
GPIO_InitStruct.GPIO_OType      =GPIO_OType_PP;
GPIO_InitStruct.GPIO_PuPd       =GPIO_PuPd_NOPULL;
GPIO_InitStruct.GPIO_Pin        =GPIO_Pin_11;
GPIO_Init(GPIOC,&GPIO_InitStruct);

/* Connect USART pins to AF */
GPIO_PinAFConfig(GPIOC, GPIO_PinSource10, GPIO_AF_USART3);
GPIO_PinAFConfig(GPIOC, GPIO_PinSource11, GPIO_AF_USART3);


//LED
GPIO_InitStruct.GPIO_Mode       =GPIO_Mode_OUT;
GPIO_InitStruct.GPIO_Pin        =GPIO_Pin_0;
GPIO_InitStruct.GPIO_Speed      =GPIO_Speed_25MHz;
GPIO_Init(GPIOB,&GPIO_InitStruct);


 }



 /* --------------------------- USART Configuration ----------------------------------*/

 void USART_Config1(){

UART_InitStruct.USART_BaudRate              =9600;
UART_InitStruct.USART_HardwareFlowControl   =USART_HardwareFlowControl_None;
UART_InitStruct.USART_Mode                  =USART_Mode_Rx | USART_Mode_Tx;
UART_InitStruct.USART_Parity                =USART_Parity_No;
UART_InitStruct.USART_StopBits              =USART_StopBits_1;
UART_InitStruct.USART_WordLength            =USART_WordLength_8b;

USART_Init(USART3, &UART_InitStruct);
USART_Cmd(USART3,ENABLE);


 }



 //--------------------------- DATA_STRING SETTING -----------------------------------/

 void Send_String_Data(char *str){

while(*str)
{
    
    while(! (USART3->SR & 0x00000040));
    USART_SendData(USART3,*str);
    str++;


}
 }


 /**************************************************************************************/

 int main(void)
 {  
SystemInit();
RCC_Configuration();
GPIO_Config1();
USART_Config1();
  while (1)
   {
   //Send_String_Data(test);

  data = USART_ReceiveData(USART3);


  if(data=='1') {
     GPIO_SetBits(GPIOB,GPIO_Pin_0);
  }
  if(data=='0') {
      GPIO_ResetBits(GPIOB,GPIO_Pin_0);
      }
   }
 }
stm32f4discovery
usart
asked on Stack Overflow Jan 9, 2021 by Emre Gülmez

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0