283
// pull down SDA to create START condition
FORCING_SDA_LOW();
}
// function to generate I2C REPEATED START condition
void i2c_usi_mst_gen_repeated_start(void)
{
USICTL0 |= USIOE;
USISRL = 0xFF;
USICNT = 1;
// wait for USIIFG is set
i2c_usi_mst_wait_usi_cnt_flag();
// small delay
_delay_cycles(100);
// pull down SDA to create START condition
FORCING_SDA_LOW();
// small delay
_delay_cycles(100);
}
// function to generate I2C STOP condition
void i2c_usi_mst_gen_stop(void)
{
USICTL0 |= USIOE;
USISRL = 0x00;
USICNT = 1;
// wait for USIIFG is set
i2c_usi_mst_wait_usi_cnt_flag();
FORCING_SDA_HIGH();
}
// function to wait for I2C counter flag condition
void i2c_usi_mst_wait_usi_cnt_flag(void)
{
while(usi_cnt_flag == FALSE)
{
//__bis_SR_register(LPM0_bits);
}
// reset flag
usi_cnt_flag = FALSE;
}
// function to send a byte
unsigned char i2c_usi_mst_send_byte(unsigned char data_byte)
{
// send address and R/W bit
SET_SDA_AS_OUTPUT();