Hello all, I am trying to interface my HC12 with an I2C EEPROM and I am having trouble performing a write to the EEPROM (Model No. M24C02) The worst part is that the in circuit debugger that I am using (ICD12Z from P&E) seems to be doing something really weird when I run the program such that I can't see anything on my scope ... and thus I don't even know where to start debugging. I would really appreciate it if someone were to take a look at my code below and tell me what I am doing wrong ... or even send me sample code for me to compare against mine.... Thanks, Taha Amiralli () ---------------------------- ;********************************************************************* ; This program writes 12 bytes of data to an I2C compatible EEPROM ;********************************************************************* ;********************************************************************* ; Register Definitions ;********************************************************************* ;I2C Module registers IBAD equ $E0 IBFD equ $E1 IBCR equ $E2 IBSR equ $E3 IBDR equ $E4 ;********************************************************************* ; Constants and tables ;********************************************************************* DATASIZE equ 13 org $0800 ;Beginning of RAM data: DB $00,$c4,$c9,$00,$c4,$06,$00,$47,$05,$02,$10,$01,$00 ;********************************************************************* ; Program ;********************************************************************* org $0400 ;Beginning of EEPROM HC12 ;HC12 Chip ;**;IIC init main: movb #$4B,IBFD ;Set Freq div for IIC movb #$FE,IBAD ;HC12 slave address bset IBCR,$80 ;Set enable bit ;Clearing registers ldaa #$00 ldab #$00 ldx #$0800 ;**;Dummy Read ;Generate Start Condition brset IBSR,$20,* ;Wait for busy flag bset IBCR,$20 ;Set Rx. and Master movb #$A1,IBDR ;Transmit Dev Select brclr IBSR,$20,* ;Wait for IBB Flag brclr IBSR,$02,* ;Wait for data bclr IBSR,$02 ;Clear flag ldaa IBSR ;Put SR into AccA ldaa IBDR ;Put Data into AccA ;Generate a Stop condition bclr IBCR,$20 ;**;Transmission ;Generate Start Condition brset IBSR,$20,* ;Wait for busy flag bset IBCR,$30 ;Set Tx and master movb #$A0,IBDR ;Transmit Dev Select brclr IBSR,$20,* ;Wait for IBB Flag brclr IBSR,$02,* ;Wait for data to be ;transmitted bclr IBSR,$02 ;Clear flag movb #$00,IBDR brclr IBSR,$02,* ;Wait for data to be ;transmitted bclr IBSR,$02 ;Clear flag movb #$c4,IBDR ;Generate a Stop condition brclr IBSR,$02,* bclr IBCR,$20 ;********************* Program halt halt: nop nop bra halt |
Help with I2C hardware on the HC12
Started by ●August 23, 2004