Receive a single byte

So far we have sending data from the micro to your laptop. It’s time to try the opposite: receivingdata from your laptop.

There’s a RDR register that will be filled with the data that comes from the RX line. If we readthat register, we’ll retrieve the data that the other side of the channel sent. The question is: Howdo we know that we have received (new) data? The status register, ISR, has a bit for that purpose:RXNE. We can just busy wait on that flag.

  1. #![deny(unsafe_code)]
  2. #![no_main]
  3. #![no_std]
  4. #[allow(unused_imports)]
  5. use aux11::{entry, iprint, iprintln};
  6. #[entry]
  7. fn main() -> ! {
  8. let (usart1, mono_timer, itm) = aux11::init();
  9. loop {
  10. // Wait until there's data available
  11. while usart1.isr.read().rxne().bit_is_clear() {}
  12. // Retrieve the data
  13. let _byte = usart1.rdr.read().rdr().bits() as u8;
  14. aux11::bkpt();
  15. }
  16. }

Let’s try this program! Let it run free using continue and then type a single character inminicom/PuTTY’s console. What happens? What are the contents of the _byte variable?

  1. (gdb) continue
  2. Continuing.
  3. Program received signal SIGTRAP, Trace/breakpoint trap.
  4. 0x8003d48 in __bkpt ()
  5. (gdb) finish
  6. Run till exit from #0 0x8003d48 in __bkpt ()
  7. usart::main () at src/11-usart/src/main.rs:19
  8. 19 aux11::bkpt();
  9. (gdb) p/c _byte
  10. $1 = 97 'a'