Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

understanding the logic of the operation bellow

Status
Not open for further replies.

yefj

Advanced Member level 5
Advanced Member level 5
Joined
Sep 12, 2019
Messages
1,505
Helped
1
Reputation
2
Reaction score
5
Trophy points
38
Activity points
9,114
Hello, for my EFM32LG controller i have a line shown bellow.From the reference table shown in the end we see the sub properties of STATUS
also i know that <<6 mean multiply by 2^6
What is the logic of this line?
Thanks.

Code:
USART1->STATUS & (1 << 6)

Code:
if(USART1->STATUS & (1 << 7)) {   // if RX buffer contains valid data
      rx_char = USART1->RXDATA;       // store the data
    }
    if(rx_char) {                     // if we have a valid character
      if(USART1->STATUS & (1 << 6)) { // check if TX buffer is empty
        USART1->TXDATA = rx_char;     // echo received char
        rx_char = 0;                  // reset temp variable
      }
    }
1594030680656.png
 

USART1->STATUS & (1 << 6)
It means what USART1 is pointing to, presumably the address of a register in the MCU, is logic ANDed with the value 0b00100000.
The (1 <<6) notation is rather pointless, it just means a number where a '1' has been shifted six places to the left. It is more normally used like (1 << BitName) so the program is more understandable. For example, using the table in your post you could write (1 << TXBL).

Brian.
 

    yefj

    Points: 2
    Helpful Answer Positive Rating
It's common method to define bit masks in C.

You won't write this low level code because the respective bit masks are already defined in Simplicity Studio include files.

Code C - [expand]
1
2
#define USART_STATUS_TXBL            (0x1UL << 6)                               /**< TX Buffer Level */
#define _USART_STATUS_TXBL_MASK      0x40UL                                     /**< Bit mask for USART_TXBL */

 

    yefj

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top