0% found this document useful (0 votes)
7 views3 pages

Code For Chat JPT

The document contains an Arduino sketch for interfacing with the AFE4490 and AFE4300 sensors. It initializes the sensors, sets up the necessary pins, and reads values from the sensors in a loop, handling interrupts for data readiness. The code includes functions for writing to and reading from the sensor registers, as well as an initialization routine for the infrared sensor settings.

Uploaded by

Nasri Makni
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views3 pages

Code For Chat JPT

The document contains an Arduino sketch for interfacing with the AFE4490 and AFE4300 sensors. It initializes the sensors, sets up the necessary pins, and reads values from the sensors in a loop, handling interrupts for data readiness. The code includes functions for writing to and reading from the sensor registers, as well as an initialization routine for the infrared sensor settings.

Uploaded by

Nasri Makni
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

const int AFE4490_SLAVE_SELECT = 8 ;

const int AFE4300_SLAVE_SELECT = 7 ;


const int AFE4490_PDN = 3 ;
const int AFE4300_DRDY = 0 ;
const int AFE4490_DRDY = 1 ;
const int ENABLE_FRONTEND = 4 ;
const int PIN_RESET = 2 ;
volatile int AFE4490_interrupt_flag = false;
unsigned int IR_value, G_value, ambIR_value, ambG_value, abs_IR, abs_G, green,
infrared;

void setup() {
Serial.begin(9600);
pinMode(A0, OUTPUT);
digitalWrite(A0, HIGH);
pinMode(PIN_RESET, OUTPUT);
pinMode(AFE4490_PDN, OUTPUT);
digitalWrite(AFE4490_PDN, HIGH);

pinMode(AFE4490_SLAVE_SELECT, OUTPUT);
digitalWrite(AFE4490_SLAVE_SELECT, HIGH);
pinMode(ENABLE_FRONTEND, OUTPUT);
digitalWrite(ENABLE_FRONTEND, HIGH);
SPI.begin();
pinMode(AFE4490_DRDY,INPUT);
attachInterrupt(digitalPinToInterrupt(AFE4490_DRDY), AFE44900_drdyRoutine,
FALLING);

void loop() {

AFE4490_init_ir();

if(AFE4490_interrupt_flag){
IR_value = AFE4490_readRegister(LED2VAL);
ambIR_value = AFE4490_readRegister(ALED2VAL);
abs_IR = AFE4490_readRegister(LED2ABSVAL);
G_value = AFE4490_readRegister(LED1VAL);
ambG_value = AFE4490_readRegister(ALED1VAL);
abs_G = AFE4490_readRegister(LED1ABSVAL);

}
AFE4490_interrupt_flag = false;
AFE4490_writeRegister(CONTROL0, 0x000008);
delay(1000);

void AFE44900_drdyRoutine(){
AFE4490_interrupt_flag = true;
}

void AFE4490_writeRegister(unsigned char address, unsigned int data)


{
unsigned char zeroByte = (unsigned char)(data >> 16);
unsigned char firstByte = (unsigned char)(data >> 8);
unsigned char secondByte = (unsigned char)data;

SPI.beginTransaction(SPISettings(100000, MSBFIRST, SPI_MODE0));


digitalWrite(AFE4490_SLAVE_SELECT, LOW);

SPI.transfer(address); //primi 8 bit address


//Send 3 bytes to be written
SPI.transfer(zeroByte);
SPI.transfer(firstByte);
SPI.transfer(secondByte); //24 bit di dati
delay(1);
digitalWrite(AFE4490_SLAVE_SELECT, HIGH);

SPI.endTransaction();
}

unsigned long AFE4490_readRegister(unsigned char address)


{
unsigned long data = 0;
AFE4490_writeRegister(CONTROL0, 0x000001);
SPI.beginTransaction(SPISettings(100000, MSBFIRST, SPI_MODE0));
digitalWrite (AFE4490_SLAVE_SELECT, LOW);
SPI.transfer (address);
data |= ((unsigned long)SPI.transfer (0) << 16);
data |= ((unsigned long)SPI.transfer (0) << 8);
data |= SPI.transfer (0);
delay(0.1);
digitalWrite (AFE4490_SLAVE_SELECT, HIGH);
SPI.endTransaction();
AFE4490_writeRegister(CONTROL0, 0X000000);

return data;
}
void AFE4490_init_ir ()
AFE4490_writeRegister(CONTROL0, 0x000008);
AFE4490_writeRegister(TIAGAIN, 0x000100);
AFE4490_writeRegister(TIA_AMB_GAIN, 0x0A0015);
AFE4490_writeRegister(LEDCNTRL, 0x01FF00);
AFE4490_writeRegister(CONTROL2, 0x060800);
AFE4490_writeRegister(CONTROL1, 0x000103);
AFE4490_writeRegister(PRPCOUNT, 0x00FA00);
AFE4490_writeRegister(LED2STC, 0X00BD10);
AFE4490_writeRegister(LED2ENDC, 0X00F9FE);
AFE4490_writeRegister(LED2LEDSTC, 0X00BB80);
AFE4490_writeRegister(LED2LEDENDC, 0X00FA00);
AFE4490_writeRegister(LED2LEDENDC, 0X00BB80);
AFE4490_writeRegister(ALED2STC, 0X000FA0);
AFE4490_writeRegister(ALED2ENDC, 0X003E70);
AFE4490_writeRegister(LED2CONVST, 0X000020);
AFE4490_writeRegister(LED2CONVEND, 0X0003E78);
AFE4490_writeRegister(ALED2CONVST, 0X003EA0);
AFE4490_writeRegister(ALED2CONVEND, 0X007CF8);
AFE4490_writeRegister(LED1STC, 0X004010);
AFE4490_writeRegister(LED1ENDC, 0X007CF0);
AFE4490_writeRegister(LED1LEDSTC, 0X003E80);
AFE4490_writeRegister(LED1LEDENDC, 0X007CF8);
AFE4490_writeRegister(ALED1STC, 0X007E90);
AFE4490_writeRegister(ALED1ENDC, 0X00BB70);
AFE4490_writeRegister(LED1CONVST, 0X007D20);
AFE4490_writeRegister(LED1CONVEND, 0X00BB78);
AFE4490_writeRegister(ALED1CONVST, 0X00BBA0);
AFE4490_writeRegister(ALED1CONVEND, 0X00FA00);
AFE4490_writeRegister(ADCRSTCNT0, 0X000000);
AFE4490_writeRegister(ADCRSTENDCT0, 0X000018);
AFE4490_writeRegister(ADCRSTCNT1, 0X003E80);
AFE4490_writeRegister(ADCRSTENDCT1, 0X003E98);
AFE4490_writeRegister(ADCRSTCNT2, 0X007D00);
AFE4490_writeRegister(ADCRSTENDCT2, 0X007D18);
AFE4490_writeRegister(ADCRSTCNT3, 0X00BB80);
AFE4490_writeRegister(ADCRSTENDCT3, 0X00BB98);
delay(1000);

You might also like