Pynq Z1
Image Version 2.4
I am trying to code a driver for the Pmod AD5. I am using the example pmod codes for a starting point, specifically the ALS example, for how to code an SPI read device, and the DAC example for how to code an SPI write device. I cannot although find an example where a pmod initiates a write + read in the same spi_transfer() call.
The Pmod AD5 uses the AD7193 chip, which the datasheet states: “All communications to the part must start with a write operation to the communications register.”
So, for example, in order to read the data register, I must write 8 bits to the comms register, and then read 24 bits from the data register.
My question is should I put both the write and read buffer arrays of different sizes in the same spi_transfer call? Or is it correct to have separate calls?
Here is part of my code, I am trying to read the state of the configuration register, which defaults to a value of 0x000117 on “Power On” of the device.
u32 get_configuration(){
/*
* Sends a read command for the Configuration Register 01010000
* Then returns the configuration
*/
WriteBuffer[0] = 0x50;
u8 Configuration[3];
spi_transfer(device, (char*)WriteBuffer, NULL, 1);
spi_transfer(device, NULL, (char*)Configuration, 3);
u32 v = ((Configuration[0] << 16) + (Configuration[1] << 8) + (Configuration[2]));
return v;
}
I call the function in Jupyter using the following:
conf = adc.read_config()
print(conf)
'{:032b}'.format(conf)
The output I get is not the expected value of 0x000117. (Nor is it a consistent value)
My full code is linked below.
Project Files (C code, Python code, bin file, Jupyter file)
PmodAD5 Reference Manual
AD7193 Datasheet