Skip to content

Commit

Permalink
Repair DA217 BUG
Browse files Browse the repository at this point in the history
  • Loading branch information
Quency-D committed Nov 29, 2022
1 parent e60b066 commit 6c14f83
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 109 deletions.
31 changes: 1 addition & 30 deletions libraries/SensorBasic/examples/DA217/da217_steps/da217_steps.ino
Original file line number Diff line number Diff line change
Expand Up @@ -3,52 +3,23 @@
#include "Arduino.h"
#include "da217.h"

#define INT1_PIN GPIO0
#define INT2_PIN GPIO1
bool da217_int1_flag,da217_int2_flag;

DA217 da217;
uint16_t step_num;
da217_step_status_t step_status;


void da217_int1_isr(void)
{
da217_int1_flag =true;
}
void da217_int2_isr(void)
{
da217_int2_flag =true;
}

void setup()
{
Serial.begin(115200);
PINMODE_INPUT_PULLDOWN(INT1_PIN);
PINMODE_INPUT_PULLDOWN(INT2_PIN);
attachInterrupt(INT1_PIN, da217_int1_isr, RISING);
attachInterrupt(INT2_PIN, da217_int2_isr, RISING);
pinMode(Vext,OUTPUT);
digitalWrite(Vext,LOW);//set vext to high
da217.da217_init();
da217.da217_start_up_step_detect(true,true,5);
da217.da217_start_up_step_detect();
}


void loop()
{
step_num = da217.da217_read_steps();
step_status = da217.da217_read_step_status();
Serial.printf("step_num = %d step_status =%d\r\n",step_num,step_status);
if( da217_int1_flag )
{
Serial.println("da217_int1_flag");
da217_int1_flag = false;
}
if(da217_int2_flag)
{
Serial.println("da217_int2_flag");
da217_int2_flag = false;
}
delay(3000);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ void setup()
da217.da217_start_xyz_axis(true,true,true);
}


