mirror of
https://github.com/qmk/qmk_firmware.git
synced 2024-11-28 22:20:13 +00:00
Update i2c.c
This commit is contained in:
parent
092416325b
commit
bb413383ee
@ -161,94 +161,4 @@ ISR(TWI_vect) {
|
||||
TWCR |= (1<<TWIE) | (1<<TWINT) | (ack<<TWEA) | (1<<TWEN);
|
||||
}
|
||||
|
||||
// from SSD1306
|
||||
/*
|
||||
void i2c_start_wait(unsigned char address)
|
||||
{
|
||||
uint8_t twst;
|
||||
|
||||
|
||||
while ( 1 )
|
||||
{
|
||||
// send START condition
|
||||
TWCR = (1<<TWINT) | (1<<TWSTA) | (1<<TWEN);
|
||||
|
||||
// wait until transmission completed
|
||||
while(!(TWCR & (1<<TWINT)));
|
||||
|
||||
// check value of TWI Status Register. Mask prescaler bits.
|
||||
twst = TW_STATUS & 0xF8;
|
||||
if ( (twst != TW_START) && (twst != TW_REP_START)) continue;
|
||||
|
||||
// send device address
|
||||
TWDR = address;
|
||||
TWCR = (1<<TWINT) | (1<<TWEN);
|
||||
|
||||
// wail until transmission completed
|
||||
while(!(TWCR & (1<<TWINT)));
|
||||
|
||||
// check value of TWI Status Register. Mask prescaler bits.
|
||||
twst = TW_STATUS & 0xF8;
|
||||
if ( (twst == TW_MT_SLA_NACK )||(twst ==TW_MR_DATA_NACK) )
|
||||
{
|
||||
// device busy, send stop condition to terminate write operation
|
||||
TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTO);
|
||||
|
||||
// wait until stop condition is executed and bus released
|
||||
while(TWCR & (1<<TWSTO));
|
||||
|
||||
continue;
|
||||
}
|
||||
//if( twst != TW_MT_SLA_ACK) return 1;
|
||||
break;
|
||||
}
|
||||
|
||||
}// i2c_start_wait
|
||||
*/
|
||||
/*************************************************************************
|
||||
Issues a repeated start condition and sends address and transfer direction
|
||||
|
||||
Input: address and transfer direction of I2C device
|
||||
|
||||
Return: 0 device accessible
|
||||
1 failed to access device
|
||||
*************************************************************************/
|
||||
/*
|
||||
unsigned char i2c_rep_start(unsigned char address)
|
||||
{
|
||||
return i2c_master_start( address );
|
||||
|
||||
}/* i2c_rep_start */
|
||||
/*************************************************************************
|
||||
Read one byte from the I2C device, request more data from device
|
||||
|
||||
Return: byte read from I2C device
|
||||
*************************************************************************/
|
||||
/*
|
||||
unsigned char i2c_readAck(void)
|
||||
{
|
||||
TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWEA);
|
||||
while(!(TWCR & (1<<TWINT)));
|
||||
|
||||
return TWDR;
|
||||
|
||||
}/* i2c_readAck */
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
Read one byte from the I2C device, read is followed by a stop condition
|
||||
|
||||
Return: byte read from I2C device
|
||||
*************************************************************************
|
||||
unsigned char i2c_readNak(void)
|
||||
{
|
||||
TWCR = (1<<TWINT) | (1<<TWEN);
|
||||
while(!(TWCR & (1<<TWINT)));
|
||||
|
||||
return TWDR;
|
||||
|
||||
}/* i2c_readNak */
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user