Send and receive data over UART, I2C, and SPI using the ANX SDK communication APIs. Includes configuration structs, read/write functions, and error handling.
The ANX SDK provides separate APIs for each serial communication protocol: UART for point-to-point serial communication with a host or another microcontroller, I2C for connecting multiple low-speed sensors and peripherals on a shared two-wire bus, and SPI for high-speed full-duplex data exchange with flash memory, displays, and other peripherals. Each protocol has its own header, configuration struct, and set of read/write functions — all returning anx_err_t for consistent error handling.
UART
I2C
SPI
UART — anx/uart.h
UART is a point-to-point asynchronous serial protocol. Include the header to access the UART API:
#include "anx/uart.h"
Initialization
Configure a UART port by populating an anx_uart_config_t struct and passing it to anx_uart_init(). Call anx_uart_init() once per port during application startup before any read or write operations.
anx_uart_config_t members
anx_uart_port_t
required
The UART port to configure. Use ANX_UART0 for the primary serial port or ANX_UART1 for the secondary port.
uint32_t
required
Baud rate in bits per second. Common values: 9600, 19200, 57600, 115200, 230400, 921600. Both ends of the connection must use the same baud rate.
uint8_t
required
Number of data bits per frame. Typically 8; 7 is supported for legacy protocols.
uint8_t
required
Number of stop bits. Use 1 for standard operation; 2 for compatibility with older hardware.
anx_parity_t
required
Parity mode. Use ANX_PARITY_NONE for no parity, ANX_PARITY_EVEN for even parity, or ANX_PARITY_ODD for odd parity.
anx_err_t
ANX_OK on success. ANX_ERR_INVALID_ARG if any config member is out of range. ANX_ERR_FAIL if the hardware port is already in use.
anx_uart_write()
Writes len bytes from data to the specified UART port. The function blocks until all bytes have been placed in the hardware transmit buffer or the operation times out.
anx_uart_port_t
required
The initialized UART port to write to (ANX_UART0 or ANX_UART1).
const uint8_t *
required
Pointer to the byte array to transmit. Must not be NULL.
size_t
required
Number of bytes to transmit from data.
anx_err_t
ANX_OK when all bytes are sent. ANX_ERR_TIMEOUT if the transmit buffer does not drain within the hardware timeout. ANX_ERR_INVALID_ARG if data is NULL or len is zero.
anx_uart_read()
Reads up to len bytes from the specified UART port into buf, waiting up to timeout_ms milliseconds for data to arrive.
anx_uart_port_t
required
The initialized UART port to read from (ANX_UART0 or ANX_UART1).
uint8_t *
required
Pointer to the buffer that receives the incoming data. Must be at least len bytes long.
size_t
required
Maximum number of bytes to read into buf.
uint32_t
required
Maximum number of milliseconds to wait for data. Pass 0 to return immediately with whatever bytes are currently available in the receive buffer.
int
The number of bytes actually read (0 to len). Returns -1 on error (for example, if the port is not initialized).
Connect the TX and RX pins together on your dev module to run a loopback test without needing a second device. It is a fast way to verify your baud rate and framing settings before integrating a real peripheral.
I2C — anx/i2c.h
I2C is a two-wire, multi-device bus protocol. Include the header to access the I2C API:
#include "anx/i2c.h"
Initialization
Configure an I2C bus by populating an anx_i2c_config_t struct and passing it to anx_i2c_init(). The ANX dev module exposes two independent I2C buses.
anx_i2c_config_t members
anx_i2c_bus_t
required
The I2C bus to configure. Use ANX_I2C0 for the primary bus or ANX_I2C1 for the secondary bus.
anx_i2c_speed_t
required
Bus clock speed. Use ANX_I2C_STANDARD for 100 kHz (compatible with all I2C devices) or ANX_I2C_FAST for 400 kHz (requires all devices on the bus to support fast mode).
anx_err_t
ANX_OK on success. ANX_ERR_INVALID_ARG if speed is not a valid value. ANX_ERR_FAIL if the bus is already initialized.
anx_i2c_write()
Sends len bytes from data to the device at 7-bit address addr on the specified bus.
anx_i2c_bus_t
required
The initialized I2C bus (ANX_I2C0 or ANX_I2C1).
uint8_t
required
The 7-bit I2C address of the target device (0x00–0x7F).
const uint8_t *
required
Pointer to the byte array to send. Must not be NULL.
size_t
required
Number of bytes to send.
anx_err_t
ANX_OK on success. ANX_ERR_NOT_FOUND if no device acknowledges the address. ANX_ERR_TIMEOUT if the bus does not become idle within the timeout window.
anx_i2c_read()
Reads len bytes from the device at 7-bit address addr on the specified bus into buf.
anx_i2c_bus_t
required
The initialized I2C bus (ANX_I2C0 or ANX_I2C1).
uint8_t
required
The 7-bit I2C address of the target device.
uint8_t *
required
Pointer to the buffer that receives the read data. Must be at least len bytes long.
size_t
required
Number of bytes to read from the device.
anx_err_t
ANX_OK on success. ANX_ERR_NOT_FOUND if the device does not acknowledge. ANX_ERR_TIMEOUT if the read does not complete in time.
anx_i2c_scan()
Scans the bus and logs the 7-bit address of every device that sends an acknowledgement. Use this during development to verify that all sensors are wired correctly and that their addresses match your expectations.
anx_i2c_bus_t
required
The initialized I2C bus to scan (ANX_I2C0 or ANX_I2C1).
anx_err_t
ANX_OK after the scan completes, regardless of how many devices responded.
Example: register read pattern
Most I2C sensors use a register-based interface: write the register address you want to read, then read back the value in a separate transaction.
Some I2C devices require a repeated-start condition between the write and read phases. If anx_i2c_read() returns ANX_ERR_NOT_FOUND immediately after a successful write, check the device datasheet to see whether it supports repeated-start or requires a full stop/start sequence.
SPI — anx/spi.h
SPI is a synchronous, full-duplex serial protocol well suited for high-speed peripherals. Include the header to access the SPI API:
#include "anx/spi.h"
Initialization
Configure an SPI bus by populating an anx_spi_config_t struct and passing it to anx_spi_init().
anx_spi_config_t members
anx_spi_bus_t
required
The SPI bus to configure. Use ANX_SPI0 for the primary SPI bus.
uint32_t
required
Clock frequency in Hz. The maximum supported speed is 40000000 (40 MHz). Start at a lower speed (4–8 MHz) when debugging and raise it once the connection is verified stable.
anx_spi_mode_t
required
SPI clock polarity and phase. Choose from:
ANX_SPI_MODE0 — CPOL=0, CPHA=0 (clock idles low, data sampled on rising edge)
ANX_SPI_MODE1 — CPOL=0, CPHA=1 (clock idles low, data sampled on falling edge)
ANX_SPI_MODE2 — CPOL=1, CPHA=0 (clock idles high, data sampled on falling edge)
ANX_SPI_MODE3 — CPOL=1, CPHA=1 (clock idles high, data sampled on rising edge)
anx_err_t
ANX_OK on success. ANX_ERR_INVALID_ARG if speed exceeds 40 MHz or mode is not valid. ANX_ERR_FAIL if the bus is already initialized.
anx_spi_transfer()
Performs a full-duplex SPI transfer, simultaneously clocking out len bytes from tx and clocking in len bytes into rx. Pass NULL for tx to receive only (MOSI held low), or NULL for rx to transmit only (MISO ignored).
anx_spi_bus_t
required
The initialized SPI bus (ANX_SPI0).
const uint8_t *
Pointer to the transmit buffer. Pass NULL to send zeroed bytes (receive-only operation).
uint8_t *
Pointer to the receive buffer. Must be at least len bytes long if non-NULL. Pass NULL to discard incoming data (transmit-only operation).
size_t
required
Number of bytes to transfer. Both tx and rx (when non-NULL) must be at least this long.
anx_err_t
ANX_OK on success. ANX_ERR_INVALID_ARG if both tx and rx are NULL, or if len is zero. ANX_ERR_TIMEOUT if the transfer does not complete within the hardware timeout.
Chip-Select Control
The ANX SPI API gives you manual control over the chip-select (CS) line so you can compose multi-transfer transactions without deselecting the device between calls.
anx_spi_cs_active()
Asserts the chip-select line (drives it low) to begin a transaction.
anx_spi_bus_t
required
The initialized SPI bus whose CS line you want to assert.
anx_err_t
ANX_OK on success.
anx_spi_cs_idle()
Deasserts the chip-select line (drives it high) to end a transaction.
anx_spi_bus_t
required
The initialized SPI bus whose CS line you want to release.
Always call anx_spi_cs_idle() after every transaction — even if anx_spi_transfer() returns an error. Leaving the CS line asserted prevents other devices that share the same SPI bus from communicating and may lock up the bus until the next reboot.
Choosing the correct SPI mode
Consult your peripheral’s datasheet and look for the CPOL and CPHA timing diagrams in the electrical characteristics section. Most SPI flash and display controllers use ANX_SPI_MODE0. If you see corrupted data at higher clock speeds, try lowering the frequency first before switching the mode — a marginal PCB trace is more commonly the culprit than a mode mismatch.
{"docsConfig":{"theme":"aspen","$schema":"https://mintlify.com/docs.json","name":"ANX Labs","colors":{"primary":"#ef7025","light":"#eec9bc","dark":"#4fa1ab"},"favicon":"https://mintcdn.com/anx-labs/H0aHZx4SlmwWLATt/favicon.svg?fit=max\u0026auto=format\u0026n=H0aHZx4SlmwWLATt\u0026q=85\u0026s=4a861bb7f869c9f6a31c9b1c852565ba","navbar":{"primary":{"type":"github","href":"https://github.com/anx-labs"}},"styling":{"latex":false},"navigation":{"pages":[]}},"deployment":{"deploymentMetadataValue":{"subdomain":"anx-labs","hasAudioNarration":false,"actualSubdomain":"anx-labs","customDomains":["launchpad.anxlabs.com"],"gitSource":{"type":"github","owner":"mintlify-community","repo":"docs-anx-labs-29c3cb4e","deployBranch":"main","contentDirectory":"","isPrivate":true,"mountPath":"","label":""},"entitlements":{"AI_CHAT":{"status":"DISABLED"}},"buildId":"6ae95c5b9249234afda65411:success","clientVersion":"0.0.4143","searchFilterCounts":[{"language":"default","tag":"Documentation","count":17},{"language":"default","tag":"API Reference","count":4},{"language":"default","tag":"SDK","count":4},{"language":"default","tag":"Dev Module","count":4},{"language":"default","tag":"Example Applications","count":4},{"language":"default","tag":"OS Firmware","count":4},{"language":"default","tag":"Get Started","count":3},{"language":"default","tag":"Troubleshooting","count":2}]},"assistantConfig":{"enableAskAiButton":false,"enableStarterQuestions":false,"enableContextualStarterQuestions":false,"enableAskAiSearchBar":true},"basePath":"","hasChatPermissions":false,"hasWebMcpPermissions":false,"toggles":[{"name":"kill-isr","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-rbac-roles","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-mintlify-slack","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-integrations-settings","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"rbac-expansion","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-pr-grouping","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-prefix","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"analytics-v7","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"user-flows-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"no-publish-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-onboarding","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving-live","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"stripTemperatureMiddleware","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"support-platform-pylon-zendesk","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"instant-rollback","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications-server","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-fable","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fixed-ai-action-pricing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automation-resolve-merge-conflict","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"scoped-publishing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"mintql","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"page-level-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-version-history-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"billing-page-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"full-page-search","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workspace-projects","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"assistant-v5","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fork-pr-previews","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"revalidation-jwt","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-sso-scim","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"hobby-abuse-scan","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"dashboard-inbox","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-signup","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-dual-write","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-enabled","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"approve-review-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-metadata","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"sso-setup-deadline-banner","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-serve","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"live-agents","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"llms-txt-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false}],"googleFontsInlined":false},"customCss":[],"page":{"pagePath":"api/communication","slug":"/api/communication","pageMetadata":{"title":"ANX SDK Communication APIs: UART, I2C, and SPI","sidebarTitle":"Communication","description":"Send and receive data over UART, I2C, and SPI using the ANX SDK communication APIs. Includes configuration structs, read/write functions, and error handling.","href":"/api/communication"},"description":{"compiledSource":"\"use strict\";\nconst {jsx: _jsx} = arguments[0];\nconst {useMDXComponents: _provideComponents} = arguments[0];\nfunction _createMdxContent(props) {\n const _components = {\n p: \"p\",\n ..._provideComponents(),\n ...props.components\n };\n return _jsx(_components.p, {\n children: \"Send and receive data over UART, I2C, and SPI using the ANX SDK communication APIs. Includes configuration structs, read/write functions, and error handling.\"\n });\n}\nfunction MDXContent(props = {}) {\n const {wrapper: MDXLayout} = {\n ..._provideComponents(),\n ...props.components\n };\n return MDXLayout ? _jsx(MDXLayout, {\n ...props,\n children: _jsx(_createMdxContent, {\n ...props\n })\n }) : _createMdxContent(props);\n}\nreturn {\n default: MDXContent\n};\n","frontmatter":{},"scope":{}},"pageType":"default","mdx":{"mdxSource":{"compiledSource":"\"use strict\";const{Fragment:_Fragment,jsx:_jsx,jsxs:_jsxs}=arguments[0];const{useMDXComponents:_provideComponents}=arguments[0];function _createMdxContent(props){const _components={code:`code`,hr:`hr`,li:`li`,p:`p`,pre:`pre`,span:`span`,ul:`ul`,..._provideComponents(),...props.components},{Accordion,CodeBlock,Heading,Note,ParamField,ResponseField,Tab,Tabs,Tip,Warning}=_components;if(!Accordion)_missingMdxReference(`Accordion`,true);if(!CodeBlock)_missingMdxReference(`CodeBlock`,true);if(!Heading)_missingMdxReference(`Heading`,true);if(!Note)_missingMdxReference(`Note`,true);if(!ParamField)_missingMdxReference(`ParamField`,true);if(!ResponseField)_missingMdxReference(`ResponseField`,true);if(!Tab)_missingMdxReference(`Tab`,true);if(!Tabs)_missingMdxReference(`Tabs`,true);if(!Tip)_missingMdxReference(`Tip`,true);if(!Warning)_missingMdxReference(`Warning`,true);return _jsxs(_Fragment,{children:[_jsxs(_components.p,{children:[`The ANX SDK provides separate APIs for each serial communication protocol: UART for point-to-point serial communication with a host or another microcontroller, I2C for connecting multiple low-speed sensors and peripherals on a shared two-wire bus, and SPI for high-speed full-duplex data exchange with flash memory, displays, and other peripherals. Each protocol has its own header, configuration struct, and set of read/write functions — all returning `,_jsx(_components.code,{children:`anx_err_t`}),` for consistent error handling.`]}),`\n`,_jsxs(Tabs,{children:[_jsxs(Tab,{title:`UART`,id:`uart`,\"data-child-heading-ids\":`[\"uart-%E2%80%94-anx%2Fuart-h\",\"initialization\",\"anx_uart_config_t-members\",\"anx_uart_write\",\"anx_uart_read\",\"example%3A-uart-loopback-test\"]`,children:[_jsxs(Heading,{level:`2`,id:`uart-—-anx/uart-h`,children:[`UART — `,_jsx(_components.code,{children:`anx/uart.h`})]}),_jsx(_components.p,{children:`UART is a point-to-point asynchronous serial protocol. Include the header to access the UART API:`}),_jsx(CodeBlock,{filename:``,numberOfLines:`1`,language:`c`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`c`,children:_jsxs(_components.code,{language:`c`,numberOfLines:`1`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`#include`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"anx/uart.h\"`})]}),`\n`]})})}),_jsx(Heading,{level:`3`,id:`initialization`,children:`Initialization`}),_jsxs(_components.p,{children:[`Configure a UART port by populating an `,_jsx(_components.code,{children:`anx_uart_config_t`}),` struct and passing it to `,_jsx(_components.code,{children:`anx_uart_init()`}),`. Call `,_jsx(_components.code,{children:`anx_uart_init()`}),` once per port during application startup before any read or write operations.`]}),_jsxs(Heading,{level:`4`,id:`anx_uart_config_t-members`,children:[_jsx(_components.code,{children:`anx_uart_config_t`}),` members`]}),_jsx(ParamField,{path:`port`,type:`anx_uart_port_t`,required:true,id:`param-port`,children:_jsxs(_components.p,{children:[`The UART port to configure. Use `,_jsx(_components.code,{children:`ANX_UART0`}),` for the primary serial port or `,_jsx(_components.code,{children:`ANX_UART1`}),` for the secondary port.`]})}),_jsx(ParamField,{path:`baud`,type:`uint32_t`,required:true,id:`param-baud`,children:_jsxs(_components.p,{children:[`Baud rate in bits per second. Common values: `,_jsx(_components.code,{children:`9600`}),`, `,_jsx(_components.code,{children:`19200`}),`, `,_jsx(_components.code,{children:`57600`}),`, `,_jsx(_components.code,{children:`115200`}),`, `,_jsx(_components.code,{children:`230400`}),`, `,_jsx(_components.code,{children:`921600`}),`. Both ends of the connection must use the same baud rate.`]})}),_jsx(ParamField,{path:`data_bits`,type:`uint8_t`,required:true,id:`param-data-bits`,children:_jsxs(_components.p,{children:[`Number of data bits per frame. Typically `,_jsx(_components.code,{children:`8`}),`; `,_jsx(_components.code,{children:`7`}),` is supported for legacy protocols.`]})}),_jsx(ParamField,{path:`stop_bits`,type:`uint8_t`,required:true,id:`param-stop-bits`,children:_jsxs(_components.p,{children:[`Number of stop bits. Use `,_jsx(_components.code,{children:`1`}),` for standard operation; `,_jsx(_components.code,{children:`2`}),` for compatibility with older hardware.`]})}),_jsx(ParamField,{path:`parity`,type:`anx_parity_t`,required:true,id:`param-parity`,children:_jsxs(_components.p,{children:[`Parity mode. Use `,_jsx(_components.code,{children:`ANX_PARITY_NONE`}),` for no parity, `,_jsx(_components.code,{children:`ANX_PARITY_EVEN`}),` for even parity, or `,_jsx(_components.code,{children:`ANX_PARITY_ODD`}),` for odd parity.`]})}),_jsx(ResponseField,{name:`anx_uart_init return`,type:`anx_err_t`,id:`param-anx-uart-init-return`,children:_jsxs(_components.p,{children:[_jsx(_components.code,{children:`ANX_OK`}),` on success. `,_jsx(_components.code,{children:`ANX_ERR_INVALID_ARG`}),` if any config member is out of range. `,_jsx(_components.code,{children:`ANX_ERR_FAIL`}),` if the hardware port is already in use.`]})}),_jsx(_components.hr,{}),_jsx(Heading,{level:`3`,id:`anx_uart_write`,children:_jsx(_components.code,{children:`anx_uart_write()`})}),_jsxs(_components.p,{children:[`Writes `,_jsx(_components.code,{children:`len`}),` bytes from `,_jsx(_components.code,{children:`data`}),` to the specified UART port. The function blocks until all bytes have been placed in the hardware transmit buffer or the operation times out.`]}),_jsx(ParamField,{path:`port`,type:`anx_uart_port_t`,required:true,id:`param-port-1`,children:_jsxs(_components.p,{children:[`The initialized UART port to write to (`,_jsx(_components.code,{children:`ANX_UART0`}),` or `,_jsx(_components.code,{children:`ANX_UART1`}),`).`]})}),_jsx(ParamField,{path:`data`,type:`const uint8_t *`,required:true,id:`param-data`,children:_jsx(_components.p,{children:`Pointer to the byte array to transmit. Must not be NULL.`})}),_jsx(ParamField,{path:`len`,type:`size_t`,required:true,id:`param-len`,children:_jsxs(_components.p,{children:[`Number of bytes to transmit from `,_jsx(_components.code,{children:`data`}),`.`]})}),_jsx(ResponseField,{name:`return`,type:`anx_err_t`,id:`param-return`,children:_jsxs(_components.p,{children:[_jsx(_components.code,{children:`ANX_OK`}),` when all bytes are sent. `,_jsx(_components.code,{children:`ANX_ERR_TIMEOUT`}),` if the transmit buffer does not drain within the hardware timeout. `,_jsx(_components.code,{children:`ANX_ERR_INVALID_ARG`}),` if `,_jsx(_components.code,{children:`data`}),` is NULL or `,_jsx(_components.code,{children:`len`}),` is zero.`]})}),_jsx(_components.hr,{}),_jsx(Heading,{level:`3`,id:`anx_uart_read`,children:_jsx(_components.code,{children:`anx_uart_read()`})}),_jsxs(_components.p,{children:[`Reads up to `,_jsx(_components.code,{children:`len`}),` bytes from the specified UART port into `,_jsx(_components.code,{children:`buf`}),`, waiting up to `,_jsx(_components.code,{children:`timeout_ms`}),` milliseconds for data to arrive.`]}),_jsx(ParamField,{path:`port`,type:`anx_uart_port_t`,required:true,id:`param-port-2`,children:_jsxs(_components.p,{children:[`The initialized UART port to read from (`,_jsx(_components.code,{children:`ANX_UART0`}),` or `,_jsx(_components.code,{children:`ANX_UART1`}),`).`]})}),_jsx(ParamField,{path:`buf`,type:`uint8_t *`,required:true,id:`param-buf`,children:_jsxs(_components.p,{children:[`Pointer to the buffer that receives the incoming data. Must be at least `,_jsx(_components.code,{children:`len`}),` bytes long.`]})}),_jsx(ParamField,{path:`len`,type:`size_t`,required:true,id:`param-len-1`,children:_jsxs(_components.p,{children:[`Maximum number of bytes to read into `,_jsx(_components.code,{children:`buf`}),`.`]})}),_jsx(ParamField,{path:`timeout_ms`,type:`uint32_t`,required:true,id:`param-timeout-ms`,children:_jsxs(_components.p,{children:[`Maximum number of milliseconds to wait for data. Pass `,_jsx(_components.code,{children:`0`}),` to return immediately with whatever bytes are currently available in the receive buffer.`]})}),_jsx(ResponseField,{name:`return`,type:`int`,id:`param-return-1`,children:_jsxs(_components.p,{children:[`The number of bytes actually read (0 to `,_jsx(_components.code,{children:`len`}),`). Returns `,_jsx(_components.code,{children:`-1`}),` on error (for example, if the port is not initialized).`]})}),_jsx(_components.hr,{}),_jsx(Heading,{level:`3`,id:`example-uart-loopback-test`,children:`Example: UART loopback test`}),_jsx(CodeBlock,{filename:`uart_loopback.c`,numberOfLines:`20`,language:`c`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`c`,children:_jsxs(_components.code,{language:`c`,numberOfLines:`20`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`#include`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"anx/anx.h\"`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`#include`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"anx/uart.h\"`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`void`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` app_main`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`void`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:` anx_uart_config_t`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` cfg `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` .port `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ANX_UART0,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` .baud `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 115200`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` .data_bits `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 8`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` .stop_bits `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 1`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` .parity `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ANX_PARITY_NONE,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` };`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` anx_uart_init`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`\u0026`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`cfg);`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` const`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` char`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` *`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`msg `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"Hello UART\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` anx_uart_write`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(ANX_UART0, (`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` uint8_t`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` *`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)msg, `}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`strlen`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(msg));`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` uint8_t`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` buf`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`[`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`32`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`];`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` int`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` n `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` anx_uart_read`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(ANX_UART0, buf, `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`sizeof`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(buf), `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`1000`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` ANX_LOGI`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"UART\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Received `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#9CDCFE`},children:`%d`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` bytes\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, n);`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`]})})}),_jsx(Tip,{children:_jsx(_components.p,{children:`Connect the TX and RX pins together on your dev module to run a loopback test without needing a second device. It is a fast way to verify your baud rate and framing settings before integrating a real peripheral.`})})]}),_jsxs(Tab,{title:`I2C`,id:`i2c`,\"data-child-heading-ids\":`[\"i2c-%E2%80%94-anx%2Fi2c-h\",\"initialization-2\",\"anx_i2c_config_t-members\",\"anx_i2c_write\",\"anx_i2c_read\",\"anx_i2c_scan\",\"example%3A-register-read-pattern\"]`,children:[_jsxs(Heading,{level:`2`,id:`i2c-—-anx/i2c-h`,children:[`I2C — `,_jsx(_components.code,{children:`anx/i2c.h`})]}),_jsx(_components.p,{children:`I2C is a two-wire, multi-device bus protocol. Include the header to access the I2C API:`}),_jsx(CodeBlock,{filename:``,numberOfLines:`1`,language:`c`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`c`,children:_jsxs(_components.code,{language:`c`,numberOfLines:`1`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`#include`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"anx/i2c.h\"`})]}),`\n`]})})}),_jsx(Heading,{level:`3`,id:`initialization-2`,children:`Initialization`}),_jsxs(_components.p,{children:[`Configure an I2C bus by populating an `,_jsx(_components.code,{children:`anx_i2c_config_t`}),` struct and passing it to `,_jsx(_components.code,{children:`anx_i2c_init()`}),`. The ANX dev module exposes two independent I2C buses.`]}),_jsxs(Heading,{level:`4`,id:`anx_i2c_config_t-members`,children:[_jsx(_components.code,{children:`anx_i2c_config_t`}),` members`]}),_jsx(ParamField,{path:`bus`,type:`anx_i2c_bus_t`,required:true,id:`param-bus`,children:_jsxs(_components.p,{children:[`The I2C bus to configure. Use `,_jsx(_components.code,{children:`ANX_I2C0`}),` for the primary bus or `,_jsx(_components.code,{children:`ANX_I2C1`}),` for the secondary bus.`]})}),_jsx(ParamField,{path:`speed`,type:`anx_i2c_speed_t`,required:true,id:`param-speed`,children:_jsxs(_components.p,{children:[`Bus clock speed. Use `,_jsx(_components.code,{children:`ANX_I2C_STANDARD`}),` for 100 kHz (compatible with all I2C devices) or `,_jsx(_components.code,{children:`ANX_I2C_FAST`}),` for 400 kHz (requires all devices on the bus to support fast mode).`]})}),_jsx(ResponseField,{name:`anx_i2c_init return`,type:`anx_err_t`,id:`param-anx-i2c-init-return`,children:_jsxs(_components.p,{children:[_jsx(_components.code,{children:`ANX_OK`}),` on success. `,_jsx(_components.code,{children:`ANX_ERR_INVALID_ARG`}),` if `,_jsx(_components.code,{children:`speed`}),` is not a valid value. `,_jsx(_components.code,{children:`ANX_ERR_FAIL`}),` if the bus is already initialized.`]})}),_jsx(_components.hr,{}),_jsx(Heading,{level:`3`,id:`anx_i2c_write`,children:_jsx(_components.code,{children:`anx_i2c_write()`})}),_jsxs(_components.p,{children:[`Sends `,_jsx(_components.code,{children:`len`}),` bytes from `,_jsx(_components.code,{children:`data`}),` to the device at 7-bit address `,_jsx(_components.code,{children:`addr`}),` on the specified bus.`]}),_jsx(ParamField,{path:`bus`,type:`anx_i2c_bus_t`,required:true,id:`param-bus-1`,children:_jsxs(_components.p,{children:[`The initialized I2C bus (`,_jsx(_components.code,{children:`ANX_I2C0`}),` or `,_jsx(_components.code,{children:`ANX_I2C1`}),`).`]})}),_jsx(ParamField,{path:`addr`,type:`uint8_t`,required:true,id:`param-addr`,children:_jsx(_components.p,{children:`The 7-bit I2C address of the target device (0x00–0x7F).`})}),_jsx(ParamField,{path:`data`,type:`const uint8_t *`,required:true,id:`param-data-1`,children:_jsx(_components.p,{children:`Pointer to the byte array to send. Must not be NULL.`})}),_jsx(ParamField,{path:`len`,type:`size_t`,required:true,id:`param-len-2`,children:_jsx(_components.p,{children:`Number of bytes to send.`})}),_jsx(ResponseField,{name:`return`,type:`anx_err_t`,id:`param-return-2`,children:_jsxs(_components.p,{children:[_jsx(_components.code,{children:`ANX_OK`}),` on success. `,_jsx(_components.code,{children:`ANX_ERR_NOT_FOUND`}),` if no device acknowledges the address. `,_jsx(_components.code,{children:`ANX_ERR_TIMEOUT`}),` if the bus does not become idle within the timeout window.`]})}),_jsx(_components.hr,{}),_jsx(Heading,{level:`3`,id:`anx_i2c_read`,children:_jsx(_components.code,{children:`anx_i2c_read()`})}),_jsxs(_components.p,{children:[`Reads `,_jsx(_components.code,{children:`len`}),` bytes from the device at 7-bit address `,_jsx(_components.code,{children:`addr`}),` on the specified bus into `,_jsx(_components.code,{children:`buf`}),`.`]}),_jsx(ParamField,{path:`bus`,type:`anx_i2c_bus_t`,required:true,id:`param-bus-2`,children:_jsxs(_components.p,{children:[`The initialized I2C bus (`,_jsx(_components.code,{children:`ANX_I2C0`}),` or `,_jsx(_components.code,{children:`ANX_I2C1`}),`).`]})}),_jsx(ParamField,{path:`addr`,type:`uint8_t`,required:true,id:`param-addr-1`,children:_jsx(_components.p,{children:`The 7-bit I2C address of the target device.`})}),_jsx(ParamField,{path:`buf`,type:`uint8_t *`,required:true,id:`param-buf-1`,children:_jsxs(_components.p,{children:[`Pointer to the buffer that receives the read data. Must be at least `,_jsx(_components.code,{children:`len`}),` bytes long.`]})}),_jsx(ParamField,{path:`len`,type:`size_t`,required:true,id:`param-len-3`,children:_jsx(_components.p,{children:`Number of bytes to read from the device.`})}),_jsx(ResponseField,{name:`return`,type:`anx_err_t`,id:`param-return-3`,children:_jsxs(_components.p,{children:[_jsx(_components.code,{children:`ANX_OK`}),` on success. `,_jsx(_components.code,{children:`ANX_ERR_NOT_FOUND`}),` if the device does not acknowledge. `,_jsx(_components.code,{children:`ANX_ERR_TIMEOUT`}),` if the read does not complete in time.`]})}),_jsx(_components.hr,{}),_jsx(Heading,{level:`3`,id:`anx_i2c_scan`,children:_jsx(_components.code,{children:`anx_i2c_scan()`})}),_jsx(_components.p,{children:`Scans the bus and logs the 7-bit address of every device that sends an acknowledgement. Use this during development to verify that all sensors are wired correctly and that their addresses match your expectations.`}),_jsx(ParamField,{path:`bus`,type:`anx_i2c_bus_t`,required:true,id:`param-bus-3`,children:_jsxs(_components.p,{children:[`The initialized I2C bus to scan (`,_jsx(_components.code,{children:`ANX_I2C0`}),` or `,_jsx(_components.code,{children:`ANX_I2C1`}),`).`]})}),_jsx(ResponseField,{name:`return`,type:`anx_err_t`,id:`param-return-4`,children:_jsxs(_components.p,{children:[_jsx(_components.code,{children:`ANX_OK`}),` after the scan completes, regardless of how many devices responded.`]})}),_jsx(_components.hr,{}),_jsx(Heading,{level:`3`,id:`example-register-read-pattern`,children:`Example: register read pattern`}),_jsx(_components.p,{children:`Most I2C sensors use a register-based interface: write the register address you want to read, then read back the value in a separate transaction.`}),_jsx(CodeBlock,{filename:`i2c_register_read.c`,numberOfLines:`11`,language:`c`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`c`,children:_jsxs(_components.code,{language:`c`,numberOfLines:`11`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`#include`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"anx/anx.h\"`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`#include`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"anx/i2c.h\"`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// Read WHO_AM_I register (0x0F) from a device at address 0x19`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`void`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` read_who_am_i`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`void`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` uint8_t`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` reg `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#B5CEA8`},children:` 0x`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`0F`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` uint8_t`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` id;`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` anx_i2c_write`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(ANX_I2C0, `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#B5CEA8`},children:`0x`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`19`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`\u0026`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`reg, `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`1`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` anx_i2c_read`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(ANX_I2C0, `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#B5CEA8`},children:`0x`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`19`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`\u0026`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`id, `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`1`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` ANX_LOGI`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"I2C\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"WHO_AM_I = 0x`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#9CDCFE`},children:`%02X`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, id);`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`]})})}),_jsx(Note,{children:_jsxs(_components.p,{children:[`Some I2C devices require a repeated-start condition between the write and read phases. If `,_jsx(_components.code,{children:`anx_i2c_read()`}),` returns `,_jsx(_components.code,{children:`ANX_ERR_NOT_FOUND`}),` immediately after a successful write, check the device datasheet to see whether it supports repeated-start or requires a full stop/start sequence.`]})})]}),_jsxs(Tab,{title:`SPI`,id:`spi`,\"data-child-heading-ids\":`[\"spi-%E2%80%94-anx%2Fspi-h\",\"initialization-3\",\"anx_spi_config_t-members\",\"anx_spi_transfer\",\"chip-select-control\",\"anx_spi_cs_active\",\"anx_spi_cs_idle\",\"example%3A-spi-flash-read\"]`,children:[_jsxs(Heading,{level:`2`,id:`spi-—-anx/spi-h`,children:[`SPI — `,_jsx(_components.code,{children:`anx/spi.h`})]}),_jsx(_components.p,{children:`SPI is a synchronous, full-duplex serial protocol well suited for high-speed peripherals. Include the header to access the SPI API:`}),_jsx(CodeBlock,{filename:``,numberOfLines:`1`,language:`c`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`c`,children:_jsxs(_components.code,{language:`c`,numberOfLines:`1`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`#include`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"anx/spi.h\"`})]}),`\n`]})})}),_jsx(Heading,{level:`3`,id:`initialization-3`,children:`Initialization`}),_jsxs(_components.p,{children:[`Configure an SPI bus by populating an `,_jsx(_components.code,{children:`anx_spi_config_t`}),` struct and passing it to `,_jsx(_components.code,{children:`anx_spi_init()`}),`.`]}),_jsxs(Heading,{level:`4`,id:`anx_spi_config_t-members`,children:[_jsx(_components.code,{children:`anx_spi_config_t`}),` members`]}),_jsx(ParamField,{path:`bus`,type:`anx_spi_bus_t`,required:true,id:`param-bus-4`,children:_jsxs(_components.p,{children:[`The SPI bus to configure. Use `,_jsx(_components.code,{children:`ANX_SPI0`}),` for the primary SPI bus.`]})}),_jsx(ParamField,{path:`speed`,type:`uint32_t`,required:true,id:`param-speed-1`,children:_jsxs(_components.p,{children:[`Clock frequency in Hz. The maximum supported speed is `,_jsx(_components.code,{children:`40000000`}),` (40 MHz). Start at a lower speed (4–8 MHz) when debugging and raise it once the connection is verified stable.`]})}),_jsxs(ParamField,{path:`mode`,type:`anx_spi_mode_t`,required:true,id:`param-mode`,children:[_jsx(_components.p,{children:`SPI clock polarity and phase. Choose from:`}),_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.code,{children:`ANX_SPI_MODE0`}),` — CPOL=0, CPHA=0 (clock idles low, data sampled on rising edge)`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.code,{children:`ANX_SPI_MODE1`}),` — CPOL=0, CPHA=1 (clock idles low, data sampled on falling edge)`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.code,{children:`ANX_SPI_MODE2`}),` — CPOL=1, CPHA=0 (clock idles high, data sampled on falling edge)`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.code,{children:`ANX_SPI_MODE3`}),` — CPOL=1, CPHA=1 (clock idles high, data sampled on rising edge)`]}),`\n`]})]}),_jsx(ResponseField,{name:`anx_spi_init return`,type:`anx_err_t`,id:`param-anx-spi-init-return`,children:_jsxs(_components.p,{children:[_jsx(_components.code,{children:`ANX_OK`}),` on success. `,_jsx(_components.code,{children:`ANX_ERR_INVALID_ARG`}),` if `,_jsx(_components.code,{children:`speed`}),` exceeds 40 MHz or `,_jsx(_components.code,{children:`mode`}),` is not valid. `,_jsx(_components.code,{children:`ANX_ERR_FAIL`}),` if the bus is already initialized.`]})}),_jsx(_components.hr,{}),_jsx(Heading,{level:`3`,id:`anx_spi_transfer`,children:_jsx(_components.code,{children:`anx_spi_transfer()`})}),_jsxs(_components.p,{children:[`Performs a full-duplex SPI transfer, simultaneously clocking out `,_jsx(_components.code,{children:`len`}),` bytes from `,_jsx(_components.code,{children:`tx`}),` and clocking in `,_jsx(_components.code,{children:`len`}),` bytes into `,_jsx(_components.code,{children:`rx`}),`. Pass NULL for `,_jsx(_components.code,{children:`tx`}),` to receive only (MOSI held low), or NULL for `,_jsx(_components.code,{children:`rx`}),` to transmit only (MISO ignored).`]}),_jsx(ParamField,{path:`bus`,type:`anx_spi_bus_t`,required:true,id:`param-bus-5`,children:_jsxs(_components.p,{children:[`The initialized SPI bus (`,_jsx(_components.code,{children:`ANX_SPI0`}),`).`]})}),_jsx(ParamField,{path:`tx`,type:`const uint8_t *`,id:`param-tx`,children:_jsx(_components.p,{children:`Pointer to the transmit buffer. Pass NULL to send zeroed bytes (receive-only operation).`})}),_jsx(ParamField,{path:`rx`,type:`uint8_t *`,id:`param-rx`,children:_jsxs(_components.p,{children:[`Pointer to the receive buffer. Must be at least `,_jsx(_components.code,{children:`len`}),` bytes long if non-NULL. Pass NULL to discard incoming data (transmit-only operation).`]})}),_jsx(ParamField,{path:`len`,type:`size_t`,required:true,id:`param-len-4`,children:_jsxs(_components.p,{children:[`Number of bytes to transfer. Both `,_jsx(_components.code,{children:`tx`}),` and `,_jsx(_components.code,{children:`rx`}),` (when non-NULL) must be at least this long.`]})}),_jsx(ResponseField,{name:`return`,type:`anx_err_t`,id:`param-return-5`,children:_jsxs(_components.p,{children:[_jsx(_components.code,{children:`ANX_OK`}),` on success. `,_jsx(_components.code,{children:`ANX_ERR_INVALID_ARG`}),` if both `,_jsx(_components.code,{children:`tx`}),` and `,_jsx(_components.code,{children:`rx`}),` are NULL, or if `,_jsx(_components.code,{children:`len`}),` is zero. `,_jsx(_components.code,{children:`ANX_ERR_TIMEOUT`}),` if the transfer does not complete within the hardware timeout.`]})}),_jsx(_components.hr,{}),_jsx(Heading,{level:`3`,id:`chip-select-control`,children:`Chip-Select Control`}),_jsx(_components.p,{children:`The ANX SPI API gives you manual control over the chip-select (CS) line so you can compose multi-transfer transactions without deselecting the device between calls.`}),_jsx(Heading,{level:`4`,id:`anx_spi_cs_active`,children:_jsx(_components.code,{children:`anx_spi_cs_active()`})}),_jsx(_components.p,{children:`Asserts the chip-select line (drives it low) to begin a transaction.`}),_jsx(ParamField,{path:`bus`,type:`anx_spi_bus_t`,required:true,id:`param-bus-6`,children:_jsx(_components.p,{children:`The initialized SPI bus whose CS line you want to assert.`})}),_jsx(ResponseField,{name:`return`,type:`anx_err_t`,id:`param-return-6`,children:_jsxs(_components.p,{children:[_jsx(_components.code,{children:`ANX_OK`}),` on success.`]})}),_jsx(Heading,{level:`4`,id:`anx_spi_cs_idle`,children:_jsx(_components.code,{children:`anx_spi_cs_idle()`})}),_jsx(_components.p,{children:`Deasserts the chip-select line (drives it high) to end a transaction.`}),_jsx(ParamField,{path:`bus`,type:`anx_spi_bus_t`,required:true,id:`param-bus-7`,children:_jsx(_components.p,{children:`The initialized SPI bus whose CS line you want to release.`})}),_jsx(ResponseField,{name:`return`,type:`anx_err_t`,id:`param-return-7`,children:_jsxs(_components.p,{children:[_jsx(_components.code,{children:`ANX_OK`}),` on success.`]})}),_jsx(_components.hr,{}),_jsx(Heading,{level:`3`,id:`example-spi-flash-read`,children:`Example: SPI flash read`}),_jsx(CodeBlock,{filename:`spi_flash_read.c`,numberOfLines:`23`,language:`c`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`c`,children:_jsxs(_components.code,{language:`c`,numberOfLines:`23`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`#include`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"anx/anx.h\"`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`#include`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"anx/spi.h\"`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// Read 4 bytes from SPI flash at address 0x001000`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`void`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` read_spi_flash`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`void`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:` anx_spi_config_t`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` cfg `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` .bus `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ANX_SPI0,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` .speed `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 4000000`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` // 4 MHz`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` .mode `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ANX_SPI_MODE0,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` };`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` anx_spi_init`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`\u0026`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`cfg);`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` uint8_t`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` cmd`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`[]`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#B5CEA8`},children:`0x`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`03`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#B5CEA8`},children:`0x`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`00`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#B5CEA8`},children:`0x`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`10`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#B5CEA8`},children:`0x`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`00`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`};`}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` // READ cmd + 24-bit addr`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` uint8_t`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` data`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`[`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`4`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`];`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` anx_spi_cs_active`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(ANX_SPI0);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` anx_spi_transfer`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(ANX_SPI0, cmd, `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:`NULL`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`4`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` // send command`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` anx_spi_transfer`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(ANX_SPI0, `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:`NULL`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, data, `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`4`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` // receive data`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` anx_spi_cs_idle`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(ANX_SPI0);`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` ANX_LOGI`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"SPI\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Data: `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#9CDCFE`},children:`%02X`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#9CDCFE`},children:` %02X`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#9CDCFE`},children:` %02X`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#9CDCFE`},children:` %02X`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` data`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`[`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`0`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`], `}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`data`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`[`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`1`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`], `}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`data`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`[`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`2`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`], `}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`data`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`[`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`3`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`]);`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`]})})}),_jsx(Warning,{children:_jsxs(_components.p,{children:[`Always call `,_jsx(_components.code,{children:`anx_spi_cs_idle()`}),` after every transaction — even if `,_jsx(_components.code,{children:`anx_spi_transfer()`}),` returns an error. Leaving the CS line asserted prevents other devices that share the same SPI bus from communicating and may lock up the bus until the next reboot.`]})}),_jsx(Accordion,{title:`Choosing the correct SPI mode`,id:`choosing-the-correct-spi-mode`,children:_jsxs(_components.p,{children:[`Consult your peripheral’s datasheet and look for the CPOL and CPHA timing diagrams in the electrical characteristics section. Most SPI flash and display controllers use `,_jsx(_components.code,{children:`ANX_SPI_MODE0`}),`. If you see corrupted data at higher clock speeds, try lowering the frequency first before switching the mode — a marginal PCB trace is more commonly the culprit than a mode mismatch.`]})})]})]})]})}function MDXContent(props={}){const{wrapper:MDXLayout}={..._provideComponents(),...props.components};return MDXLayout?_jsx(MDXLayout,{...props,children:_jsx(_createMdxContent,{...props})}):_createMdxContent(props)}return{default:MDXContent};function _missingMdxReference(id,component){throw new Error(`Expected `+(component?`component`:`object`)+\" `\"+id+\"` to be defined: you likely forgot to import, pass, or provide it.\")}","frontmatter":{},"scope":{"config":{},"pageMetadata":{"title":"ANX SDK Communication APIs: UART, I2C, and SPI","sidebarTitle":"Communication","description":"Send and receive data over UART, I2C, and SPI using the ANX SDK communication APIs. Includes configuration structs, read/write functions, and error handling.","href":"/api/communication"}}},"mdxSourceWithNoJs":null},"mdxExtracts":{"tableOfContents":[{"title":"UART — anx/uart.h","slug":"uart-—-anx/uart-h","depth":2,"children":[{"title":"Initialization","slug":"initialization","depth":3,"children":[],"tabId":"uart"},{"title":"anx_uart_config_t members","slug":"anx_uart_config_t-members","depth":4,"children":[],"tabId":"uart"},{"title":"anx_uart_write()","slug":"anx_uart_write","depth":3,"children":[],"tabId":"uart"},{"title":"anx_uart_read()","slug":"anx_uart_read","depth":3,"children":[],"tabId":"uart"},{"title":"Example: UART loopback test","slug":"example-uart-loopback-test","depth":3,"children":[],"tabId":"uart"}],"tabId":"uart"},{"title":"I2C — anx/i2c.h","slug":"i2c-—-anx/i2c-h","depth":2,"children":[{"title":"Initialization","slug":"initialization-2","depth":3,"children":[],"tabId":"i2c"},{"title":"anx_i2c_config_t members","slug":"anx_i2c_config_t-members","depth":4,"children":[],"tabId":"i2c"},{"title":"anx_i2c_write()","slug":"anx_i2c_write","depth":3,"children":[],"tabId":"i2c"},{"title":"anx_i2c_read()","slug":"anx_i2c_read","depth":3,"children":[],"tabId":"i2c"},{"title":"anx_i2c_scan()","slug":"anx_i2c_scan","depth":3,"children":[],"tabId":"i2c"},{"title":"Example: register read pattern","slug":"example-register-read-pattern","depth":3,"children":[],"tabId":"i2c"}],"tabId":"i2c"},{"title":"SPI — anx/spi.h","slug":"spi-—-anx/spi-h","depth":2,"children":[{"title":"Initialization","slug":"initialization-3","depth":3,"children":[],"tabId":"spi"},{"title":"anx_spi_config_t members","slug":"anx_spi_config_t-members","depth":4,"children":[],"tabId":"spi"},{"title":"anx_spi_transfer()","slug":"anx_spi_transfer","depth":3,"children":[],"tabId":"spi"},{"title":"Chip-Select Control","slug":"chip-select-control","depth":3,"children":[],"tabId":"spi"},{"title":"anx_spi_cs_active()","slug":"anx_spi_cs_active","depth":4,"children":[],"tabId":"spi"},{"title":"anx_spi_cs_idle()","slug":"anx_spi_cs_idle","depth":4,"children":[],"tabId":"spi"},{"title":"Example: SPI flash read","slug":"example-spi-flash-read","depth":3,"children":[],"tabId":"spi"}],"tabId":"spi"}],"codeExamples":{}},"jsLinks":[],"subdomain":"anx-labs","siteName":"ANX Labs","title":"ANX SDK Communication APIs: UART, I2C, and SPI - ANX Labs","navMaps":{"firstHrefInVersion":{},"firstHrefInLanguage":{}},"lastModified":"2026-07-17T14:27:25.073Z","originalFileLocation":"api/communication.mdx"},"headHtml":"\u003cscript data-mint-head>(function(){var d=document.documentElement,p=null;if(!p){try{p=localStorage.getItem(\"isDarkMode\")}catch(e){}if(p==='true')p='dark';else if(p==='false')p='light';if(p!=='light'\u0026\u0026p!=='dark'\u0026\u0026p!=='system')p=\"system\"}var r=p==='system'?(matchMedia(\"(prefers-color-scheme: dark)\").matches?'dark':'light'):p;d.classList.remove(r==='dark'?'light':'dark');d.classList.add(r);d.setAttribute(\"data-theme-preference\",p)})();\u003c/script>\u003cmeta data-mint-head name=\"description\" content=\"Send and receive data over UART, I2C, and SPI using the ANX SDK communication APIs. Includes configuration structs, read/write functions, and error handling.\">\u003cmeta data-mint-head name=\"application-name\" content=\"ANX Labs\">\u003cmeta data-mint-head name=\"generator\" content=\"Mintlify\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/anx-labs/z-GSEWZrCxjpatX7/_generated/favicon/android-chrome-192x192.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"apple-touch-icon\" type=\"image/png\" sizes=\"180x180\" href=\"/mintlify-assets/_mintlify/favicons/anx-labs/z-GSEWZrCxjpatX7/_generated/favicon/apple-touch-icon.png\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/anx-labs/z-GSEWZrCxjpatX7/_generated/favicon/favicon-16x16.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/anx-labs/z-GSEWZrCxjpatX7/_generated/favicon/favicon-32x32.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/anx-labs/z-GSEWZrCxjpatX7/_generated/favicon/favicon.ico\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/anx-labs/z-GSEWZrCxjpatX7/_generated/favicon-dark/android-chrome-192x192.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/anx-labs/z-GSEWZrCxjpatX7/_generated/favicon-dark/favicon-16x16.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/anx-labs/z-GSEWZrCxjpatX7/_generated/favicon-dark/favicon-32x32.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/anx-labs/z-GSEWZrCxjpatX7/_generated/favicon-dark/favicon.ico\" media=\"(prefers-color-scheme: dark)\">\u003cmeta data-mint-head property=\"og:title\" content=\"ANX SDK Communication APIs: UART, I2C, and SPI - ANX Labs\">\u003cmeta data-mint-head property=\"og:description\" content=\"Send and receive data over UART, I2C, and SPI using the ANX SDK communication APIs. Includes configuration structs, read/write functions, and error handling.\">\u003cmeta data-mint-head property=\"og:site_name\" content=\"ANX Labs\">\u003cmeta data-mint-head property=\"og:url\" content=\"https://launchpad.anxlabs.com/api/communication\">\u003cmeta data-mint-head property=\"og:type\" content=\"website\">\u003cmeta data-mint-head property=\"og:image\" content=\"https://anx-labs.mintlify.site/_mintlify/api/og/v2?division=SDK\u0026amp;title=ANX+SDK+Communication+APIs%3A+UART%2C+I2C%2C+and+SPI\u0026amp;description=Send+and+receive+data+over+UART%2C+I2C%2C+and+SPI+using+the+ANX+SDK+communication+APIs.+Includes+configuration+structs%2C+read%2Fwrite+functions%2C+and+error+handling.\u0026amp;theme=c2f844e4eb2bbb817b1fc1a7\u0026amp;signature=2f719c23eba21087ade02e2f5b568d934c7f338dfcec6192615f9d29ec2bdd3d\">\u003cmeta data-mint-head property=\"og:image:width\" content=\"1200\">\u003cmeta data-mint-head property=\"og:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"twitter:card\" content=\"summary_large_image\">\u003cmeta data-mint-head name=\"twitter:title\" content=\"ANX SDK Communication APIs: UART, I2C, and SPI - ANX Labs\">\u003cmeta data-mint-head name=\"twitter:description\" content=\"Send and receive data over UART, I2C, and SPI using the ANX SDK communication APIs. Includes configuration structs, read/write functions, and error handling.\">\u003cmeta data-mint-head name=\"twitter:image\" content=\"https://anx-labs.mintlify.site/_mintlify/api/og/v2?division=SDK\u0026amp;title=ANX+SDK+Communication+APIs%3A+UART%2C+I2C%2C+and+SPI\u0026amp;description=Send+and+receive+data+over+UART%2C+I2C%2C+and+SPI+using+the+ANX+SDK+communication+APIs.+Includes+configuration+structs%2C+read%2Fwrite+functions%2C+and+error+handling.\u0026amp;theme=c2f844e4eb2bbb817b1fc1a7\u0026amp;signature=2f719c23eba21087ade02e2f5b568d934c7f338dfcec6192615f9d29ec2bdd3d\">\u003cmeta data-mint-head name=\"twitter:image:width\" content=\"1200\">\u003cmeta data-mint-head name=\"twitter:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"msapplication-config\" content=\"/mintlify-assets/_mintlify/favicons/anx-labs/z-GSEWZrCxjpatX7/_generated/favicon/browserconfig.xml\">\u003cmeta data-mint-head name=\"apple-mobile-web-app-title\" content=\"ANX Labs\">\u003cmeta data-mint-head name=\"msapplication-TileColor\" content=\"#ef7025\">\u003clink data-mint-head rel=\"canonical\" href=\"https://launchpad.anxlabs.com/api/communication\">\u003clink data-mint-head rel=\"alternate\" type=\"application/xml\" href=\"/sitemap.xml\">\u003clink data-mint-head rel=\"alternate\" type=\"text/markdown\" href=\"/api/communication.md\">\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https://launchpad.anxlabs.com/#organization\",\"name\":\"ANX Labs\",\"url\":\"https://launchpad.anxlabs.com\"},{\"@type\":\"WebSite\",\"@id\":\"https://launchpad.anxlabs.com#website\",\"name\":\"ANX Labs\",\"url\":\"https://launchpad.anxlabs.com\",\"publisher\":{\"@id\":\"https://launchpad.anxlabs.com/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https://launchpad.anxlabs.com/api/communication#webpage\",\"url\":\"https://launchpad.anxlabs.com/api/communication\",\"name\":\"ANX SDK Communication APIs: UART, I2C, and SPI\",\"description\":\"Send and receive data over UART, I2C, and SPI using the ANX SDK communication APIs. Includes configuration structs, read/write functions, and error handling.\",\"dateModified\":\"2026-07-17T14:27:25.073Z\",\"isPartOf\":{\"@id\":\"https://launchpad.anxlabs.com#website\"},\"breadcrumb\":{\"@id\":\"https://launchpad.anxlabs.com/api/communication#breadcrumb\"}},{\"@type\":\"BreadcrumbList\",\"@id\":\"https://launchpad.anxlabs.com/api/communication#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"SDK\",\"item\":\"https://launchpad.anxlabs.com/api/overview\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"ANX SDK Communication APIs: UART, I2C, and SPI\",\"item\":\"https://launchpad.anxlabs.com/api/communication\"}]},{\"@type\":[\"Article\",\"TechArticle\"],\"@id\":\"https://launchpad.anxlabs.com/api/communication#article\",\"headline\":\"ANX SDK Communication APIs: UART, I2C, and SPI\",\"name\":\"ANX SDK Communication APIs: UART, I2C, and SPI\",\"description\":\"Send and receive data over UART, I2C, and SPI using the ANX SDK communication APIs. Includes configuration structs, read/write functions, and error handling.\",\"url\":\"https://launchpad.anxlabs.com/api/communication\",\"mainEntityOfPage\":{\"@id\":\"https://launchpad.anxlabs.com/api/communication#webpage\"},\"dateModified\":\"2026-07-17T14:27:25.073Z\",\"publisher\":{\"@id\":\"https://launchpad.anxlabs.com/#organization\"},\"isPartOf\":{\"@id\":\"https://launchpad.anxlabs.com#website\"}}]}\u003c/script>\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@type\":\"WebSite\",\"name\":\"ANX Labs\",\"publisher\":{\"@type\":\"Organization\",\"name\":\"ANX Labs\"},\"provider\":{\"@type\":\"Organization\",\"name\":\"Mintlify\",\"url\":\"https://mintlify.com\"}}\u003c/script>","agentPointerHref":"/api/communication.md","siteName":"ANX Labs","nav":{"global":null,"tabs":[{"tab":"Documentation","pages":[{"title":"Documentation","href":"/introduction"}]},{"tab":"API Reference","groups":[{"group":"SDK","pages":[{"title":"ANX SDK Reference: Modules and Architecture","sidebarTitle":"Overview","href":"/api/overview"},{"title":"ANX SDK Initialization and System Functions","sidebarTitle":"Initialization","href":"/api/initialization"},{"title":"ANX SDK GPIO API: Digital I/O Control","sidebarTitle":"GPIO","description":"Configure GPIO pins as input or output, read and write digital values, enable pull resistors, and attach interrupt handlers using the ANX SDK GPIO API.","href":"/api/gpio"},{"title":"ANX SDK Communication APIs: UART, I2C, and SPI","sidebarTitle":"Communication","href":"/api/communication"}]}]}]},"basePath":"","title":"ANX SDK Communication APIs: UART, I2C, and SPI - ANX Labs","buildId":"dpl_Fyv1NbzwP68g2bEH2Roy98uY1zmE","deploymentId":"dpl_Fyv1NbzwP68g2bEH2Roy98uY1zmE","dynamics":[],"chunks":[]}