Functions

usart1.c File Reference

#include "usart1.h"

Functions

void USART_init (uint16_t baudval)
 Initialise USART and set baud rate.
void USART_transmit (uint8_t data)
void USART_transmit_string (const unsigned char *data)
 Transmit a string via USART at currently set baud rate.
void USART_transmit_uint8 (uint8_t val)
 Transmit an 8 bit unsigned integer via USART at currently set baud rate.
void USART_transmit_int8 (int8_t val)
 Transmit an 8 bit signed integer via USART at currently set baud rate.
void USART_transmit_uint16 (uint16_t val)
 Transmit a 16 bit unsigned integer via USART at currently set baud rate.
void USART_transmit_int16 (int16_t val)
 Transmit a 16 bit signed integer via USART at currently set baud rate.
void USART_transmit_bin (uint8_t val)
 Transmit an 8 bit unsigned integer as eight ASCII characters 0 or 1.
void USART_transmit_nibble (uint8_t nibble)
 Transmit the lowest 4 bits of an 8 bit unsigned integer as a single ASCII character 0-9 or A-F.
void USART_transmit_hex (uint8_t val)
uint8_t USART_receive (void)
 Receive an 8 bit value from the USART by polling.
void USART_flush (void)
 Repeatedly receive and discard values received by the USART until the input buffer empties.

Function Documentation

void USART_flush ( void   ) 

Repeatedly receive and discard values received by the USART until the input buffer empties.

Uses polling.

Note that in the event of continuous input, this function may never complete.

void USART_init ( uint16_t  baudval  )  [inline]

Initialise USART and set baud rate.

Parameters:
baudval Value to put in UBRR to selectbaud rate.

Initialise USART on microcontrollers where there is a single USART which doesn't use the newer register and bit position names which include a USART number

The baudval parameter will depend on the CPU clock frequency see the tables in the microcontroller documentation for suitable values

Clears any existing transmissions, turns off double speed, enables transmitter and receiver.

Note that this initialisation DOESN'T enable the interrupts Rx complete and Tx Complete

uint8_t USART_receive ( void   ) 

Receive an 8 bit value from the USART by polling.

Returns:
value Value received.

Uses polling, so waits for receive buffer to fill before returning.

void USART_transmit ( uint8_t  data  ) 
void USART_transmit_bin ( uint8_t  val  ) 

Transmit an 8 bit unsigned integer as eight ASCII characters 0 or 1.

Parameters:
val Value to transmit.

Transmit an 8 bit unsigned integer as eight ASCII characters 0 or 1.

Doesn't interrupt any existing transmit already in progress.

Uses polling, so waits for transmit buffer to be empty before appending new characters

void USART_transmit_hex ( uint8_t  val  ) 
void USART_transmit_int16 ( int16_t  val  ) 

Transmit a 16 bit signed integer via USART at currently set baud rate.

Parameters:
val value to transmit.

Transmit a 16 bit signed integer via the USART, as an optional minus sign followed by up to five decimal characters, using polling, not interrutps. Doesn't output leading zeroes, so number of characters transmitted may vary. Doesn't interrupt any existing transmit already in progress.

Uses polling, so waits for transmit buffer to be empty before appending new characters

void USART_transmit_int8 ( int8_t  val  ) 

Transmit an 8 bit signed integer via USART at currently set baud rate.

Parameters:
val Value to transmit.

Transmit an 8 bit signed integer via the USART, as an optional minus sign followed by up to three decimal characters, using polling, not interrutps. Doesn't output leading zeroes, so number of characters transmitted may vary. Doesn't interrupt any existing transmit already in progress.

Uses polling, so waits for transmit buffer to be empty before appending new characters

void USART_transmit_nibble ( uint8_t  nibble  ) 

Transmit the lowest 4 bits of an 8 bit unsigned integer as a single ASCII character 0-9 or A-F.

Parameters:
nibble Value to transmit.

Doesn't interrupt any existing transmit already in progress.

Uses polling, so waits for transmit buffer to be empty before appending new characters

void USART_transmit_string ( const unsigned char *  data  ) 

Transmit a string via USART at currently set baud rate.

Parameters:
data Pointer to start of string.

Transmit a string via the USART, using polling, not interrutps. Doesn't change baud rate. Doesn't interrupt any existing transmit already in progress.

Uses polling, so waits for transmit buffer to be empty

void USART_transmit_uint16 ( uint16_t  val  ) 

Transmit a 16 bit unsigned integer via USART at currently set baud rate.

Parameters:
val Value to transmit.

Transmit a 16 bit unsigned integer via the USART, as a series of up to five decimal characters, using polling, not interrutps. Doesn't output leading zeroes, so number of characters transmitted may vary. Doesn't interrupt any existing transmit already in progress.

Uses polling, so waits for transmit buffer to be empty before appending new characters

void USART_transmit_uint8 ( uint8_t  val  ) 

Transmit an 8 bit unsigned integer via USART at currently set baud rate.

Parameters:
val Character to transmit.

Transmit an 8 bit unsigned integer via the USART, as a series of up to three decimal characters, using polling, not interrutps. Doesn't output leading zeroes, so number of characters transmitted may vary. Doesn't interrupt any existing transmit already in progress.

Uses polling, so waits for transmit buffer to be empty before appending new characters