HI,
i already posted my problem in Arduino DUE section , but no response . Kindly help me .
i am trying to connect the AFE4300 ADC to DUE .
it supposed to make RDY pin toggle at every 8uS once its registers set properly .
but the chip not responding at all .
i am sure my hardware connections are right . i attached my code and the signal from logic analyzer .
The chip ADC clock 1MHz is generated from Logic analyzer .
Connection diagram attached , code formatted . thanks.
here is my code :
#include <SPI.h>
// pins
#define PIN_RESET 9
#define PIN_DRDY 2
#define PIN_LED 13
#define SlaveSelectPIn 4
void resetAFE4300();
void writeRegister(unsigned char address, unsigned int data); //Writes to a register on the AFE4300
int readRegister(unsigned char address); //Reads from a register on the AFE4300
void initAFE4300(); //intialize AFE
void initWeighScale(); // Initializes the Weigh Scale Module
void initBCM(); // Initializes the BCM Module
int readData(); // Reads the ADC data register
/***************************
AFE4300 register address definitions
****************************/
#define ADC_DATA_RESULT 0x00
#define ADC_CONTROL_REGISTER 0x01
#define MISC1_REGISTER 0x02
#define MISC2_REGISTER 0x03
#define DEVICE_CONTROL_1 0x09
#define ISW_MATRIX 0x0A
#define VSW_MATRIX 0x0B
#define IQ_MODE_ENABLE 0x0C
#define WEIGHT_SCALE_CONTROL 0x0D
#define BCM_DAC_FREQ 0x0E
#define DEVICE_CONTROL_2 0x0F
#define ADC_CONTROL_REGISTER_2 0x10
#define MISC3_REGISTER 0x1A
void setup()
{
pinMode(PIN_LED, OUTPUT);
pinMode(PIN_RESET, OUTPUT);
pinMode(PIN_DRDY, INPUT);
pinMode (PIN_CS, OUTPUT);
Serial.begin(115200);
Serial.flush();
pinMode (13,OUTPUT);
SPI.begin(SlaveSelectPIn); // SPI CS for slave
SPI.setClockDivider(SlaveSelectPIn,42); // 2MHz SPI clock generation
resetAFE4300();
initAFE4300();
initWeighScale();
}
void loop()
{
readData();
}
/**
* @brief Resets the AFE4300 device
*/
void resetAFE4300()
{
digitalWrite(PIN_RESET ,LOW);
delay(100);
digitalWrite(PIN_RESET ,HIGH);
}
/**
* @brief Writes to a register on the AFE4300
**/
void writeRegister(unsigned char address, unsigned int data)
{
unsigned char firstByte = (unsigned char)(data >> 8);
unsigned char secondByte = (unsigned char)data;
SPI.transfer(SlaveSelectPIn,address,SPI_CONTINUE);
//Send 2 bytes to be written
SPI.transfer(SlaveSelectPIn,firstByte,SPI_CONTINUE);
SPI.transfer(SlaveSelectPIn,secondByte,SPI_LAST);
}
/**
* @brief Reads from a register on the AFE4300
*/
int readRegister(unsigned char address)
{
SPI.begin(SlaveSelectPIn);
int spiReceive = 0;
unsigned char spiReceiveFirst = 0;
unsigned char spiReceiveSecond = 0;
address = address & 0x1F; //Last 5 bits specify address
address = address | 0x20; //First 3 bits need to be 001 for read opcode
SPI.transfer(SlaveSelectPIn,address,SPI_CONTINUE);
spiReceiveFirst = SPI.transfer(SlaveSelectPIn,0x00,SPI_CONTINUE);
spiReceiveSecond = SPI.transfer(SlaveSelectPIn,0x00,SPI_LAST);
//Combine the two received bytes into a signed int
spiReceive = (spiReceiveFirst << 8);
spiReceive |= spiReceiveSecond;
return spiReceive;
}
/**
* @brief Initializes the AFE4300 device
*/
void initAFE4300()
{
writeRegister(ADC_CONTROL_REGISTER,0x5140);
writeRegister(MISC1_REGISTER,0x0000);
writeRegister(MISC2_REGISTER,0xFFFF);
writeRegister(DEVICE_CONTROL_1,0x0004); //Power down both signal chains
writeRegister(ISW_MATRIX,0x0000);
writeRegister(VSW_MATRIX,0x0000);
writeRegister(IQ_MODE_ENABLE,0x0000);
writeRegister(WEIGHT_SCALE_CONTROL,0x0000);
writeRegister(BCM_DAC_FREQ,0x0040);
writeRegister(DEVICE_CONTROL_2,0x0000);
writeRegister(ADC_CONTROL_REGISTER_2,0x0011);
writeRegister(MISC3_REGISTER,0x00C0);
}
/**
* @brief Initializes the Weigh Scale Module
*/
void initWeighScale()
{
writeRegister(ADC_CONTROL_REGISTER,0x4120); //Differential measurement mode, 32 SPS
writeRegister(DEVICE_CONTROL_1,0x0005); //Power up weigh scale signal chain
writeRegister(ADC_CONTROL_REGISTER_2,0x0000); //ADC selects output of weigh scale
writeRegister(WEIGHT_SCALE_CONTROL,0x003F); //Gain = 1 DAC Offset = -1
writeRegister(BCM_DAC_FREQ,0x0040); //Frequency = default
writeRegister(IQ_MODE_ENABLE,0x0000); //Disable IQ mode
writeRegister(ISW_MATRIX,0x0000); //Channels IOUTP1 and IOUTN0
writeRegister(VSW_MATRIX,0x0000); //Channels VSENSEP1 and VSENSEN0
}
/**
* @brief Initializes the BCM Module
*/
void initBCM()
{
writeRegister(ADC_CONTROL_REGISTER,0x4120); //Differential measurement mode, 32 SPS
writeRegister(DEVICE_CONTROL_1,0x0006); //Power up BCM signal chain
writeRegister(ISW_MATRIX,0x0804); //Channels IOUTP1 and IOUTN0
writeRegister(VSW_MATRIX,0x0804); //Channels VSENSEP1 and VSENSEN0
writeRegister(ADC_CONTROL_REGISTER_2,0x0063); //ADC selects output of BCM-I output
writeRegister(WEIGHT_SCALE_CONTROL,0x0000); //Gain = 1 DAC Offset = 0
}
/**
* @brief Reads the ADC data register
*/
int readData()
{
return readRegister(ADC_DATA_RESULT);
}
Thanks in advance ,
-prag - INDIA