![FTDI FT51A Скачать руководство пользователя страница 46](http://html1.mh-extra.com/html/ftdi/ft51a/ft51a_application-note_2341158046.webp)
Application Note
AN_289 FT51A Programming Guide
Version 1.0
Document Reference No.: FT_000962 Clearance No.: FTDI# 483
45
Copyright © 2015 Future Technology Devices International Limited
2.5.6.2
Send Data
To send data to an I
2
C Slave the following procedure is used:
For a single cycle:
o
Write the slave address to the
I2CMSA
register and set bit R/S to 0.
o
Write the first byte of data to the
I2CMBUF
register.
o
Write to the Control Register
I2CMCR
with
HS
=0,
STOP
=1,
START
=1,
RUN
=1.
o
Read the
I2CMSR
register until the
BUSY
bit is clear.
For multiple cycles:
o
Write the slave address to the
I2CMSA
register and set bit R/S to 0.
o
Write the first byte of data to the
I2CMBUF
register.
o
Write to the Control Register
I2CMCR
with
HS
=0,
STOP
=0,
START
=1,
RUN
=1.
o
Read the
I2CMSR
register until the
BUSY
bit is clear.
o
For remaining bytes (except last byte):
Write the next byte of data to the
I2CMBUF
register.
Write to the Control Register
HS
=0,
STOP
=0,
START
=1,
RUN
=1.
Read the
I2CMSR
register until the
BUSY
bit is clear.
o
Write the last byte of data to the
I2CMBUF
register.
o
Write to the Control Register
I2CMCR
with
HS
=0,
STOP
=1,
START
=1,
RUN
=1.
o
Read the
I2CMSR
register until the
BUSY
bit is clear.
To allow a burst write, change
STOP
bit to 0.
uint8_t
data;
// Set I2C Slave Address
I2CMSA = 0x22<<1;
__asm NOP __endasm;
I2CMBUF = data;
I2CMCR = 0x04 | 0x02 | 0x01; // I2C_FLAGS_STOP | I2C_FLAGS_START | I2C_FLAGS_RUN
__asm NOP __endasm;
__asm NOP __endasm;
__asm NOP __endasm;
do
{ // loop while busy
status = I2CMCR;
if (!(status & 0x01)) //I2C_STATUS_BUSY
{
if (status & 0x02) //I2C_STATUS_ERROR
return 0;
return 1;
}
}while( 1 );
2.5.6.3
Receive Data
To receive data from an I
2
C Slave the following procedure is used:
For single cycle:
o
Write the slave address to the
I2CMSA
register and set bit R/S to 1.
o
Write to the Control Register
I2CMCR
with
HS
=0,
ACK
=1,
STOP
=1,
START
=1,
RUN
=1.
o
Read the
I2CMSA
register until the
BUSY
bit is clear.
o
Read the first byte of data from the
I2CMBUF
register.
For multiple cycles:
o
Write the slave address to the
I2CMSA
register and set bit R/S to 1.
o
Write to the Control Register
I2CMCR
with
HS
=0,
ACK
=1,
STOP
=0,
START
=1,
RUN
=1.