1. /*
  2. * Author: Niklas Menke - https://www.niklas-menke.de/ (GE)
  3. * Description: This library uses the USI (Universal Serial Interface) to provide a UART. Also there are some supportive routines.
  4. *
  5. * File: usi-uart.h
  6. * Description: Functions declaration
  7. * Microcontroller: Attiny861A@8MHz; No other microcontrollers were tested
  8. * Date (created): Mar 10, 2021
  9. *
  10. * Version (Hardware): -
  11. * Version (Software): 1.0.0
  12. * Date (updated): -
  13. * Change log: -
  14. * ToDo: - (Ideas or Problems? --> https://www.niklas-menke.de/kontakt/ (GE))
  15. *
  16. *
  17. * WARNING!: This code was only test with the Attiny861A controller and a CPU frequency of 8MHz. Support is not guaranteed for other conditions!
  18. * To get a CPU frequency of 8MHz, you have to clear the clock divider fuse (LOW.CKDIV8).
  19. */
  20.  
  21.  
  22. #ifndef USI_UART_H_
  23. #define USI_UART_H_
  24.  
  25.  
  26. #include <avr/io.h>
  27. #include <avr/interrupt.h>
  28.  
  29.  
  30. void uart_listen(void); // Monitor DI pin for incoming bytes
  31. void uart_stop(void); // Stop monitoring DI pin for incoming bytes
  32.  
  33. uint16_t uart_getBaudrate(void); // Return baud rate from the pin header
  34. void uart_TimerConfig(void); // Calculate timer setpoint and prescaler
  35.  
  36. void uart_receive(void); // Receive one byte
  37. void uart_transmit(const uint8_t byte); // Transmit one byte
  38. void uart_transmitArray(const uint8_t *byte, const uint8_t length); // Transmit an array of bytes
  39.  
  40. uint8_t uart_available(void); // Return number of received bytes in buffer
  41. uint8_t uart_readByte(void); // Return first byte from buffer without delete them from buffer
  42. uint8_t uart_getByte(void); // Return first byte from buffer and delete them from buffer
  43. void uart_delete(void); // Clear buffer
  44.  
  45. uint8_t rev_byte(uint8_t rbyte); // Reverse bits of a byte
  46.  
  47.  
  48. #endif /* USI_UART_H_ */