{"record":{"id":"d7cac02808bce7c0","repo":"embassy-rs/embassy","slug":"consecutive-read-operations-are-not-supported","errorCode":null,"errorMessage":"Consecutive read operations are not supported!","messagePattern":"Consecutive read operations are not supported!","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"embassy-nrf/src/twim.rs","lineNumber":434,"sourceCode":"\n        if inten {\n            r.intenset().write(|w| {\n                w.set_suspended(true);\n                w.set_stopped(true);\n                w.set_error(true);\n            });\n        } else {\n            r.intenclr().write(|w| {\n                w.set_suspended(true);\n                w.set_stopped(true);\n                w.set_error(true);\n            });\n        }\n\n        assert!(!operations.is_empty());\n        match operations {\n            [Operation::Read(_), Operation::Read(_), ..] => {\n                panic!(\"Consecutive read operations are not supported!\")\n            }\n            [Operation::Read(rd_buffer), Operation::Write(wr_buffer), rest @ ..] => {\n                let stop = rest.is_empty();\n\n                // Set up DMA buffers.\n                unsafe {\n                    self.set_tx_buffer(wr_buffer)?;\n                    self.set_rx_buffer(rd_buffer)?;\n                }\n\n                r.shorts().write(|w| {\n                    w.set_lastrx_dma_tx_start(true);\n                    if stop {\n                        w.set_lasttx_stop(true);\n                    } else {\n                        w.set_lasttx_suspend(true);\n                    }\n                });","sourceCodeStart":416,"sourceCodeEnd":452,"githubUrl":"https://github.com/embassy-rs/embassy/blob/463a07b963419a1bfe61d5d597c44acb810afb8b/embassy-nrf/src/twim.rs#L416-L452","documentation":"The TWIM (I2C master) driver's transaction helper validates the operation sequence before programming the peripheral. The nRF TWIM hardware cannot perform two back-to-back receive transactions because a repeated-start must be issued between reads, and the driver does not synthesize one automatically. Instead of mis-sequencing DMA transfers, it panics with this message. Callers must merge consecutive reads or insert a write between them.","triggerScenarios":"Calling `twim.blocking_transaction`, `blocking_transaction_timeout`, or `transaction` with an operations slice beginning with `[Operation::Read(..), Operation::Read(..), ..]` — i.e. two or more Operation::Read entries where the first two are adjacent.","commonSituations":"Porting code that issued register-write then multi-chunk reads as separate operations; sensor drivers that read several register banks in one transaction; converting blocking read() calls into a multi-operation transaction and listing two reads back to back.","solutions":["Merge the consecutive reads into a single Operation::Read with one buffer sized to hold all expected bytes.","If the device requires separate reads, split into two separate transactions (issuing a STOP between them).","Reorder operations so a Write separates the two Read operations if the device protocol allows repeated start with write in between.","Split into two separate transactions (each read gets its own START/STOP)."],"exampleFix":"// before\nlet mut ops = [Operation::Write(&[0x00]), Operation::Read(&mut buf1), Operation::Read(&mut buf2)];\ntwim.blocking_transaction(addr, &mut ops)?;\n// after\nlet mut combined = [0u8; buf1.len() + buf2.len()];\nlet mut ops = [Operation::Write(&[0x00]), Operation::Read(&mut combined)];\ntwim.blocking_transaction(addr, &mut ops)?;\n// then split `combined` into buf1/buf2","handlingStrategy":"validation","validationCode":"fn validate_ops(ops: &[Operation]) -> bool {\n    ops.windows(2).all(|w| !matches!(w, [Operation::Read(_), Operation::Read(_)]))\n}\nassert!(validate_ops(&ops), \"consecutive reads unsupported on TWIM\");","typeGuard":"fn has_consecutive_reads(ops: &[Operation]) -> bool {\n    ops.windows(2).any(|w| matches!(w, [Operation::Read(_), Operation::Read(_)]))\n}","tryCatchPattern":null,"preventionTips":["Build a helper that coalesces adjacent Read operations into one buffered read before calling transaction APIs.","Model I2C transactions as write-then-read pairs, which is what most devices actually require.","Write a unit test over your operation builders asserting no adjacent reads."],"tags":["embedded","i2c","twim","nrf","panic"],"backgroundTag":"unsupported-operation","analyzedSha":"463a07b963419a1bfe61d5d597c44acb810afb8b","analyzedAt":"2026-09-10T13:38:26.660Z","contentChangedAt":"2026-09-10T13:38:26.660Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}