twi.h(3avr)
β¨ NAME β¨
twi.h β that's it, that's the whole name, bestie π
it's a header file and it lives in section 3avr of the manual, so when you see twi.h(3avr) floating around you already know what time it is.
π SYNOPSIS π
Macros
TWSR values
okay so this is the part where we get into the actual content, and ngl it's a lot of little #defines, but every single one of them is a mood and a half π
Mnemonics:
the naming scheme is lowkey iconic once you clock it β each family of values tells you who's doing the talking and what just happened:
TW_MT_xxxβ master transmitter π«ΆTW_MR_xxxβ master receiverTW_ST_xxxβ slave transmitterTW_SR_xxxβ slave receiver
and here's the full lineup, character for character, no cap:
#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)
not me noticingTW_MT_ARB_LOSTandTW_MR_ARB_LOSTare literally the same value,0x38β twins, obviously, they ate π
R/~W bit in SLA+R/W address field.
this is the little bit that decides which direction the conversation is going, and it only has two settings, which honestly? main character energy:
#define TW_READ 1
#define TW_WRITE 0
π Author π
generated automatically by Doxygen for AVR-LibC from the source code. so like, nobody wrote this page by hand, it manifested, and we respect that π§
okay bye bestie β this was twi.h from AVR-LibC, Version 2.2.1, page twi.h(3avr). go forth and slay those TWI status codes β¨π¦π
π¦ where this page comes from
- debian trixie: avr-libc 1:2.2.1-1 Β· BSD-3-Clause
- ubuntu questing: avr-libc 1:2.2.1-1
- ubuntu resolute: avr-libc 1:2.2.1-1build1 Β· BSD-3-Clause
- ubuntu stonking: avr-libc 1:2.2.1-1build1 Β· BSD-3-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms