Mudanças entre as edições de "ESTE: UART - Basic Interrupts"

De MediaWiki do Campus São José
Ir para navegação Ir para pesquisar
(Criou página com 'This experiment is part of this project. Here we are going to do an experiment to implement a real ...')
 
 
(8 revisões intermediárias pelo mesmo usuário não estão sendo mostradas)
Linha 1: Linha 1:
 
This experiment is part of [[Embedded_Systems_Experiments_for_the_Telecommunication_Engineering_Course|this project]].
 
This experiment is part of [[Embedded_Systems_Experiments_for_the_Telecommunication_Engineering_Course|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.  
+
Here we are going to do an experiment to aprimorate the UART and Interrupts concepts. Until now, for our applications on UART communication we were using the "one-single-loop". This model is quite fast and hardly inserts processing or memory overhead. However, the biggest problem with this architecture is to create routines involving information reading, that generate some kind of delay, and receiving messages. One of the solutions available to solve these problems are the interruptions, that allow a predefined function to be executed whenever an event happens and so, we can program a system that responds to events and not just run their operations sequentially. Among the most common interruptions implemented that will be used in this experiment are the communication one, generated by a reception of a message/byte or when the system is available to send some information. Therefore the exercise here proposed will light up a led - activated by interruption - every time new bytes of data arrive on the serial communication port. To complete this experiment it is recommended to see at first the [http://wiki.sj.ifsc.edu.br/index.php/ESTE:_GPIO_and_External_Interrupts_-_part_1 GPIO and External Interrupts - part 1] and [http://wiki.sj.ifsc.edu.br/index.php/ESTE:_Universal_Assynchronous_Receiver_and_Transmitter_%28UART%29 UART] scripts.  
  
 
==Pseudo code==
 
==Pseudo code==
  
Let's begin with a solution. The pseudo code of the master an slave boards, respectively, is below:
+
Let's begin with a solution. The pseudo code (actual coding is up to you) is below:
  
 
<syntaxhighlight lang=c>
 
<syntaxhighlight lang=c>
//master  - sender
 
 
int main(void) {
 
int main(void) {
  int num;
+
    byte incomingByte;
  baud_rate = 9600;
+
    baud_rate = 9600;
  while(1) {
+
    while(1) {
         num = 0;
+
         led_off();
        println(num);
+
    }
        delay_2000_ms();
+
    return 0;  
         num = 1;
+
}
         println(num);
+
void serial_interrupt_event() {
         delay_2000_ms();
+
    if (data_available_on_input_field()) {
 +
         incomingByte = read_data_on_input_field();
 +
         println(incomingByte);
 +
         led_on();
 
     }
 
     }
    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;   
 
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
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.
+
This pseudo-code has a comparison statement to check if there are data available on the input field of the serial monitor, i.e serial port.  If so, the data available will be stored on the memory, printed - only  for debuging- and the led will be lighted on.
  
 
==Schematic==
 
==Schematic==
[[Arquivo:Uart_2arduinos_AVR_Esquemático_new.png|600px|thumb|center|Fig. 1 Schematic of the circuit for the AVR microcontroller]]
+
[[Arquivo:Uart_interrupt_basic_Esquemático.png|450px|thumb|center|Fig. 1 Schematic of the circuit]]
[[Arquivo:Uart_2arduinos_IDE_Esquemático_new.png|600px|thumb|center|Fig. 1.1 Schematic of the circuit for the Arduino IDE]]
 
  
 
==Part List==
 
==Part List==
 
*1 LED
 
*1 LED
*2 Arduinos UNO
+
*1 220 ohm resistor for the led
*1 220 ohm resistor
 
 
*1 Protoboard
 
*1 Protoboard
*1 9V Batery (just for the Arduino IDE circuit)
+
*2 copper wires (tinned) or jumpers
*6 copper wires (tinned) or jumpers
+
 
 
<br/>
 
<br/>
  
 
==Assembly==
 
==Assembly==
[[Arquivo:Uart_2arduinos_AVR_bb_new.png|600px|thumb|center|Fig. 2 Assembly of the circuit for the AVR microcontroller]]
+
[[Arquivo:Uart_interrupt_basic_bb.png|450px|thumb|center|Fig. 2 Assembly of the circuit]]
[[Arquivo:Uart_2arduinos_IDE_bb.png|600px|thumb|center|Fig. 2.1 Assembly of the circuit for the Arduino IDE]]
 
  
 
==Solutions==
 
==Solutions==
*[https://drive.google.com/open?id=0B_chZ-d1CkpCSjdjeTB5T2RDM1E C - AVR (master)]
+
*[https://drive.google.com/open?id=0B_chZ-d1CkpCSnFlWUFzNGlIbVE C - AVR]
*[https://drive.google.com/open?id=0B_chZ-d1CkpCc0hhNU5HWUpIbUk Arduino UNO (master)]
+
*[https://drive.google.com/open?id=0B_chZ-d1CkpCX01oeDBCVE9SSjQ Arduino UNO]
*[https://drive.google.com/open?id=0B_chZ-d1CkpCaklFN2xwQXRUWlk C - AVR (slave)]
 
*[https://drive.google.com/open?id=0B_chZ-d1CkpCdlhmYkpNZHhDUXc Arduino UNO (slave)]
 
  
 
==Tools==
 
==Tools==
Linha 67: Linha 50:
  
 
==References==
 
==References==
*[http://lab.guilhermemartins.net/2008/12/24/serial-comunication-between-arduinos-with-wire-wireless/ Serial Comunication between Arduinos]
+
*[http://www.embarcados.com.br/arquitetura-de-desenvolvimento-de-software-ii/ Embarcados: Arquitetura de desenvolvimento de software]
*[http://arduinizando.blogspot.com.br/2013/02/comunicacao-serial-entre-arduinos.html Arduinizando: Comunicação serial entre arduinos]
+
*[https://www.youtube.com/watch?v=Ih-wJGpFjqs Video Tutorial: UART Between the AVR Microcontroller and Computer ]
*[http://harduino.me/2013/11/30/comunicacao-serial-entre-dois-arduinos/ Harduino: Comunicação Serial Entre Dois Arduinos]
+
*[http://deans-avr-tutorials.googlecode.com/svn/trunk/InterruptUSART/Output/InterruptUSART.pdf Deans AVR Tutorials: Interrupt Driven USART in AVR-GCC]
*[https://www.youtube.com/watch?v=U1kr9gYviMc Video Tutorial: Microcontroller - AVR ATmega32 - One Way UART Communication with Two Chips]
+
*[http://www.kanda.com/AVR-C-Code-UART.php Kanda: AVR UART Code]

Edição atual tal como às 09h11min de 15 de outubro de 2015

This experiment is part of this project.

Here we are going to do an experiment to aprimorate the UART and Interrupts concepts. Until now, for our applications on UART communication we were using the "one-single-loop". This model is quite fast and hardly inserts processing or memory overhead. However, the biggest problem with this architecture is to create routines involving information reading, that generate some kind of delay, and receiving messages. One of the solutions available to solve these problems are the interruptions, that allow a predefined function to be executed whenever an event happens and so, we can program a system that responds to events and not just run their operations sequentially. Among the most common interruptions implemented that will be used in this experiment are the communication one, generated by a reception of a message/byte or when the system is available to send some information. Therefore the exercise here proposed will light up a led - activated by interruption - every time new bytes of data arrive on the serial communication port. To complete this experiment it is recommended to see at first the GPIO and External Interrupts - part 1 and UART scripts.

Pseudo code

Let's begin with a solution. The pseudo code (actual coding is up to you) is below:

int main(void) {
    byte incomingByte;
    baud_rate = 9600;
    while(1) {
        led_off();
    }
    return 0;    
}
void serial_interrupt_event() {
    if (data_available_on_input_field()) {
        incomingByte = read_data_on_input_field();
        println(incomingByte);
        led_on();
    }
}

This pseudo-code has a comparison statement to check if there are data available on the input field of the serial monitor, i.e serial port. If so, the data available will be stored on the memory, printed - only for debuging- and the led will be lighted on.

Schematic

Fig. 1 Schematic of the circuit

Part List

  • 1 LED
  • 1 220 ohm resistor for the led
  • 1 Protoboard
  • 2 copper wires (tinned) or jumpers


Assembly

Fig. 2 Assembly of the circuit

Solutions

Tools

References