This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

AFE4300: Can SPI write properly but cannot SPI read properly

Part Number: AFE4300

Hi,

I am encountering an odd issue with my AFE4300. I can write values to the registers, but cannot read them back properly sometimes. I am indeed writing either a desired value or the previous value back to the register immediately after read. I am in SPI_MODE_1 (CPHA = 1).

My current program, running on a TI Beaglebone Black, after RESET of the AFE4300:

1) reads 0x8000 from MISC_REG1 and writes 0x0000 back to it
2) reads 0x7FFF from MISC_REG2 and writes 0xFFFF back to it
3) reads 0x0000 from MISC_REG3 and writes 0x0000 back to it
4) reads 0x0000 from DEVICE_CONTROL1 and writes 0x6006 to it
5) if I check the VREF pin, it is indeed activated to 1.7V
6) reads 0xFFFF (instead of the expected 0x6006) from DEVICE_CONTROL1 and writes 0x6005 to it
7) if I check the VLDO pin, it is indeed activated to 1.7V, and the VREF pin is no longer activated.
8) Any read after this results in 0xFFFF (on the SDOUT line, nothing is changing, but all other signals are correct).

I am baffled as to why the AFE4300 seems to be sending the right data sometimes (at the very beginning), and then stops sending data pretty much at all.

Here is my read function:

	uint16_t __transferRead(const uint8_t& address, const uint16_t& value, bool use_value = false) {
		const uint16_t upperbyte = 0xFF00;
		const uint16_t lowerbyte = 0x00FF;
		const uint8_t readaddr = 0x20;
		//uint8_t send[3] = { (address | readaddr), (value & upperbyte) >> 8, (value & lowerbyte) };
		uint8_t send[3] = { (readaddr | address), 0x00, 0x00};
		uint8_t recv[3];
		usleep(2);
		__spidev.transfer_block(send, recv, 3);
		uint16_t returnval = (recv[1] << 8) | recv[2];
		if (use_value == true) {
			__transferWrite(address, value);
		}
		else {
			__transferWrite(address, returnval);
		}
		return returnval;
	}