Consider the "big" IF-statement, for the count > 2 case:
1) ACK should get enabled to implement the protocol as per the timing diagram in the reference manual.
2) the index 'i' into data is ahead by one after the WHILE loop -- it got already incremented in the loop when it exits.
Code: Select all
IF count = 1 THEN (* ... *) ELSIF count = 2 THEN (* ... *) ELSE SetBit(CR1, ACK); (* 1) enable ACK *) i := 0; WHILE count > 3 DO (* ... *) INC(i); DEC(count) END; (* ... *) SYSTEM.GET(DR, data[i]); (* 2) i was INC-ed in the WHILE loop *) (* ... *) SYSTEM.GET(DR, data[i + 1]); (* 2) *) (* ... *) SYSTEM.GET(DR, data[i + 2]) (* 2) *) END;