A
Size: a a a
A
RC
//send data
switch(bytes)
{
case 3:
_spi.write(((value >> 16) & 255));
case 2:
_spi.write(((value >> 8) & 255));
case 1:
_spi.write((value & 255));
break;
default:
break;
}
RC
RC
/************************************************************************************************************************/
//function to initiate the conversion of a sample
/************************************************************************************************************************/
int AD7730::startConversion(bool wait){
//set the mode to do a single conversion
//0101000100000000 (0x5000) Single Conversion, unipolar, short data, low reference, 0-10mv, channel 0
int mode = 0x5100;
writeRegistry(MODE_REG, mode);
if(wait){
//wait for conversion to complete
wait_us(1); //give time for ready to go high*/
int time = 0;
while(_readyDig && time < 2000000){
time += 2;
wait_us(2);
}//wait for ready pin to go low.*/
if(time >= 2000000){
//printf("Convert Timeout\r\n");
_exeError = 56;
return 1;
}
}
return 0;
}
A
RC
RC
A
r
RC
RC
#include "mbed.h"
SPI spi(p5, p6, p7); // mosi, miso, sclk
DigitalOut cs(p8);
int main() {
// Chip must be deselected
cs = 1;
// Setup the spi for 8 bit data, high steady state clock,
// second edge capture, with a 1MHz clock rate
spi.format(8,3);
spi.frequency(1000000);
// Select the device by seting chip select low
cs = 0;
// Send 0x8f, the command to read the WHOAMI register
spi.write(0x8F);
// Send a dummy byte to receive the contents of the WHOAMI register
int whoami = spi.write(0x00);
printf("WHOAMI register = 0x%X\n", whoami);
// Deselect the device
cs = 1;
}
A
r
A
A
СС
RC
A
A
A