; ====================== I2C2scsn.asm ================== ; ; I2C master ; by V.Angelov -- last modified: 15:57 / 23-Jun-2005 ; ; Only one CPU is required, CPU0 ; ; Typical usage: ; ; 1) initialize the srv_command with 0 and call the program ; This will initialize the I2C interface ; ; 2) put in srv_command ; Bits 23..16 15..8 7..1 0 ; number_of_bytes start_address device_address read(1)/write(0) ; ; if number_of_bytes=0 the I2C will be initialized only ; ; 3) in case of writing store the bytes to be send starting ; from srv_indata, one byte / address. This is not optimal, can be ; 3-4 bytes / address. ; ; 4) call the program ; ; 5) in case of reading the read bytes are from address ; srv_outdata, one byte / address. Again, this can be optimized. ; ; If the I2C communication fails, the timeout counter will be incremented. ; It can be read at IO address srv_command. ; ; ====================================================== tst: #ifdef traceon mvpcr 0, deb_reg sra+ deb_reg #endif mov 0xFF, wrk iext srv_command lgio 0, srv_command jmpr cc_busy, 0 lpio 0x300, r8 and wrk, r8, dev_addr ; -- device address shl -8, r8, ibit and wrk, ibit, start_addr ; -- start address shl -8, ibit, ibit and wrk, ibit, nbytes ; -- number of bytes jmp cc_zero, i2c_only_init shl -8, ibit, ibit andt dev_addr, c1 ; -- 1 for read, 0 for write mov i2c_lp, return1 ; -- mov doesn't change the zero flag! jmp cc_zero, i2c_swrite jmp cc_uncond, i2c_sread i2c_only_init: mvpcr +2, return1 jmp cc_uncond, i2c_init i2c_lp: #ifdef traceon mov 0xFFF, deb_reg sra+ deb_reg #endif jmpr cc_busy, 0 iext srv_command sgio timeoutcnt, srv_command jmpr cc_busy, 0 mov CMD_LP, dev_addr sgio dev_addr, SMCMD jmpr cc_uncond, 0 ; END OF THE MAIN PROGRAM