STM32L0 HAL Library UART serial Read and write function

Source: Internet
Author: User

Serial Send function:

uint8_t txdata["01234abcde"; Hal_uart_transmit (&huart2,txdata,0xffff); // Send the contents of the TxData through the Uart2, the length is 10,timeout time is the maximum value 0xFFFF

Serial Reception function 1:

uint8_t value='F'; Hal_uart_receive (&huart2, (uint8_t *) &value,1,+); // in this statement stay 1000ms waiting to receive 1 bytes of data, the data stored in value

Serial Reception function 2:

Hal_uart_receive_it (&huart2, (uint8_t *) &value,1); // The program will not stay in this statement, directly according to the interrupt mode to store the received data in value, but this statement can only enable one serial port interrupt. So to re-enable in the Interrupt service function

Serial Reception function 3:

 if  (Hal_uart_receive_it (&huart2, (uint8_t *) &value,1 )! = HAL_OK) {//  This sentence is written in the while (1) of the main function Above. Used to start a program to start an interrupt receive  Hal_uart_transmit (&huart2, (uint8_t *) & " error\r\n  , 7 , 10  );  while  (1     
void Hal_uart_rxcpltcallback (Uart_handletypedef *uarthandle) {    hal_uart_transmit (&huart2, (uint8_t *) &"\r\ninto hal_uart_rxcpltcallback\r\n",0xffff);    // Verify that this function has been entered.    Hal_uart_transmit (&huart2, (uint8_t *) &value,1,0xffff); // Send the received         data through the serial port    Hal_uart_receive_it (&huart2, (uint8_t *) &value,1); // re-open serial interrupt }

Stm32l0 HAL Library UART serial Read and write function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.