Summary of serial data transmission STM32

Serial transmission of data STM32

1.1, to be called to initialize the serial port parameters:

  1. Instance to be called base address of the serial register chunkou.
  2. BaudRate baud rate
  3. StopBits stop bit
  4. WordLength bytes in length
  5. HwFlowCtl hardware flow, under normal circumstances, no set,
  6. Mode setting serial transmit or receive data, send or receive simultaneously.
  7. Parity The parity bit serial

These parameters are placed in serial UART_HandleTypeDef this structural body, therefore, the need to define a variable UART_HandleTypeDef. UART_HandleTypeDef   usart1_handler

 

 1.2 can be invoked so that serial, HAL_UART_Init () entry parameters of this function is a pointer variable UART_HandleTypeDef, therefore, this function is called when the direct HAL_UART_Init (& usart1_handler) on it.

 

In order not to initialize the main, you can define your own function to initialize it.

void usart1_init()

// required parameters for the serial port initialization, serial port and enable open.

void usart1_init () 

{ 

// need to initialize the serial port parameters, and the serial enable on. 



}

 

 

By the time you can call in the main function. '

 

int main () 
{ 
    usart1_init ();     // this call, then, when looking at the main function, it would be streamlined. 
}

 

 

2.1 serial quintile, RX, TX, eventually will need to be on IO port pin, therefore, we need to configure the relevant IO feet, as well as the multiplex configuration

Correlation function is HAL_UART_MspInit, which is a virtual function, need to be redefined. However, the function of the IO pin configuration is HAL_GPIO_Init () function in,

 

void HAL_UART_MspInit (UART_HandleTypeDef * HUART) 
{ 
   GPIO_InitTypeDef GPIO_Initure;                            
// HAL_GPIO_Init call to
                         // HAL_UART_MspInit this function is to be invoked in HAL_UART_Init


    
}

 

 3.1 the transmission data, and waits for completion of transmission of data

int main ( void ) 
{ 

    U8 rdates [] = " 125488xaaaff123 " ;   // this is to be transmitted 
    HAL_Init (); 
    Stm32_Clock_Init ( 360 , 25 , 2 , . 8 ); 
    delay_init ( 180 [ );             // This delay function initialization is not configured, the main function of a timely delay function is no effect, so bath to configure 
    usart1_init ();
     the while ( . 1 ) 
    { 
        HAL_UART_Transmit ( & usart1_handler, rdates, the sizeof (rdates), 1000 ); 
        Delay_ms (1000);     
    }


}

 

 

                                                                                           

 

Guess you like

Origin www.cnblogs.com/DY004/p/11443248.html