ESTE: UART - Serial Communication

De MediaWiki do Campus São José
Ir para navegação Ir para pesquisar

This experiment is part of this project.

Here we are going to do an experiment to implement a real aplication with UART. The exercise proposed here is to implement a communication between two boards, namelly two Arduinos Uno. A led on the second arduino(slave board) will blink according to the data received from the first arduino(master board). Therefore we need to programm to types of code: one for the master(sender) board and one for the slave board(receiver). In order to understand all the concepts used in this experiment it is recommended to see at first the basic UART script.

Pseudo code

Let's begin with a solution. The pseudo code of the master an slave boards, respectively, is below:

//master  - sender
int main(void) {
   int num;
   baud_rate = 9600;
   while(1) {
        num = 0;
        println(num);
        delay_2000_ms();
        num = 1;
        println(num);
        delay_2000_ms();
    }
    return 0 ;
}
//slave - receiver
int main(void) {
   int byte_received = 0;
   int baud_rate = 9600;
   int led;
   while(1) {
       if (data_input_field > 0 ) {
           byte_received = read_data_on_input_field();
       }
       led = byte_received;
   }
   return 0;    
}

The master pseudo-code always varies a value to be send via the serial port. The slave pseudo-code has a comparison statement to check if the data_input_field is already filled and, if so, we know a data has been sent from the serial port and then the receiver board stores the data on the memory board and turns the led on or off according to the byte_received.

Schematic

Fig. 1 Schematic of the circuit for the AVR microcontroller
Fig. 1.1 Schematic of the circuit for the Arduino IDE

Part List

  • 1 LED
  • 2 Arduinos UNO
  • 1 220 ohm resistor
  • 1 Protoboard
  • 1 9V Batery (just for the Arduino IDE circuit)
  • 6 copper wires (tinned) or jumpers


Assembly

Fig. 2 Assembly of the circuit for the AVR microcontroller
Fig. 2.1 Assembly of the circuit for the Arduino IDE

Solutions

Tools

References