util_twi(3)

๐Ÿ“ฆ version 2.2.1, in fedora 43, fedora 44, opensuse-leap 16.0

๐Ÿ’– NAME ๐Ÿ’–

util_twi โ€” bestie, this is the AVR TWI header, and it's literally the whole vibe check for your IยฒC status codes โœจ

This page lives in the avr-libc manual, section 3 (library functions, iykyk) ๐Ÿซถ


โœจ SYNOPSIS โœจ

๐ŸŒˆ TWSR values ๐ŸŒˆ

Okay so the mnemonics here are chef's kiss โ€” they tell you at a glance whose turn it is on the bus:

  • TW_MT_xxx โ€” master transmitter
  • TW_MR_xxx โ€” master receiver
  • TW_ST_xxx โ€” slave transmitter
  • TW_SR_xxx โ€” slave receiver
#define TW_START   0x08
#define TW_REP_START   0x10
#define TW_MT_SLA_ACK   0x18
#define TW_MT_SLA_NACK   0x20
#define TW_MT_DATA_ACK   0x28
#define TW_MT_DATA_NACK   0x30
#define TW_MT_ARB_LOST   0x38
#define TW_MR_ARB_LOST   0x38
#define TW_MR_SLA_ACK   0x40
#define TW_MR_SLA_NACK   0x48
#define TW_MR_DATA_ACK   0x50
#define TW_MR_DATA_NACK   0x58
#define TW_ST_SLA_ACK   0xA8
#define TW_ST_ARB_LOST_SLA_ACK   0xB0
#define TW_ST_DATA_ACK   0xB8
#define TW_ST_DATA_NACK   0xC0
#define TW_ST_LAST_DATA   0xC8
#define TW_SR_SLA_ACK   0x60
#define TW_SR_ARB_LOST_SLA_ACK   0x68
#define TW_SR_GCALL_ACK   0x70
#define TW_SR_ARB_LOST_GCALL_ACK   0x78
#define TW_SR_DATA_ACK   0x80
#define TW_SR_DATA_NACK   0x88
#define TW_SR_GCALL_DATA_ACK   0x90
#define TW_SR_GCALL_DATA_NACK   0x98
#define TW_SR_STOP   0xA0
#define TW_NO_INFO   0xF8
#define TW_BUS_ERROR   0x00
#define TW_STATUS_MASK
#define TW_STATUS   (TWSR & TW_STATUS_MASK)

๐Ÿฆ‹ R/~W bit in SLA+R/W address field ๐Ÿฆ‹

Just the two, and yes they're tiny and perfect:

#define TW_READ   1
#define TW_WRITE   0

๐ŸŒธ Detailed Description ๐ŸŒธ

#include <util/twi.h>

So like. This header file is where the bit mask definitions live, for use with the AVR TWI interface. That's it, that's the whole job, and it does it gorgeously ๐Ÿ’…


๐ŸŽ€ Macro Definition Documentation ๐ŸŽ€

Here comes the full rundown, bestie โ€” every single one, no skipping, no cap ๐Ÿ’€

#define TW_BUS_ERROR 0x00

illegal start or stop condition ๐Ÿ˜ญ the bus said no thank you

#define TW_MR_ARB_LOST 0x38

arbitration lost in SLA+R or NACK โ€” you lost the race, it's giving awkward ๐Ÿ™ˆ

#define TW_MR_DATA_ACK 0x50

data received, ACK returned ๐Ÿ‘‘

#define TW_MR_DATA_NACK 0x58

data received, NACK returned ๐Ÿ’€

#define TW_MR_SLA_ACK 0x40

SLA+R transmitted, ACK received โœจ

#define TW_MR_SLA_NACK 0x48

SLA+R transmitted, NACK received ๐Ÿฅฒ

#define TW_MT_ARB_LOST 0x38

arbitration lost in SLA+W or data ๐Ÿ™ˆ

#define TW_MT_DATA_ACK 0x28

data transmitted, ACK received ๐Ÿ”ฅ

#define TW_MT_DATA_NACK 0x30

data transmitted, NACK received ๐Ÿ˜ญ

#define TW_MT_SLA_ACK 0x18

SLA+W transmitted, ACK received ๐Ÿซถ

#define TW_MT_SLA_NACK 0x20

SLA+W transmitted, NACK received ๐Ÿ’”

#define TW_NO_INFO 0xF8

no state information available โ€” the void, the silence, main character mystery energy ๐Ÿ•ณ๏ธ

#define TW_READ 1

SLA+R address ๐Ÿ“–

#define TW_REP_START 0x10

repeated start condition transmitted ๐Ÿ”

#define TW_SR_ARB_LOST_GCALL_ACK 0x78

arbitration lost in SLA+RW, general call received, ACK returned ๐ŸŒˆ

#define TW_SR_ARB_LOST_SLA_ACK 0x68

arbitration lost in SLA+RW, SLA+W received, ACK returned ๐Ÿงš

#define TW_SR_DATA_ACK 0x80

data received, ACK returned ๐Ÿ’–

#define TW_SR_DATA_NACK 0x88

data received, NACK returned ๐Ÿ™ƒ

#define TW_SR_GCALL_ACK 0x70

general call received, ACK returned ๐Ÿ“ฃ

#define TW_SR_GCALL_DATA_ACK 0x90

general call data received, ACK returned ๐ŸŒŸ

#define TW_SR_GCALL_DATA_NACK 0x98

general call data received, NACK returned ๐Ÿ’”

#define TW_SR_SLA_ACK 0x60

SLA+W received, ACK returned ๐ŸŽ€

#define TW_SR_STOP 0xA0

stop or repeated start condition received while selected โœ‹

#define TW_ST_ARB_LOST_SLA_ACK 0xB0

arbitration lost in SLA+RW, SLA+R received, ACK returned ๐Ÿ˜ฎโ€๐Ÿ’จ

#define TW_ST_DATA_ACK 0xB8

data transmitted, ACK received โญ

#define TW_ST_DATA_NACK 0xC0

data transmitted, NACK received ๐Ÿ˜”

#define TW_ST_LAST_DATA 0xC8

last data byte transmitted, ACK received ๐Ÿ the finale, the last episode, iconic

#define TW_ST_SLA_ACK 0xA8

SLA+R received, ACK returned ๐Ÿ‘‘

#define TW_START 0x08

start condition transmitted ๐Ÿš€

#define TW_STATUS (TWSR & TW_STATUS_MASK)

TWSR, masked by TW_STATUS_MASK ๐ŸŽญ

#define TW_STATUS_MASK

Value:

(_BV(TWS7)|_BV(TWS6)|_BV(TWS5)|_BV(TWS4)|                _BV(TWS3))
Real talk though: the lower 3 bits of TWSR are reserved on the ATmega163. And the 2 LSB carry the prescaler bits on the newer ATmegas. So like, know your chip, bestie ๐Ÿซก

#define TW_WRITE 0

SLA+W address โœ๏ธ


๐Ÿ’œ Author ๐Ÿ’œ

Generated automatically by Doxygen for avr-libc from the source code. Not me writing it by hand, the robot did it, and honestly? Slay ๐Ÿค–โœจ


Okay bye bestie โ€” this was Version 2.1.0, dated Sat Jan 29 2022, straight from the avr-libc streets. Go talk to your IยฒC bus, it misses you ๐Ÿฆ‹๐Ÿ’– periodt.

๐Ÿ“ฆ where this page comes from