3 Replies Latest reply on Jan 13, 2017 12:10 PM by maxfennig_2214451

    I2C Write on EZ-USB FX (original one)

    maxfennig_2214451

      I am trying to make some changes to the firmware of a device. It uses an EZ-USB FX with a serial eeprom (24lc02)

         

      The firmware is uploaded via USB control A0

         

      The original developers are long since left. and the source code was not found, so I disassembled it.

         

      I need to add some debug to allow me to do single byte eeprom read/writes.

         

      The eeprom read works fine and allows me to dump the full eeprom, but thee writes just don't happen (bytes remain unchanged) - no indication of error.

         

      I have simplified my code to not do error checking so under normal case it should just work

         

      At the start of this code, DPT points to 7CC0h, ie OUTBUF4 which contains 3 bytes

         

      $31, $50, $62

         

      The first byte $31 is the command number (EEPROM WRITE) - this causes my code to be called.

         

      In this example, $50 is the eeprom address wish to change and $62 is the new byte value.

         
        inc DPTR       ; Get a byte from OUT4BUF[1]   movx A, @DPTR      ; /   mov RAM_C, A      ; Set the EEPROM address (RAM_C) to the byte    inc DPTR       ; Get a byte from OUT4BUF[2]   movx A, @DPTR      ; /   mov RAM_D, A      ; Set the EEPROM data (RAM_D) to the byte    clr A       ; \   mov DPTR, #7E00h      ; Set IN2BUF[0] to 0x00 - Default to Success   movx @DPTR, A      ; /    ;-------------------- I2C START    mov DPTR, #7FA5h      ; Get I2C-Compatible Control and Status (I2CS)   movx A, @DPTR      ; /   orl A, #80h       ; Set the START bit   movx @DPTR, A      ; /    ;-------------------- I2C CONTROL BYTE    mov DPTR, #7FA6h      ; Get I2C-Compatible Data (I2DAT)   mov A, #0A0h                                          ; Device = EEPROM 24LC02, Direction = Write   movx @DPTR, A      ; /  loop1:  mov DPTR, #7FA5h         movx A, @DPTR      ; Get I2C-Compatible Control and Status (I2CS)   jnb ACC.0, loop1      ; Wait until the DONE bit is set (1)    ;-------------------- I2C WRITE ADDRESS    mov R7, RAM_C      ; Set R7 to the address   mov DPTR, #7FA6h      ; \   mov A, R7       ; Set I2C-Compatible Data (I2DAT) to the contents of R7   movx @DPTR, A      ; /  loop2:  mov DPTR, #7FA5h      ; Get I2C-Compatible Control and Status (I2CS)   movx A, @DPTR      ; /   jnb ACC.0, loop2    ;-------------------- I2C WRITE DATA      mov R7, RAM_D      ; Set R7 to the data   mov DPTR, #7FA6h      ; \   mov A, R7       ; Set I2C-Compatible Data (I2DAT) to the contents of R7   movx @DPTR, A      ; /  loop3:  mov DPTR, #7FA5h      ; Get I2C-Compatible Control and Status (I2CS)   movx A, @DPTR      ; /   jnb ACC.0, loop3    ;-------------------- I2C STOP    mov DPTR, #7FA5h      ; Get I2C-Compatible Control and Status (I2CS)   movx A, @DPTR      ; /   orl A, #40h       ; Set the STOP bit   movx @DPTR, A      ; /  loop4:  mov DPTR, #7FA5h      ; Get I2C-Compatible Control and Status (I2CS)   movx A, @DPTR      ; /   jb ACC.6, loop4      ; Wait until the STOP bit reads back as clear (0)    mov DPTR, #7FB9h      ; \   mov A, #1       ; Set the Byte Count for Endpoint IN2 (IN2BC) to 1   movx @DPTR, A      ; /   ljmp COMMAND_COMPLETED