at90swuart - Software UART for AVR like AltSoftSerial or NeoICSerial without Arduino layer for AT90USB128

1 post / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

# at90swuart
Software UART for AVR like AltSoftSerial or NeoICSerial without Arduino layer

Currently only AT90USB128X and ATMEGA328P is supported (uncomment USE_ARDUINO_UNO define)

You can adapt this library for your AVR with a few changes (look below)

 

This is the official post to ask about this project, feedback is always welcome.

 

This library is like AltSoftSerial: 
- Can simultaneously transmit and receive. Minimal interference with simultaneous use of HardwareSerial and other libraries
- Consumes a 16 bit timer (and will not work with any libraries which need that timer) and disables some PWM pins
- Its possible to switch between TIMER1 and TIMER3 with a simple #define
- Can be sensitive to interrupt usage by other libraries
- Capable of running up to 31250 baud on 16 MHz AVR. Slower baud rates are recommended when other code may delay library's interrupt response
- More info about Interrupt Latency Requirements,  Timer Usage, Usable Speed: https://www.pjrc.com/teensy/td_l...

 

**WARNING**: this library is more simple and small than AltSoftSerial/NeoICSerial. RX bytes is not stored in a internal ring buffer. If you dont want loss RX bytes just keep calling SWU_RxByte quickly or use SWU_RegisterRxCb function to handle your our ring buffer (look the main.c example)

 

Compiled and tested in: 
- Microchip Atmel Studio 

 

Default values:
- TIMER1
- BAUD 9600
- F_CPU 16000000L

 

This class can only use one predefined Input Capture pin

 

Each MCU and board has a pre-determined pin:

 

pin_table

 

 

## Files ready to flash in 16mhz AT90USB128x (rpk2, Teensy++ 2.0 ..)

### TIMER1
- https://github.com/therealdreg/a...
- https://github.com/therealdreg/a...

 

### TIMER3
- https://github.com/therealdreg/a...
- https://github.com/therealdreg/a...

 

## Files ready to flash in 16mhz ATMEGA328P (Arduino UNO ..) 

- https://github.com/therealdreg/a...
- https://github.com/therealdreg/a...

 

## Adapt this library for your AVR

You can adapt this library for your AVR with a few changes:

 

### Change default TIMER1 to TIMER3

Edit at90swuart.h and comment #define SWUSE_TIMER1 1

 

### Change BAUD 

Edit at90swuart.h and modify #define BAUDRATE    9600

 

### Change CPU speed

Edit at90swuart.h and modify #define F_CPU   16000000L

 

### Adapt your own AVR PORTs

Edit at90swuart.h and modify:
- #define SWU_DDR     DDRB
- #define SWU_PORT    PORTB
- #define SWU_PIN     PIND
- #define SWU_RX      PD4
- #define SWU_TX      PB5

 

Example for **ARDUINO UNO** (Atmega328p):

- #define SWU_DDR        DDRB
- #define SWU_PORT        PORTB
- #define SWU_PIN        PINB
- #define SWU_RX        PB0
- #define SWU_TX        PB1

And done! this is all the work necessary for ARDUINO UNO. Just change MCU device from AT90USB1287 to Atmega328p in Microchip Atmel Studio and compile the project.

 

### Adapt other stuff like AVR TIMERS etc

Just take a look to:

- https://github.com/PaulStoffrege...
- https://github.com/PaulStoffrege...
- https://github.com/PaulStoffrege...
- https://github.com/PaulStoffrege...

Now you know what TIMERS, registers etc are used in your AVR board.

Just make a the necessary changes to: at90swuart.c and at90swuart.h

 

### IDE and Make supported 

Currently only Microchip Atmel Studio is supported

 

 

## Other UART Software resources

- https://www.avrfreaks.net/index....

- https://www.avrfreaks.net/index....

- https://www.avrfreaks.net/index....

- https://www.avrfreaks.net/index....

- https://www.avrfreaks.net/index....

- https://www.avrfreaks.net/index....

- https://www.avrfreaks.net/index....

- https://www.avrfreaks.net/index....

- https://www.avrfreaks.net/index....

- http://www.atmel.com/Images/avr3...

- https://github.com/SlashDevin/Ne...

- https://github.com/SlashDevin/Ne...

 

## Credits

 

A second UART in software by P. Dannegger danni@specs.de
- https://community.atmel.com/proj...

 

AVR_SWUART by kiki (eziya)
- https://github.com/eziya/AVR_SWUART
- https://blog.naver.com/eziya76/2...

 

AltSoftSerial
- https://www.pjrc.com/teensy/td_l...

 

NeoICSerial
- https://github.com/SlashDevin/Ne...

 

## CHANGELOG

v2 03-12-2021:
- Arduino IDE support
- convert FDEV_SETUP_STREAM macro to fdev_setup_stream for Arduino C++ compatibility
- new define: DISABLE_FDEV_SETP to disable fdev_setup_stream for soft_uart and soft_uart_echo
- added rx-callback mechanism for TIMER3 
- addex .hex and .elf versions for TIMER3
- Arduino UNO (atmega328p) is officially supported just uncomment USE_ARDUINO_UNO define

 

v1 28-11-2021:
- MIT License
- support for AT90USB128x: rpk2, Teensy++ 2.0, AT90USBKEY ...
- support TIMER1 and TIMER3. ts possible to switch between TIMER1 and TIMER3 with a simple #define
- RX callback SWU_RegisterRxCb, like NeoICSerial
- RX echo support: SWU_RxByte_echo, SWU_RxByte_echo_isprint, SWU_RxByte_echo_isprint_nl, SWU_RxBuffer_echo
- FDEV_SETUP_STREAM support, now you can use printf, scanf, fprintf ...
- main example using all features
 

 

Official repository: https://github.com/therealdreg/at90swuart

 

Attached v2!

Attachment(s): 

Last Edited: Fri. Dec 3, 2021 - 08:38 AM