mirror of
https://github.com/Sovichea/avr-i2c-library.git
synced 2025-10-16 07:54:47 +03:00
Reformatted the document
This commit is contained in:
@@ -10,9 +10,9 @@
|
|||||||
static ret_code_t tw_start(void)
|
static ret_code_t tw_start(void)
|
||||||
{
|
{
|
||||||
/* Send START condition */
|
/* Send START condition */
|
||||||
#if DEBUG_LOG
|
#if DEBUG_LOG
|
||||||
printf(BG "Send START condition..." RESET);
|
printf(BG "Send START condition..." RESET);
|
||||||
#endif
|
#endif
|
||||||
TWCR = (1 << TWINT) | (1 << TWEN) | (1 << TWSTA);
|
TWCR = (1 << TWINT) | (1 << TWEN) | (1 << TWSTA);
|
||||||
|
|
||||||
/* Wait for TWINT flag to set */
|
/* Wait for TWINT flag to set */
|
||||||
@@ -21,15 +21,15 @@ static ret_code_t tw_start(void)
|
|||||||
/* Check error */
|
/* Check error */
|
||||||
if (TW_STATUS != TW_START && TW_STATUS != TW_REP_START)
|
if (TW_STATUS != TW_START && TW_STATUS != TW_REP_START)
|
||||||
{
|
{
|
||||||
#if DEBUG_LOG
|
#if DEBUG_LOG
|
||||||
printf("\n");
|
printf("\n");
|
||||||
#endif
|
#endif
|
||||||
return TW_STATUS;
|
return TW_STATUS;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if DEBUG_LOG
|
#if DEBUG_LOG
|
||||||
printf("SUCCESS\n");
|
printf("SUCCESS\n");
|
||||||
#endif
|
#endif
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,9 +37,9 @@ static ret_code_t tw_start(void)
|
|||||||
static void tw_stop(void)
|
static void tw_stop(void)
|
||||||
{
|
{
|
||||||
/* Send STOP condition */
|
/* Send STOP condition */
|
||||||
#if DEBUG_LOG
|
#if DEBUG_LOG
|
||||||
puts(BG "Send STOP condition." RESET);
|
puts(BG "Send STOP condition." RESET);
|
||||||
#endif
|
#endif
|
||||||
TWCR = (1 << TWINT) | (1 << TWEN) | (1 << TWSTO);
|
TWCR = (1 << TWINT) | (1 << TWEN) | (1 << TWSTO);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,9 +47,9 @@ static void tw_stop(void)
|
|||||||
static ret_code_t tw_write_sla(uint8_t sla)
|
static ret_code_t tw_write_sla(uint8_t sla)
|
||||||
{
|
{
|
||||||
/* Transmit slave address with read/write flag */
|
/* Transmit slave address with read/write flag */
|
||||||
#if DEBUG_LOG
|
#if DEBUG_LOG
|
||||||
printf(BG "Write SLA + R/W: 0x%02X..." RESET, sla);
|
printf(BG "Write SLA + R/W: 0x%02X..." RESET, sla);
|
||||||
#endif
|
#endif
|
||||||
TWDR = sla;
|
TWDR = sla;
|
||||||
TWCR = (1 << TWINT) | (1 << TWEN);
|
TWCR = (1 << TWINT) | (1 << TWEN);
|
||||||
|
|
||||||
@@ -57,15 +57,15 @@ static ret_code_t tw_write_sla(uint8_t sla)
|
|||||||
while (!(TWCR & (1 << TWINT)));
|
while (!(TWCR & (1 << TWINT)));
|
||||||
if (TW_STATUS != TW_MT_SLA_ACK && TW_STATUS != TW_MR_SLA_ACK)
|
if (TW_STATUS != TW_MT_SLA_ACK && TW_STATUS != TW_MR_SLA_ACK)
|
||||||
{
|
{
|
||||||
#if DEBUG_LOG
|
#if DEBUG_LOG
|
||||||
printf("\n");
|
printf("\n");
|
||||||
#endif
|
#endif
|
||||||
return TW_STATUS;
|
return TW_STATUS;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if DEBUG_LOG
|
#if DEBUG_LOG
|
||||||
printf("SUCCESS\n");
|
printf("SUCCESS\n");
|
||||||
#endif
|
#endif
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,9 +73,9 @@ static ret_code_t tw_write_sla(uint8_t sla)
|
|||||||
static ret_code_t tw_write(uint8_t data)
|
static ret_code_t tw_write(uint8_t data)
|
||||||
{
|
{
|
||||||
/* Transmit 1 byte*/
|
/* Transmit 1 byte*/
|
||||||
#if DEBUG_LOG
|
#if DEBUG_LOG
|
||||||
printf(BG "Write data byte: 0x%02X..." RESET, data);
|
printf(BG "Write data byte: 0x%02X..." RESET, data);
|
||||||
#endif
|
#endif
|
||||||
TWDR = data;
|
TWDR = data;
|
||||||
TWCR = (1 << TWINT) | (1 << TWEN);
|
TWCR = (1 << TWINT) | (1 << TWEN);
|
||||||
|
|
||||||
@@ -83,15 +83,15 @@ static ret_code_t tw_write(uint8_t data)
|
|||||||
while (!(TWCR & (1 << TWINT)));
|
while (!(TWCR & (1 << TWINT)));
|
||||||
if (TW_STATUS != TW_MT_DATA_ACK)
|
if (TW_STATUS != TW_MT_DATA_ACK)
|
||||||
{
|
{
|
||||||
#if DEBUG_LOG
|
#if DEBUG_LOG
|
||||||
printf("\n");
|
printf("\n");
|
||||||
#endif
|
#endif
|
||||||
return TW_STATUS;
|
return TW_STATUS;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if DEBUG_LOG
|
#if DEBUG_LOG
|
||||||
printf("SUCCESS\n");
|
printf("SUCCESS\n");
|
||||||
#endif
|
#endif
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,9 +117,9 @@ static uint8_t tw_read(bool read_ack)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
uint8_t data = TWDR;
|
uint8_t data = TWDR;
|
||||||
#if DEBUG_LOG
|
#if DEBUG_LOG
|
||||||
printf(BG "Read data byte: 0x%02X\n" RESET, data);
|
printf(BG "Read data byte: 0x%02X\n" RESET, data);
|
||||||
#endif
|
#endif
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,9 +129,9 @@ void tw_init(twi_freq_mode_t twi_freq_mode, bool pullup_en)
|
|||||||
DDRC |= (1 << TW_SDA_PIN) | (1 << TW_SCL_PIN);
|
DDRC |= (1 << TW_SDA_PIN) | (1 << TW_SCL_PIN);
|
||||||
if (pullup_en)
|
if (pullup_en)
|
||||||
{
|
{
|
||||||
#if DEBUG_LOG
|
#if DEBUG_LOG
|
||||||
puts(BG "Enable pull-up resistor." RESET);
|
puts(BG "Enable pull-up resistor." RESET);
|
||||||
#endif
|
#endif
|
||||||
PORTC |= (1 << TW_SDA_PIN) | (1 << TW_SCL_PIN);
|
PORTC |= (1 << TW_SDA_PIN) | (1 << TW_SCL_PIN);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
Reference in New Issue
Block a user