void loop()
{
da217.da217_read_xyz_data(&x_data,&y_data,&z_data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void setup()

switch(address)
{
case 0x27:
case 0x26:
{
da217.da217_init();
da217.da217_set_odr_rate(DA217_ODR_500HZ);
Expand Down Expand Up @@ -170,7 +170,7 @@ void loop()
{
switch(address)
{
case 0x27:
case 0x26:
{
da217.da217_read_xyz_data(&x_data,&y_data,&z_data);
Serial.printf("x_data=%d y_data=%d z_data=%d\r\n",x_data,y_data,z_data);
Expand Down
96 changes: 22 additions & 74 deletions libraries/SensorBasic/src/da217.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@

#include "da217.h"


#define FLOAT_TO_INT(x) ((x) >= 0 ? (int)((x) + 0.5) : (int)((x)-0.5))


void DA217::da217_write_single_reg(uint8_t reg,uint8_t data)
{
da217_write_multiple_reg(reg,&data,1);
Expand Down Expand Up @@ -77,70 +73,24 @@ void DA217::da217_init(int sda,int scl ,uint32_t freq)
void DA217::da217_poweron(void)
{
uint8_t temp;
temp = DA217_PWR_ON |DA217_BANDWIDTH_500HZ |DA217_AUTOSLEEP_EN;
da217_write_single_reg(DA217_REG_MODE_BW,temp);
temp = DA217_PWR_ON |DA217_BANDWIDTH_500HZ |DA217_AUTOSLEEP_EN;
da217_write_single_reg(DA217_REG_MODE_BW,temp);
}

void DA217::da217_poweroff(void)
{
uint8_t temp;
temp = ~DA217_PWR_ON & (~DA217_AUTOSLEEP_EN);
da217_write_single_reg(DA217_REG_MODE_BW,temp);
temp = ~DA217_PWR_ON & (~DA217_AUTOSLEEP_EN);
da217_write_single_reg(DA217_REG_MODE_BW,temp);
}

void DA217::da217_start_up_step_detect(bool step_int_en,bool sm_int_en,uint8_t sm_threshold)
void DA217::da217_start_up_step_detect(void)
{
uint8_t temp;
da217_write_single_reg(DA217_REG_STEP_FILTER,DA217_STEP_FILTER_EN);
da217_write_single_reg(DA217_REG_RESET_STEP,DA217_RESET_STEP);
delay(100);
da217_write_single_reg(DA217_REG_RESET_STEP,~DA217_RESET_STEP);

if(step_int_en)
{
temp = da217_read_single_reg(DA217_REG_INT_SET0);
temp |= DA217_STEP_INT_EN;
da217_write_single_reg(DA217_REG_INT_SET0,temp);

temp = da217_read_single_reg(DA217_REG_INTERRUPT_MAPPING3);
temp |= DA217_INT2_STEP;
da217_write_single_reg(DA217_REG_INTERRUPT_MAPPING3,temp);

temp = da217_read_single_reg(DA217_REG_INTERRUPT_MAPPING1);
temp &= ~DA217_INT1_STEP;
da217_write_single_reg(DA217_REG_INTERRUPT_MAPPING1,temp);

}
temp = da217_read_single_reg(DA217_REG_INTERRUPT_MAPPING3);
Serial.printf("DA217_REG_INTERRUPT_MAPPING3 = %d \r\n",temp);
if(sm_int_en)
{
temp = da217_read_single_reg(DA217_REG_INT_SET0);
temp |= DA217_SM_INT_EN;
da217_write_single_reg(DA217_REG_INT_SET0,temp);
da217_write_single_reg(DA217_REG_SM_THRESHOLD, sm_threshold);



temp = da217_read_single_reg(DA217_REG_INTERRUPT_MAPPING1);
temp |= DA217_INT1_SM;
da217_write_single_reg(DA217_REG_INTERRUPT_MAPPING1,temp);

temp = da217_read_single_reg(DA217_REG_INTERRUPT_MAPPING3);
temp &= ~DA217_INT2_SM;
Serial.printf("DA217_INT2_SM = %u \r\n",temp);

da217_write_single_reg(DA217_REG_INTERRUPT_MAPPING3,temp);
}
da217_write_single_reg(DA217_REG_INT_LATCH,DA217_INT_LATCH_VALUE);


temp = da217_read_single_reg(DA217_REG_INTERRUPT_MAPPING3);
Serial.printf("DA217_REG_INTERRUPT_MAPPING3 = %d \r\n",temp);
temp = da217_read_single_reg(DA217_REG_INTERRUPT_MAPPING1);
Serial.printf("DA217_REG_INTERRUPT_MAPPING1 = %d \r\n",temp);
temp = da217_read_single_reg(DA217_REG_INT_SET0);
Serial.printf("DA217_REG_INT_SET0 = %d \r\n",temp);
}


Expand All @@ -159,41 +109,39 @@ void DA217::da217_stop_step_detect(void)
uint16_t DA217::da217_read_steps(void)
{
uint16_t step_num = 0;
step_num = da217_read_single_reg(DA217_REG_STEPS_MSB) << 8; //Step Counter
step_num += da217_read_single_reg(DA217_REG_STEPS_LSB); //Step Counter
return step_num;
step_num = da217_read_single_reg(DA217_REG_STEPS_MSB) << 8; //Step Counter
step_num += da217_read_single_reg(DA217_REG_STEPS_LSB); //Step Counter
return step_num;
}

da217_step_status_t DA217::da217_read_step_status(void)
{
uint8_t step_status,temp;
temp = da217_read_single_reg(DA217_ORIENT_STATUS) ; //Step Counter
step_status = temp & DA217_STEP_STATUS;
return (da217_step_status_t)step_status;
temp = da217_read_single_reg(DA217_ORIENT_STATUS) ; //Step Counter
step_status = temp & DA217_STEP_STATUS;
return (da217_step_status_t)step_status;
}



void DA217::da217_enable_watchdog(void)
{
uint8_t temp;
temp = da217_read_single_reg(DA217_REG_RESOLUTION_RANGE);
temp = da217_read_single_reg(DA217_REG_RESOLUTION_RANGE);
temp |= WATCHDOG_EN;
temp |= WATCHDOG_TIME_50MS;
da217_write_single_reg(DA217_REG_RESOLUTION_RANGE,temp);
temp = da217_read_single_reg(DA217_REG_RESOLUTION_RANGE);
temp = da217_read_single_reg(DA217_REG_RESOLUTION_RANGE);
}

void DA217::da217_disable_watchdog(void)
{
uint8_t temp;
temp = da217_read_single_reg(DA217_REG_RESOLUTION_RANGE);
temp = da217_read_single_reg(DA217_REG_RESOLUTION_RANGE);
temp &= ~WATCHDOG_EN;
da217_write_single_reg(DA217_REG_RESOLUTION_RANGE,temp);
}



void DA217::da217_start_xyz_axis(bool x_en,bool y_en,bool z_en)
{
uint8_t temp;
Expand Down Expand Up @@ -231,24 +179,24 @@ void DA217::da217_start_xyz_axis(bool x_en,bool y_en,bool z_en)
void DA217::da217_set_odr_rate(da217_odr_rate_t odr_rate)
{
uint8_t temp;
temp = da217_read_single_reg(DA217_REG_ODR_AXIS)&0xF0;
temp = da217_read_single_reg(DA217_REG_ODR_AXIS)&0xF0;
temp |= odr_rate;
da217_write_single_reg(DA217_REG_ODR_AXIS,temp);
}

void DA217::da217_set_fifo_mode(da217_fifo_mode_t mode)
{
uint8_t temp;
temp = da217_read_single_reg(DA217_REG_FIFO_CTRL) &0x3F;
temp |= mode;
temp = da217_read_single_reg(DA217_REG_FIFO_CTRL) &0x3F;
temp |= mode;
da217_write_single_reg(DA217_REG_FIFO_CTRL,temp);
}

void DA217::da217_set_full_scale(da217_full_scale_t fs)
{
uint8_t temp;
temp = da217_read_single_reg(DA217_REG_RESOLUTION_RANGE) &0xFC;
temp |= fs;
temp = da217_read_single_reg(DA217_REG_RESOLUTION_RANGE) &0xFC;
temp |= fs;
da217_write_single_reg(DA217_REG_RESOLUTION_RANGE,temp);
}

Expand All @@ -268,7 +216,7 @@ void DA217::da217_read_xyz_data(uint16_t *x_data,uint16_t *y_data,uint16_t *z_da
return;
}
da217_read_multiple_reg(DA217_REG_ACC_X_LSB,data,6);
*x_data = data[0]+ (data[1]<< 8);
*y_data = data[2]+ (data[3]<< 8);
*z_data = data[4]+ (data[5]<< 8);
*x_data = ((data[0]&0xFC) >> 2)+ (data[1]<< 6);
*y_data = ((data[2]&0xFC) >> 2)+ (data[3]<< 6);
*z_data = ((data[4]&0xFC) >> 2)+ (data[5]<< 6);
}
4 changes: 2 additions & 2 deletions libraries/SensorBasic/src/da217.h
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ Macro definitions - Register define for Gsensor asic
#define DA217_REG_SM_THRESHOLD 0x34


#define I2C_ADDRESS 0x27
#define I2C_ADDRESS 0x26

typedef enum
{
Expand Down Expand Up @@ -323,7 +323,7 @@ class DA217
{
public:
void da217_init( int sda=3,int scl=4 ,uint32_t freq=50000);
void da217_start_up_step_detect( bool step_int_en = false,bool sm_int_en = false, uint8_t sm_threshold = 0xFF);
void da217_start_up_step_detect(void);
void da217_stop_step_detect(void);
uint16_t da217_read_steps(void);
da217_step_status_t da217_read_step_status(void);
Expand Down

0 comments on commit 6c14f83

Please sign in to comment.