GARTHWILSON wrote:
Be sure you've considered http://wilsonminesco.com/6502primer/GENRLI2C.ASM . It does use a couple of CMOS instructions which you'll have to replace with more instructions to run on the NMOS 6507, but its efficiency is pretty good, and its readability is better. The code there is in several forms. Thanks for taking a look. The c02 instructions aside it actually looks like your send byte routine is basically the same, almost down to the instruction.
Code:
SEND_I2C_BYTE: ; Start with byte in A, and clock low. Ends with I2C_ACK?.
STA I2C_TEMP ; Store the byte in a variable so we can use A with TSB & TRB for data line.
LDA #10000000B ; Init A for mask for TRB & TSB below. A does not get disturbed below.
LDX #8 ; We will do 8 bits.
sIb2: TRB DDRA ; Release data line. This is like I2C_DATA_UP but saves 1 instruction.
ASL I2C_TEMP ; Get next bit to send and put it in the C flag.
BCS sIb1
TSB DDRA ; If the bit was 0, pull data line down by making it an output.
sIb1: DEC DDRA ; Do a high pulse on the clock line. Remember there's a 0 in the output
INC DDRA ; register bit, and DEC'ing DDRA makes that bit an input, so it can float up.
DEX ; IOW, it's backwards from what it seems.
BNE sIb2
JMP I2C_ACK? ; (JSR, RTS)
;------------------
I’m still scratching my head over the fact that when I optimize away the SCL RMW’s to one INC, SCL never goes low.
PB6 & 7 are busy so SDA is on bit 1.