@@ -74,7 +74,7 @@ CPBStandardSerial::CPBStandardSerial()
7474 .callback = onSendBits,
7575 .arg = this ,
7676 .dispatch_method = ESP_TIMER_ISR,
77- .name = " Send "
77+ .name = " onSendBits "
7878 };
7979 esp_timer_create (&args, &timer_send_h);
8080 // Debug_printv("send_timer_create");
@@ -119,6 +119,7 @@ uint8_t CPBStandardSerial::receiveByte()
119119 // to accept data. What happens next is variable.
120120
121121 // Wait for all other devices to release the data line
122+ // IEC.release( PIN_IEC_DATA_IN );
122123 if ( timeoutWait ( PIN_IEC_DATA_IN, RELEASED, FOREVER, false ) == TIMED_OUT )
123124 {
124125 Debug_printv ( " Wait for all other devices to release the data line" );
@@ -131,10 +132,8 @@ uint8_t CPBStandardSerial::receiveByte()
131132 // will do nothing. The listener should be watching, and if 200 microseconds pass
132133 // without the Clock line going to true, it has a special task to perform: note EOI.
133134
134- // IEC.pull ( PIN_IEC_SRQ );
135+ IEC.pull ( PIN_IEC_SRQ );
135136 if ( timeoutWait ( PIN_IEC_CLK_IN, PULLED, TIMING_Tye, false ) == TIMING_Tye )
136- // timer_start( TIMING_Tye );
137- // while ( IEC.status ( PIN_IEC_CLK_IN ) != PULLED )
138137 {
139138 // INTERMISSION: EOI
140139 // If the Ready for Data signal isn't acknowledged by the talker within 200 microseconds, the
@@ -152,30 +151,23 @@ uint8_t CPBStandardSerial::receiveByte()
152151
153152 // IEC.pull ( PIN_IEC_SRQ );
154153
155- // if ( timer_timedout )
156- {
157- timer_timedout = false ;
158- IEC.flags |= EOI_RECVD;
159-
160- // Acknowledge by pull down data more than 60us
161- // wait ( TIMING_Th );
162- IEC.pull ( PIN_IEC_DATA_OUT );
163- wait ( TIMING_Tei );
164- IEC.release ( PIN_IEC_DATA_OUT );
154+ timer_timedout = false ;
155+ IEC.flags |= EOI_RECVD;
165156
166- // Wait for clock line to be pulled
167- timeoutWait ( PIN_IEC_CLK_IN, PULLED, TIMING_Tye, false );
168- }
157+ // Acknowledge by pull down data more than 60us
158+ // wait ( TIMING_Th );
159+ IEC.pull ( PIN_IEC_DATA_OUT );
160+ wait ( TIMING_Tei );
161+ IEC.release ( PIN_IEC_DATA_OUT );
169162
170- // usleep( 2 );
171- // IEC.release ( PIN_IEC_SRQ );
172- // usleep( 2 );
163+ // Wait for clock line to be pulled
164+ // timeoutWait ( PIN_IEC_CLK_IN, PULLED, TIMING_Tye, false );
173165 }
174- // IEC.release ( PIN_IEC_SRQ );
166+ IEC.release ( PIN_IEC_SRQ );
175167
176- // Sample ATN and set flag to indicate COMMAND or DATA mode
177- if ( IEC.status ( PIN_IEC_ATN ) )
178- IEC.flags |= ATN_PULLED;
168+ // // Sample ATN and set flag to indicate COMMAND or DATA mode
169+ // if ( IEC.status ( PIN_IEC_ATN ) )
170+ // IEC.flags |= ATN_PULLED;
179171
180172 // STEP 3: RECEIVING THE BITS
181173 // IEC.pull ( PIN_IEC_SRQ );
@@ -229,18 +221,23 @@ uint8_t CPBStandardSerial::receiveBits ()
229221{
230222 IEC.bit = 0 ;
231223 IEC.byte = 0 ;
232- timer_start ( TIMEOUT_DEFAULT );
233224
225+ timer_start ( TIMEOUT_DEFAULT );
234226 while ( IEC.bit < 7 )
235227 {
236228 if ( timer_timedout )
237229 {
230+ Debug_printv ( " Timeout bit[%d]" , IEC.bit );
238231 IEC.flags |= ERROR;
239232 return 0 ;
240233 }
241234
242- usleep ( 2 );
235+ IEC.pull ( PIN_IEC_SRQ );
236+ usleep ( 1 );
237+ IEC.release ( PIN_IEC_SRQ );
238+ usleep ( 1 );
243239 }
240+ timer_stop ();
244241
245242 // If there is a 218us delay before bit 7, the controller uses JiffyDOS
246243 timer_start ( TIMING_PROTOCOL_DETECT );
@@ -270,8 +267,12 @@ uint8_t CPBStandardSerial::receiveBits ()
270267 }
271268 }
272269
273- usleep ( 2 );
270+ IEC.pull ( PIN_IEC_SRQ );
271+ usleep ( 1 );
272+ IEC.release ( PIN_IEC_SRQ );
273+ usleep ( 1 );
274274 }
275+ timer_stop ();
275276
276277 // Wait for CLK to be pulled after last bit
277278 if ( timeoutWait ( PIN_IEC_CLK_IN, PULLED, FOREVER, false ) == TIMED_OUT )
@@ -396,7 +397,7 @@ bool CPBStandardSerial::sendByte(uint8_t data, bool eoi)
396397 // line to false. Suppose there is more than one listener. The Data line will go false
397398 // only when all listeners have RELEASED it - in other words, when all listeners are ready
398399 // to accept data.
399- IEC.pull ( PIN_IEC_SRQ );
400+ // IEC.pull ( PIN_IEC_SRQ );
400401 if ( timeoutWait ( PIN_IEC_DATA_IN, RELEASED, FOREVER ) == TIMED_OUT )
401402 {
402403 if ( !(IEC.flags & ATN_PULLED) )
@@ -407,7 +408,7 @@ bool CPBStandardSerial::sendByte(uint8_t data, bool eoi)
407408
408409 return false ; // return error because of ATN or timeout
409410 }
410- IEC.release ( PIN_IEC_SRQ );
411+ // IEC.release ( PIN_IEC_SRQ );
411412
412413 // What happens next is variable. Either the talker will pull the
413414 // Clock line back to true in less than 200 microseconds - usually within 60 microseconds - or it
@@ -471,33 +472,33 @@ bool CPBStandardSerial::sendByte(uint8_t data, bool eoi)
471472
472473 // Wait for listener to accept data
473474 // IEC.pull ( PIN_IEC_SRQ );
474- // if ( timeoutWait ( PIN_IEC_DATA_IN, PULLED, TIMEOUT_Tf ) == TIMEOUT_Tf )
475+ if ( timeoutWait ( PIN_IEC_DATA_IN, PULLED, TIMEOUT_Tf ) == TIMEOUT_Tf )
476+ {
477+ // RECIEVER TIMEOUT
478+ // If no receiver pulls DATA within 1000 µs at the end of the transmission of a byte (after step 28), a receiver timeout is raised.
479+ Debug_printv ( " Wait for listener to acknowledge byte received (pull data) [%02X]" , data );
480+ Debug_printv ( " RECEIVER TIMEOUT" );
481+ IEC.flags |= ERROR;
482+ // IEC.release ( PIN_IEC_SRQ );
483+ return false ; // return error because timeout
484+ }
485+ // IEC.release ( PIN_IEC_SRQ );
486+ // IEC.pull ( PIN_IEC_SRQ );
487+ // timer_start( TIMEOUT_Tf );
488+ // while ( IEC.status ( PIN_IEC_DATA_IN ) != PULLED )
475489 // {
476- // // RECIEVER TIMEOUT
477- // // If no receiver pulls DATA within 1000 µs at the end of the transmission of a byte (after step 28), a receiver timeout is raised.
478- // Debug_printv ( "Wait for listener to acknowledge byte received (pull data) [%02x]", data );
479- // Debug_printv ( "RECEIVER TIMEOUT" );
480- // IEC.flags |= ERROR;
481- // IEC.release ( PIN_IEC_SRQ );
482- // return false; // return error because timeout
490+ // if ( timer_timedout )
491+ // {
492+ // // RECIEVER TIMEOUT
493+ // // If no receiver pulls DATA within 1000 µs at the end of the transmission of a byte (after step 28), a receiver timeout is raised.
494+ // Debug_printv ( "Wait for listener to acknowledge byte received (pull data) [%02X]", data );
495+ // Debug_printv ( "RECEIVER TIMEOUT" );
496+ // IEC.flags |= ERROR;
497+ // //IEC.release ( PIN_IEC_SRQ );
498+ // return false; // return error because timeout
499+ // }
483500 // }
484501 // IEC.release ( PIN_IEC_SRQ );
485- IEC.pull ( PIN_IEC_SRQ );
486- timer_start ( TIMEOUT_Tf );
487- while ( IEC.status ( PIN_IEC_DATA_IN ) != PULLED )
488- {
489- if ( timer_timedout )
490- {
491- // RECIEVER TIMEOUT
492- // If no receiver pulls DATA within 1000 µs at the end of the transmission of a byte (after step 28), a receiver timeout is raised.
493- Debug_printv ( " Wait for listener to acknowledge byte received (pull data) [%02x]" , data );
494- Debug_printv ( " RECEIVER TIMEOUT" );
495- IEC.flags |= ERROR;
496- IEC.release ( PIN_IEC_SRQ );
497- return false ; // return error because timeout
498- }
499- }
500- IEC.release ( PIN_IEC_SRQ );
501502
502503 // STEP 5: START OVER
503504 // We're finished, and back where we started. The talker is holding the Clock line true,
0 commit comments