Hardware Reference
In-Depth Information
brclr
IBSR,IBIF,*
; wait until the EEPROM ID is sent out
movb
#IBIF,IBSR
; clear the IBIF flag
brclr
IBSR,RXAK,ranRdok2
; does EEPROM acknowledge?
ldab
#$FF
; return 2 1, if EEPROM does not ackowledge
rts
ranRdok2
bset
IBCR,TXAK
; prepare to send NACK
bclr
IBCR,TXRX
; perform reception
ldaa
IBDR
; dummy read to initiate reception
brclr
IBSR,IBIF,*
; wait for a byte to shift in
movb
#IBIF,IBSR
; clear the IBIF flag
bclr
IBCR,MSSL
; generate a stop condition
ldaa
IBDR
; get the data byte
ldab
#0
; normal read status
rts
The C language version of the function is as follows:
char EErandomRead(char ID, char addr)
{
char dummy;
SendSlaveID(ID);
if (IBSR & RXAK)
return 2 1;
IBDR 5 addr;
/* send out EEPROM address */
while(!(IBSR & IBIF));
/* wait until the address is shifted out */
IBSR 5 IBIF;
/* clear IBIF flag */
if (IBSR & RXAK)
return 2 1;
IBCR | 5 RSTA;
/* generate restart condition */
IBDR 5 ID | 0x01;
/* prepare to read */
while (!(IBSR & IBIF));
IBSR 5 IBIF;
if (IBSR & RXAK)
return 2 1;
IBCR | 5 TXAK;
/* prepare to send NACK */
IBCR & 5 , TXRX;
/* perform reception */
dummy 5 IBDR;
/* dummy read to trigger nine clock pulses */
while(!(IBSR & IBIF));
/* wait for data to shift in */
IBSR 5 IBIF;
IBCR & 5 , MSSL;
/* generate a stop condition */
return IBDR;
}
Sequential read is performed in a block read operation. When the MCU saves the contents
of the IBDR register, it also initiates a sequential read if the MCU acknowledges the previously
received byte.
 
Search WWH ::




Custom Search