I am working with a max112010 a2d chip and need to use spi interface to read the a2d data. The a2d data is stored in 24bit data register. The example shows how one can read a register. There are control registers that I need to WRITE to them and I am not clear how that is done. I have tried consecutive write commands with the register address first and then the command number but all I am getting is 0xFF from all registers. I have tired different clock polarity and phase values as well. I would appreciate any comments or feedback on my code bellow.
- include "mbed.h"
- define STAT1 0x0
- define CTRL1 0x1
- define CTRL2 0x2
- define CTRL3 0x3
- define DATAR 0x4
- define CTRL1C 0x88
function defintion
void calibrate11200(void);
void reset(void);
SPI spi(p11, p12, p13); mosi, miso, sclk
SPI spi(p5, p6, p7); mosi, miso, sclk
DigitalOut cs(p8);
Serial pc(USBTX, USBRX); tx, rx
int main()
{
Setup the spi for 8 bit data, high steady state clock,
second edge capture, with a 1MHz clock rate
spi.format(8,0); format ( # of bits, poloarti = 0,1,2,3)
spi.frequency(5000000); spi clock frequency 5MHz (ds, page 4)
reset();
while(1)
{
pc.printf(".......................begine whil loop here \n\r");
cs = 0; Select the device by seting chip select low
calibrate11200(); see calibration fun.
spi.write(STAT1);
int stat1returns = spi.write(0x00);
pc.printf("STAT1 returned = 0x%X \r\n", stat1returns);
spi.write(CTRL1);
int CTRL1returns = spi.write(CTRL1C);
pc.printf("CTRL1 returned = 0x%X \r\n", CTRL1returns);
spi.write(DATAR);
int data1 = spi.write(0x00);
pc.printf("data1 register = 0x%X \r\n", data1);
pc.printf("\n\r.......................loop ended here \n\r");
cs = 1;
}
}
I am working with a max112010 a2d chip and need to use spi interface to read the a2d data. The a2d data is stored in 24bit data register. The example shows how one can read a register. There are control registers that I need to WRITE to them and I am not clear how that is done. I have tried consecutive write commands with the register address first and then the command number but all I am getting is 0xFF from all registers. I have tired different clock polarity and phase values as well. I would appreciate any comments or feedback on my code bellow.
function defintion void calibrate11200(void); void reset(void);
SPI spi(p11, p12, p13); mosi, miso, sclk SPI spi(p5, p6, p7); mosi, miso, sclk DigitalOut cs(p8);
Serial pc(USBTX, USBRX); tx, rx
int main() { Setup the spi for 8 bit data, high steady state clock, second edge capture, with a 1MHz clock rate spi.format(8,0); format ( # of bits, poloarti = 0,1,2,3) spi.frequency(5000000); spi clock frequency 5MHz (ds, page 4) reset(); while(1) { pc.printf(".......................begine whil loop here \n\r"); cs = 0; Select the device by seting chip select low calibrate11200(); see calibration fun. spi.write(STAT1); int stat1returns = spi.write(0x00); pc.printf("STAT1 returned = 0x%X \r\n", stat1returns);
spi.write(CTRL1); int CTRL1returns = spi.write(CTRL1C); pc.printf("CTRL1 returned = 0x%X \r\n", CTRL1returns);
spi.write(DATAR); int data1 = spi.write(0x00); pc.printf("data1 register = 0x%X \r\n", data1); pc.printf("\n\r.......................loop ended here \n\r"); cs = 1; } }