MAX1270 12 Bit A/D-Wandler am IO-Warrior

Die Hardware...

... Ansteuerung des MAX1270 ...

... und die Programmierung

int ret;
uint8_t data[2];
/* MAX1270 uses CPOL=0 and CPHA=1 */
/* mode = 0000,CPOL,CPHA,DR,DR */
/* DR,DR = 0,0 => 0.0625 MBits/sec */
if(iow_spi_enable(h, 0x07) < 0) {
	fprintf(stderr, "error: could not enable the spi bus\n");
	return -1;
}
/* Control Byte: 1CCCRBPP => C=channel, 0-5 Volt RB=0, PP=0 */
data[0]=0x80|((chan&0x07)<<4);
if(iow_spi_io(h, 0x00, data, 1) < 0) {
	fprintf(stderr, "spi bus error\n");
	iow_spi_disable(h);
	return -1;
}
data[0]=0;
data[1]=0;
if(iow_spi_io(h, 0x00, data, 2) < 0) {
	fprintf(stderr, "spi bus error\n");
	iow_spi_disable(h);
	return -1;
}
ret=(data[0]<<4)|(data[1]>>4);
printf("Raw = %03x = %f Volt\n", ret, (ret/4096.0)*5.0);
iow_spi_disable(h);

Komplettes Codebeispiel zum download: spi_max1270.c