Copyright Brian Starkey 2012-2014
Valid HTML 4.01 Transitional

Valid CSS!
iconAVR USART Drivermax, min, close
This is a small driver for the AVR USART. It should work (I think) on any AVR with a USART peripheral (tested only on Attiny2313), but if you get errors about register names then colour me wrong.
The driver provides synchronous reading and writing functionality, with an optional timeout on reads. The write has a buffer, which is filled as quickly as possible to allow for non-blocking writes for messages up to the length of the buffer.
The read function utilises a 16-byte circular buffer to allow high data throughput. The code is semi-interrupt driven, making use of the the USART interrupts.
Having spent a good deal of time writing drivers since completing this one, it's clear that I could optimise this code and make it entirely interrupt driven, however who has the time!?

// Serial driver for AVR USART
// Uses 24 bytes for buffers etc
// This work is provided as-is without any warranty whatsoever
// Use it at your own risk
// Modify and redistribute at will, as long as this disclaimer remains
// (C) Brian Starkey, 2011

#define USART_MOD 1

extern const char comma PROGMEM;
extern const char newline[3] PROGMEM;

void init_usart(void);
void usart_send(char * buffer, uint8_t len);
void usart_byte(uint8_t data);
void usart_send_pmem(PGM_P data, uint8_t len);
uint8_t usart_recv(char * data, uint8_t len, uint16_t o_timeout);