Commit db903a7f49d669682e9e2ef61dca91e02b7908c8

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

New version 3.0.

This version improves the previous one facing two problems: a bug and a bad behavior.

1. The bug was related to bytes with a start bit received nearly at the same time that the TC interrupt happens. This problems has been solved using a period for sampling the reception line which is a quarter of the bit time, an not accessing the TC register from the reception interrupt.
2. The library now gurantee the duration of stop bits when sendin bytes in any circunstance.

Thanks to David Hansel (david@hansels.net) for debugging the library up to find out those two problems, and also for suggesting solutions for them.
CMakeLists.txt
... ... @@ -59,6 +59,7 @@ set(
59 59 soft_uart_serial_test_half_duplex
60 60 soft_uart_serial_test_half_duplex_9O2
61 61 soft_uart_serial_test_half_duplex_char
  62 + echo_test
62 63 )
63 64  
64 65 foreach(src_example ${SOFT_UART_EXAMPLES})
... ...
README.md
1   -## soft_uart v2.0
  1 +## soft_uart v3.0
2 2  
3 3 This is soft_uart library for the Arduino DUE electronic prototyping platform.
4 4  
5   -Copyright (C) 2015 Antonio C. Domínguez Brito (<adominguez@iusiani.ulpgc.es>). División de Robótica y Oceanografía Computacional (<http://www.roc.siani.es>) and Departamento de Informática y Sistemas (<http://www.dis.ulpgc.es>). Universidad de Las Palmas de Gran Canaria (ULPGC) (<http://www.ulpgc.es>).
  5 +Copyright (C) 2015-2018 Antonio C. Domínguez Brito (<adominguez@iusiani.ulpgc.es>). División de Robótica y Oceanografía Computacional (<http://www.roc.siani.es>) and Departamento de Informática y Sistemas (<http://www.dis.ulpgc.es>). Universidad de Las Palmas de Gran Canaria (ULPGC) (<http://www.ulpgc.es>).
6 6  
7 7 ### 0. License
8 8  
... ... @@ -137,7 +137,13 @@ In this section we would like to enumerate users using the library in their own
137 137  
138 138 The list of users/projects goes now:
139 139  
140   -1. **Project:** Autonomous sailboat A-Tirma (<http://velerorobot.blogspot.com.es>). **User**: División de Robótica y Oceanografía Computacional (<http://www.roc.siani.es>). **Description**: The library was a specific development for this project. The sailboat onboard system is based on an Arduino DUE, and we ran out of hardware serial ports for all the hardware we use on the boat.
  140 +1. **Project:** Autonomous sailboat A-Tirma (<http://velerorobot.blogspot.com.es>). **User:** División de Robótica y Oceanografía Computacional (<http://www.roc.siani.es>). **Description:** The library was a specific development for this project. The sailboat onboard system is based on an Arduino DUE, and we ran out of hardware serial ports for all the hardware we use on the boat.
  141 +
  142 +2. **Project:** Arduino Altair 8800 simulator (<https://github.com/dhansel/Altair8800>). **User:** David Hansel (<david@hansels.net>). **Description:** Source code for Arduino Altair 8800 simulator.
  143 +
  144 +### 9. Acknowledgements
  145 +
  146 +David Hansel for his suggestions and debugging of the library, soft_uart version 2.0 and 3.0 owe a lot to his findings.
141 147  
142 148 ### 8. Feedback & Suggestions
143 149  
... ...
examples/basic_test/basic_test.ino
1 1 /**
2 2 ** soft_uart library
3   - ** Copyright (C) 2015
  3 + ** Copyright (C) 2015-2018
4 4 **
5 5 ** Antonio C. Domínguez Brito <adominguez@iusiani.ulpgc.es>
6 6 ** División de Robótica y Oceanografía Computacional <www.roc.siani.es>
... ...
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 +
... ...
examples/soft_uart_serial_test/soft_uart_serial_test.ino
1 1 /**
2 2 ** soft_uart library
3   - ** Copyright (C) 2015
  3 + ** Copyright (C) 2015-2018
4 4 **
5 5 ** Antonio C. Domínguez Brito <adominguez@iusiani.ulpgc.es>
6 6 ** División de Robótica y Oceanografía Computacional <www.roc.siani.es>
... ... @@ -40,7 +40,7 @@ using namespace arduino_due;
40 40  
41 41 #define RX_PIN 10 // software serial port's reception pin
42 42 #define TX_PIN 11 // software serial port's transmision pin
43   -#define SOFT_UART_BIT_RATE 115200 // 57600 38400 1200 19200 9600 115200 300
  43 +#define SOFT_UART_BIT_RATE 57600 // 57600 38400 1200 19200 9600 115200 300
44 44 #define RX_BUF_LENGTH 256 // software serial port's reception buffer length
45 45 #define TX_BUF_LENGTH 256 // software serial port's transmision buffer length
46 46 #define RECEPTION_TIMEOUT 100 // milliseconds
... ...
examples/soft_uart_serial_test_auto/soft_uart_serial_test_auto.ino
1 1 /**
2 2 ** soft_uart library
3   - ** Copyright (C) 2015
  3 + ** Copyright (C) 2015-2018
4 4 **
5 5 ** Antonio C. Domínguez Brito <adominguez@iusiani.ulpgc.es>
6 6 ** División de Robótica y Oceanografía Computacional <www.roc.siani.es>
... ...
examples/soft_uart_serial_test_half_duplex/soft_uart_serial_test_half_duplex.ino
1 1 /**
2 2 ** soft_uart library
3   - ** Copyright (C) 2015
  3 + ** Copyright (C) 2015-2018
4 4 **
5 5 ** Antonio C. Domínguez Brito <adominguez@iusiani.ulpgc.es>
6 6 ** División de Robótica y Oceanografía Computacional <www.roc.siani.es>
... ...
examples/soft_uart_serial_test_half_duplex_9O2/soft_uart_serial_test_half_duplex_9O2.ino
1 1 /**
2 2 ** soft_uart library
3   - ** Copyright (C) 2015
  3 + ** Copyright (C) 2015-2018
4 4 **
5 5 ** Antonio C. Domínguez Brito <adominguez@iusiani.ulpgc.es>
6 6 ** División de Robótica y Oceanografía Computacional <www.roc.siani.es>
... ...
examples/soft_uart_serial_test_half_duplex_char/soft_uart_serial_test_half_duplex_char.ino
1 1 /**
2 2 ** soft_uart library
3   - ** Copyright (C) 2015
  3 + ** Copyright (C) 2015-2018
4 4 **
5 5 ** Antonio C. Domínguez Brito <adominguez@iusiani.ulpgc.es>
6 6 ** División de Robótica y Oceanografía Computacional <www.roc.siani.es>
... ...
fifo.h
1 1 /**
2 2 ** soft_uart library
3   - ** Copyright (C) 2015
  3 + ** Copyright (C) 2015-2018
4 4 **
5 5 ** Antonio C. Domínguez Brito <adominguez@iusiani.ulpgc.es>
6 6 ** División de Robótica y Oceanografía Computacional <www.roc.siani.es>
... ...
library.properties
1 1 name=soft_uart
2   -version=2.0
  2 +version=3.0
3 3 author=Antonio C. Domínguez Brito <adominguez@iusiani.ulpgc.es>
4 4 maintainer=Antonio C. Domínguez Brito <adominguez@iusiani.ulpgc.es>
5 5 sentence=This is an implementation of a software UART (Universal Asynchronous Receiver Transmitter) library for the Arduino Due's Atmel ATSAM3X8E micro-controller.
... ...
soft_uart.cpp
1 1 /**
2 2 ** soft_uart library
3   - ** Copyright (C) 2015
  3 + ** Copyright (C) 2015-2018
4 4 **
5 5 ** Antonio C. Domínguez Brito <adominguez@iusiani.ulpgc.es>
6 6 ** División de Robótica y Oceanografía Computacional <www.roc.siani.es>
... ...
soft_uart.h
1 1 /**
2 2 ** soft_uart library
3   - ** Copyright (C) 2015
  3 + ** Copyright (C) 2015-2018
4 4 **
5 5 ** Antonio C. Domínguez Brito <adominguez@iusiani.ulpgc.es>
6 6 ** División de Robótica y Oceanografía Computacional <www.roc.siani.es>
... ... @@ -670,6 +670,7 @@ namespace arduino_due
670 670 double frame_time;
671 671 uint32_t bit_ticks;
672 672 uint32_t bit_1st_half;
  673 + uint32_t bit_1st_quarter;
673 674  
674 675 // serial protocol
675 676 uint32_t bit_rate;
... ... @@ -923,6 +924,7 @@ namespace arduino_due
923 924  
924 925 bit_ticks=static_cast<uint32_t>(bit_time/tc_tick);
925 926 bit_1st_half=(bit_ticks>>1);
  927 + bit_1st_quarter=(bit_ticks>>2);
926 928  
927 929 data_bits=the_data_bits; parity=the_parity; stop_bits=the_stop_bits;
928 930  
... ... @@ -991,7 +993,8 @@ namespace arduino_due
991 993 //disable_tc_ra_interrupt();
992 994  
993 995 //TC_SetRC(timer_p->tc_p,timer_p->channel,bit_ticks);
994   - TC_SetRC(timer_p->tc_p,timer_p->channel,bit_1st_half);
  996 + //TC_SetRC(timer_p->tc_p,timer_p->channel,bit_1st_half);
  997 + TC_SetRC(timer_p->tc_p,timer_p->channel,bit_1st_quarter);
995 998 //disable_tc_rc_interrupt();
996 999 enable_tc_rc_interrupt();
997 1000  
... ... @@ -1020,10 +1023,11 @@ namespace arduino_due
1020 1023 // rx code
1021 1024 if(rx_status==rx_status_codes::RECEIVING)
1022 1025 {
1023   - if((rx_interrupt_counter++)&1)
  1026 + if(rx_interrupt_counter==1)
1024 1027 {
1025   - get_incoming_bit();
1026   - if((rx_bit_counter++)==rx_frame_bits-1)
  1028 + get_incoming_bit();
  1029 + rx_bit_counter++;
  1030 + if(rx_bit_counter==rx_frame_bits)
1027 1031 {
1028 1032 if(stop_bits==stop_bit_codes::TWO_STOP_BITS)
1029 1033 get_incoming_bit();
... ... @@ -1035,27 +1039,33 @@ namespace arduino_due
1035 1039 rx_status=rx_status_codes::LISTENING;
1036 1040 }
1037 1041 }
  1042 + rx_interrupt_counter=(rx_interrupt_counter+1)&0x3;
1038 1043 }
1039 1044  
1040 1045 // tx code
1041 1046 if(tx_status==tx_status_codes::SENDING)
1042 1047 {
1043   - if((tx_interrupt_counter++)&1)
  1048 + if(tx_interrupt_counter==0)
1044 1049 {
1045   - set_outgoing_bit();
1046   - if((tx_bit_counter++)==tx_frame_bits-1)
  1050 + if(tx_bit_counter>=tx_frame_bits)
1047 1051 {
1048 1052 uint32_t data_to_send;
1049 1053 if(tx_buffer.pop(data_to_send))
1050   - { tx_data=data_to_send; tx_bit_counter=0; }
  1054 + {
  1055 + tx_data=data_to_send; tx_bit_counter=0;
  1056 + set_outgoing_bit(); tx_bit_counter++;
  1057 + }
1051 1058 else
1052 1059 {
1053   - if(rx_status==rx_status_codes::LISTENING) stop_tc_interrupts();
  1060 + if(rx_status==rx_status_codes::LISTENING)
  1061 + stop_tc_interrupts();
1054 1062  
1055 1063 tx_status=tx_status_codes::IDLE;
1056 1064 }
1057 1065 }
  1066 + else { set_outgoing_bit(); tx_bit_counter++; }
1058 1067 }
  1068 + tx_interrupt_counter=(tx_interrupt_counter+1)&0x3;
1059 1069 }
1060 1070 }
1061 1071 }
... ... @@ -1080,16 +1090,16 @@ namespace arduino_due
1080 1090 {
1081 1091 rx_status=rx_status_codes::RECEIVING;
1082 1092 rx_data=rx_bit_counter=rx_bit=0;
1083   - rx_interrupt_counter=1;
  1093 + rx_interrupt_counter=0;
1084 1094  
1085 1095 if(tx_status==tx_status_codes::IDLE) start_tc_interrupts();
1086   - else
1087   - {
1088   - register uint32_t timer_value=
1089   - TC_ReadCV(timer_p->tc_p,timer_p->channel);
  1096 + //else
  1097 + //{
  1098 + // register uint32_t timer_value=
  1099 + // TC_ReadCV(timer_p->tc_p,timer_p->channel);
1090 1100  
1091   - if(timer_value>=(bit_1st_half>>1)) rx_interrupt_counter=0;
1092   - }
  1101 + // if(timer_value>=(bit_1st_half>>1)) rx_interrupt_counter=0;
  1102 + //}
1093 1103 }
1094 1104 break;
1095 1105  
... ... @@ -1213,7 +1223,7 @@ namespace arduino_due
1213 1223 {
1214 1224 tx_buffer.pop(data_to_send);
1215 1225 tx_data=data_to_send; tx_bit_counter=0;
1216   - tx_interrupt_counter=1;
  1226 + tx_interrupt_counter=0;
1217 1227 }
1218 1228  
1219 1229 if(
... ...
soft_uart_license_header.txt
1 1 /**
2 2 ** soft_uart library
3   - ** Copyright (C) 2015
  3 + ** Copyright (C) 2015-2018
4 4 **
5 5 ** Antonio C. Domínguez Brito <adominguez@iusiani.ulpgc.es>
6 6 ** División de Robótica y Oceanografía Computacional <www.roc.siani.es>
... ...