Commit 605438336843b084d67ca68a6338f57613423f3b

Authored by Antonio Carlos Domínguez Brito
1 parent 5e438bab
Exists in master

New version 3.0.

This version is an improvement in order to solve a bug and a deviation from "good behavior":

1. TC interrupts are programmed at a quarter of the bit time period. This avoid a problems at receiving bytes starting at the very end of the half bit time period in the previous version.
2. In the previous version stop bit duration was not guaranteed when finishing a transmission, the second change to the library guarantees this exxtend.

Thanks to David Hansel (david@hansels.net) for diagnosing those two problems, and for suggesting alternative solutions for solving them.
Showing 1 changed file with 70 additions and 0 deletions   Show diff stats
examples/echo_test/echo_test.ino 0 → 100644
... ... @@ -0,0 +1,70 @@
  1 +/**
  2 + ** soft_uart library
  3 + ** Copyright (C) 2015-2018
  4 + **
  5 + ** Antonio C. Domínguez Brito <antonio.dominguez@ulpgc.es>
  6 + ** División de Robótica y Oceanografía Computacional <www.roc.siani.es>
  7 + ** and Departamento de Informática y Sistemas <www.dis.ulpgc.es>
  8 + ** Universidad de Las Palmas de Gran Canaria (ULPGC) <www.ulpgc.es>
  9 + **
  10 + ** This file is part of the soft_uart library.
  11 + ** The soft_uart library is free software: you can redistribute it and/or modify
  12 + ** it under the terms of the GNU General Public License as published by
  13 + ** the Free Software Foundation, either version 3 of the License, or any
  14 + ** later version.
  15 + **
  16 + ** The soft_uart library is distributed in the hope that it will be useful,
  17 + ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  18 + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
  19 + ** Public License for more details.
  20 + **
  21 + ** You should have received a copy (COPYING file) of the GNU General Public
  22 + ** License along with the soft_uart library.
  23 + ** If not, see: <http://www.gnu.org/licenses/>.
  24 + **/
  25 +/*
  26 + * File: echo_test.ino
  27 + * Description: This is an echo program for testing the library with another
  28 + * device (another microcontroller, a computer, etc.).
  29 + * Date: November 25th, 2018
  30 + * Author: Antonio C. Dominguez-Brito <antonio.dominguez@ulpgc.es>
  31 + * ROC-SIANI - Universidad de Las Palmas de Gran Canaria - Spain
  32 + */
  33 +
  34 +#include "soft_uart.h"
  35 +
  36 +using namespace arduino_due;
  37 +
  38 +#define RX_PIN 10 // software serial port's reception pin
  39 +#define TX_PIN 11 // software serial port's transmision pin
  40 +#define SOFT_UART_BIT_RATE 57600 // 57600 38400 1200 19200 9600 115200 300
  41 +#define RX_BUF_LENGTH 256 // software serial port's reception buffer length
  42 +#define TX_BUF_LENGTH 256 // software serial port's transmision buffer length
  43 +
  44 +// declaration of software serial port object serial_tc4
  45 +// which uses timer/counter channel TC4
  46 +serial_tc4_declaration(RX_BUF_LENGTH,TX_BUF_LENGTH);
  47 +auto& serial_obj=serial_tc4; // serial_tc4_t& serial_obj=serial_tc4;
  48 +
  49 +void setup()
  50 +{
  51 + // serial_obj initialization
  52 + serial_obj.begin(
  53 + RX_PIN,
  54 + TX_PIN,
  55 + SOFT_UART_BIT_RATE,
  56 + soft_uart::data_bit_codes::EIGHT_BITS,
  57 + soft_uart::parity_codes::NO_PARITY,
  58 + soft_uart::stop_bit_codes::ONE_STOP_BIT
  59 + );
  60 +}
  61 +
  62 +void loop()
  63 +{
  64 + if(serial_obj.available())
  65 + {
  66 + auto data=serial_obj.read();
  67 + if(data>=0)
  68 + serial_obj.write(static_cast<uint8_t>(data&0xff));
  69 +}
  70 +
... ...