util_twi(3avr)

✨ util_twi β€” the TWI bit mask glow-up ✨

okay bestie, listen. this is util_twi from AVR-LibC, manual page util_twi(3avr), and it's literally the header <util/twi.h> that holds all the TWI bit mask definitions. no cap, it's giving "small file, huge main character energy". πŸŽ€


πŸ“– NAME

util_twi β€” <util/twi.h>: TWI bit mask definitions


🌸 SYNOPSIS

✨ TWSR values ✨

the mnemonics, so you know who's who at the party:

  • TW_MT_xxx β€” master transmitter πŸ’…
  • TW_MR_xxx β€” master receiver 🫢
  • TW_ST_xxx β€” slave transmitter
  • TW_SR_xxx β€” slave receiver

and now the actual defines, verbatim, no edits, periodt:

#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 they're iconic:

#define TW_READ   1
#define TW_WRITE   0

πŸ’– Detailed Description πŸ’–

first thing, the include. it's:

#include <util/twi.h>

and what IS this header, you ask? it contains bit mask definitions for use with the AVR TWI interface. that's it. that's the whole vibe. πŸ”₯


πŸ‘‘ Macro Definition Documentation πŸ‘‘

alphabetical order, the way the compiler gods intended. every single one, bestie, i'm not skipping a crumb:

  • #define TW_BUS_ERROR 0x00 β€” illegal start or stop condition πŸ’€
  • #define TW_MR_ARB_LOST 0x38 β€” arbitration lost in SLA+R or NACK
  • #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 πŸ™ˆ
  • #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
  • #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))
⚠️ okay important lore, don't skip this: 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, fr fr. πŸ”₯
  • #define TW_WRITE 0 β€” SLA+W address

🌈 Author 🌈

Generated automatically by Doxygen for AVR-LibC from the source code.


and that's the whole page, bestie!! go forth and bit-mask with confidence πŸ’…βœ¨

this lil beauty is from AVR-LibC, Version 2.2.1, and it's page util_twi(3avr) β€” mwah, no notes, obsessed πŸ«ΆπŸŽ€

πŸ“¦ where this page comes from