I'm working on a driver for an SPI device that returns some data (device status) while the command byte is still being written. Is there a way to read this status data using standard Arduino APIs or do I need to bit-bang to access it?
Here's what the SPI signals look like:
The 6 bits in red are the ones I'm interested in reading.
For context, the device in question is a Microchip MCP3561 ADC (MCP3X6X series). It has a bug (erratum 2) where the new-data-ready flag (/DR_STATUS
) is not always set correctly. Part of the work-around involves reading the status bits mentioned above.
1 Answer 1
The SPI.transfer()
method is designed to send a byte through
the SPI port and, at the same time receive an incoming byte.
Usage pattern:
uint8_t byte_to_send = ...;
uint8_t received_byte = SPI.transfer(byte_to_send);
-
Turns out the bug was elsewhere in my code. This works fine. Thanks!Alex Hajnal– Alex Hajnal2021年02月27日 13:35:37 +00:00Commented Feb 27, 2021 at 13:35