@@ -32,7 +32,6 @@ reg [1:0] in_reg = 2'b0; // shift reg for input signal conditioning
3232reg [4 :0 ] in_hold_reg = 5'b0 ; // shift reg for signal hold time checks
3333reg [3 :0 ] sample_count = 4'b0 ; // count ticks for 16x oversample
3434reg [4 :0 ] out_hold_count = 5'b0 ; // count ticks before clearing output data
35- reg was_stop_good = 1'b0 ; // flag for stop signal hold time was met
3635reg [2 :0 ] bit_index = 3'b0 ; // index for 8-bit data
3736reg [7 :0 ] received_data = 8'b0 ; // storage for the deserialized data
3837wire in_sample;
@@ -96,7 +95,6 @@ always @(posedge clk) begin
9695 // state variables
9796 sample_count <= 4'b0 ;
9897 out_hold_count <= 5'b0 ;
99- was_stop_good <= 1'b0 ;
10098 received_data <= 8'b0 ;
10199 // outputs
102100 busy <= 1'b0 ;
@@ -120,8 +118,10 @@ always @(posedge clk) begin
120118 */
121119 if (! in_sample) begin
122120 if (sample_count == 4'b0 ) begin
123- if (& in_prior_hold_reg || was_stop_good) begin
124- // meets the preceding min high hold time
121+ if (& in_prior_hold_reg || done && ! err) begin
122+ // meets the preceding min high hold time -
123+ // note that {done} && !{err} encodes the fact that
124+ // the min hold time was met earlier in STOP_BIT state
125125 sample_count <= 4'b1 ;
126126 err <= 1'b0 ;
127127 end else begin
@@ -133,7 +133,6 @@ always @(posedge clk) begin
133133 sample_count <= sample_count + 4'b1 ;
134134 if (& sample_count[2 :0 ]) begin // reached 7
135135 sample_count <= 4'b0 ; // start the interval count over
136- was_stop_good <= 1'b0 ;
137136 busy <= 1'b1 ;
138137 err <= 1'b0 ;
139138 state <= `START_BIT;
@@ -199,7 +198,6 @@ always @(posedge clk) begin
199198 // changed to a start signal
200199 if (sample_count == 4'b1000 &&
201200 & in_prior_hold_reg) begin // meets the hold time
202- was_stop_good <= 1'b1 ;
203201 // can accept the transmitted data and output it
204202 sample_count <= 4'b0 ;
205203 out_hold_count <= 5'b1 ;
@@ -217,7 +215,6 @@ always @(posedge clk) begin
217215 end
218216 end else begin
219217 if (& in_current_hold_reg) begin // meets min high hold time
220- was_stop_good <= 1'b1 ;
221218 // can accept the transmitted data and output it
222219 sample_count <= 4'b0 ;
223220 done <= 1'b1 ;
0 commit comments