Commit 8caf1e15eb7427d571187e7eeb8df634626a48b9

Authored by Antonio Carlos Domínguez Brito
1 parent 3ce37850
Exists in master

bug fix: solved start bit reading when it starts in last quarter of TC period

examples/soft_uart_serial_test_auto/soft_uart_serial_test_auto.ino
... ... @@ -124,7 +124,7 @@ void loop() {
124 124 Serial.println("********************************************************");
125 125 Serial.println("********************************************************");
126 126  
127   - Serial.print("--> [serial_obj] sending: "); Serial.println(counter);
  127 + Serial.print("--> [serial_tc4] sending: "); Serial.println(counter);
128 128 // IMPORTANT: for sending 9-bit values you should send each value separately
129 129 // using function write(uint32_t). Using functions print or println, or alike
130 130 // function will truncate each data to be send to 8 bits.
... ...
soft_uart.h
... ... @@ -673,6 +673,7 @@ namespace arduino_due
673 673 volatile uint32_t rx_bit;
674 674 volatile rx_status_codes rx_status;
675 675 volatile uint32_t rx_data_status;
  676 + volatile bool rx_at_end_quarter;
676 677  
677 678 // tx data
678 679 fifo<uint32_t,TX_BUFFER_LENGTH> tx_buffer;
... ... @@ -935,6 +936,7 @@ namespace arduino_due
935 936 rx_status=rx_status_codes::LISTENING;
936 937 rx_data_status=rx_data_status_codes::NO_DATA_AVAILABLE;
937 938 rx_buffer.reset();
  939 + rx_at_end_quarter=false;
938 940  
939 941 rx_irq=(
940 942 (rx_pio_p==PIOA)?
... ... @@ -993,21 +995,25 @@ namespace arduino_due
993 995 {
994 996 if(rx_status==rx_status_codes::RECEIVING)
995 997 {
996   - get_incoming_bit();
997   - if((rx_bit_counter++)==rx_frame_bits-1)
  998 + if(!rx_at_end_quarter)
998 999 {
999   - if(stop_bits==stop_bit_codes::TWO_STOP_BITS)
1000   - get_incoming_bit();
  1000 + get_incoming_bit();
  1001 + if((rx_bit_counter++)==rx_frame_bits-1)
  1002 + {
  1003 + if(stop_bits==stop_bit_codes::TWO_STOP_BITS)
  1004 + get_incoming_bit();
1001 1005  
1002   - disable_tc_ra_interrupt();
  1006 + disable_tc_ra_interrupt();
1003 1007  
1004   - if(tx_status==tx_status_codes::IDLE)
1005   - stop_tc_interrupts();
  1008 + if(tx_status==tx_status_codes::IDLE)
  1009 + stop_tc_interrupts();
1006 1010  
1007   - update_rx_data_buffer();
  1011 + update_rx_data_buffer();
1008 1012  
1009   - rx_status=rx_status_codes::LISTENING;
  1013 + rx_status=rx_status_codes::LISTENING;
  1014 + }
1010 1015 }
  1016 + else rx_at_end_quarter=false;
1011 1017 }
1012 1018 }
1013 1019  
... ... @@ -1095,10 +1101,16 @@ namespace arduino_due
1095 1101 register uint32_t timer_value=
1096 1102 TC_ReadCV(timer_p->tc_p,timer_p->channel);
1097 1103  
1098   - if(
1099   - (timer_value<=(bit_1st_half>>1)) ||
1100   - (timer_value>bit_1st_half+(bit_1st_half>>1))
1101   - ) enable_tc_ra_interrupt();
  1104 + if(timer_value<=(bit_1st_half>>1))
  1105 + enable_tc_ra_interrupt();
  1106 + else
  1107 + {
  1108 + if(timer_value>bit_1st_half+(bit_1st_half>>1))
  1109 + {
  1110 + enable_tc_ra_interrupt();
  1111 + rx_at_end_quarter=true;
  1112 + }
  1113 + }
1102 1114 }
1103 1115 }
1104 1116 break;
... ...