uint16_t lmx2595_read_register(uint8_t regAddr) { uint8_t tx[3] = { (0x80 | regAddr), 0x00, 0x00 }; uint8_t rx[3]; // Clear RX FIFO first SPI_clearRxFIFO(SPIA_BASE); // --- Send 24-bit read command (3 writes = 24 clocks) --- SPI_writeDataBlockingFIFO(SPIA_BASE, tx[0] << 8); // Send MSB SPI_writeDataBlockingFIFO(SPIA_BASE, tx[1] << 8); // Send mid SPI_writeDataBlockingFIFO(SPIA_BASE, tx[2] << 8); // Send LSB // Wait for TX complete while(SPI_isBusy(SPIA_BASE)); // Wait until 3 bytes are received in RX FIFO while(SPI_getRxFIFOStatus(SPIA_BASE) < 3); // --- Read the 3 response bytes from RX FIFO --- rx[0] = (uint8_t)(SPI_readDataBlockingFIFO(SPIA_BASE) >> 8); rx[1] = (uint8_t)(SPI_readDataBlockingFIFO(SPIA_BASE) >> 8); rx[2] = (uint8_t)(SPI_readDataBlockingFIFO(SPIA_BASE) >> 8); // Combine middle and last bytes to get 16-bit register value uint16_t regVal = ((uint16_t)rx[1] << 8) | rx[2]; return regVal; }