C Programming. Implement a function called initialise_uart which initialises the UART hardware to…

C Programming.

Implement a function called initialise_uart which initialises the UART hardware to enable serial communication with another device.

Your task is to implement the function, following the detailed specification laid out in comments in the program skeleton below. The UART must be set up with the following parameters.

  • Baud rate: 1200 bits per second.
  • UART mode: Asynchronous double speed.
  • Character size: 8 bits.
  • Parity: no parity.
  • Stop: 1 stop bit

Notes

  • Use this test driver to implement your function on a device prior to submission.
    • The test driver is hosted in TinkerCad at https://www.tinkercad.com/things/h5NjagqvPQR .
    • The TinkerCad circuit uses two Arduino Uno devices, so you will need to add a copy of the test driver source code to each of the devices for the driver to work properly.
    • It is also suggested that you make is_positive = 1 in Device 1, and is_positive = 0 in Device 2, to verify that distinct byte sequences are transmitted between devices.

_______________________________________________________________________________________________

#include

// (a) Implement a function called initialise_uart which requires no arguments and
// returns no value.
// (a.a) Set the data transmission rate to 1200 bits per second,
// using the formula provided in the lecture notes and slides. This depends
// on the UART operating mode, baud rate, and CPU clock speed.

// (a.b) Set the UART operating mode to double speed.

// (a.c) Enable receive and transmit, but do not enable any UART-related
// interrupts.

// (a.d) Set the character size to 8 bits, with no parity
// and 1 stop bit.

// (b) End of function initialise_uart

/*
***************************************************************************
** Send one byte, protecting against overrun in the transmit buffer.
**
** Param: data – a byte to be transmitted.
**
** Returns: Nothing.
***************************************************************************
*/
void uart_putbyte(unsigned char data) {
// Wait for empty transmit buffer
while (!(UCSR0A & (1 << UDRE0)));

// Send data by assigning into UDR0
UDR0 = data;
}

/*
***************************************************************************
** Attempt to receive one byte, returning immediately to sender.
**
** Param: buffer – the address of a byte in which a result may be stored.
**
** Returns: If a byte is available returns 1 and stores the incoming byte in
** location referenced by buffer. Otherwise returns 0 and makes no other
** change to the state.
***************************************************************************
*/
int uart_getbyte(unsigned char *buffer) {
// If receive buffer contains data…
if (UCSR0A & (1 << RXC0)) {
// Copy received byte from UDR0 into memory location (*buffer)
*buffer = UDR0;
//
return 1;
}
else {
return 0;
}
}

/*
***************************************************************************
** Initialise LEDS to display byte values as “binary”.
***************************************************************************
*/
void setup_leds(void) {
// Use pins 2, 3, 4, 5, 6, 7 of port D and pins 0, 1 of port B as output.
DDRD |= ~3;
DDRB |= 3;
}

/*
***************************************************************************
** Display value of a byte via LED.
**
** Param: value – a byte to display.
**
** Side effects: The LEDs connected to pins 0, 1 of Port B and 2,…,7 of
** port D are illuminated (or otherwise) to display the binary
** representation of the argument.
***************************************************************************
*/
void display(unsigned char value) {
// Pins 2, 3, 4, 5, 6, 7 of port D are bits 2,…,7 of the argument.
// Pins 0, 1 of port B are bits 0, 1 of the argument.
PORTD = (PORTD & 3) | (value & ~3);
PORTB = (PORTB & ~3) | (value & 3);
}

/*
***************************************************************************
** Implement main event loop.
***************************************************************************
*/
void process() {
// One device sends +counter, the other sends -counter.
// Both display the value received from the other.
const int is_positive = 1;

// Private variable which keeps its value between function calls.
static unsigned char counter = 0;

if (is_positive) {
uart_putbyte(counter);
}
else {
uart_putbyte(256-counter);
}
counter++;

unsigned char received_byte;

if (uart_getbyte(&received_byte)) {
display(received_byte);
}

_delay_ms(300);
}

int main(void) {
setup_leds();
initialise_uart();

while (1) {
process();
}
}

Place your order
(550 words)

Approximate price: $22

Calculate the price of your order

550 words
We'll send you the first draft for approval by September 11, 2018 at 10:52 AM
Total price:
$26
The price is based on these factors:
Academic level
Number of pages
Urgency
Basic features
  • Free title page and bibliography
  • Unlimited revisions
  • Plagiarism-free guarantee
  • Money-back guarantee
  • 24/7 support
On-demand options
  • Writer’s samples
  • Part-by-part delivery
  • Overnight delivery
  • Copies of used sources
  • Expert Proofreading
Paper format
  • 275 words per page
  • 12 pt Arial/Times New Roman
  • Double line spacing
  • Any citation style (APA, MLA, Chicago/Turabian, Harvard)

Our guarantees

Delivering a high-quality product at a reasonable price is not enough anymore.
That’s why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.

Money-back guarantee

You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.

Read more

Zero-plagiarism guarantee

Each paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.

Read more

Free-revision policy

Thanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.

Read more

Privacy policy

Your email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.

Read more

Fair-cooperation guarantee

By sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.

Read more
error: Content is protected !!