2021-03-27 07:49 AM
Hi everyone,
I am trying to bring in sensor synchronization for accurate data acquisition in a wireless sensor network built using STM32F407 Discovery.
ADXL355 Digital accelerometer (shown below ) provides full external sync by applying an external clock (enabled via the EXT_CLK bit) at 1.024 MHz on the INT2 pin (Pin 13) and an external synchronization signal, SYNC, on the DRDY pin (Pin 14). The pulse width of the SYNC signal must be at least 3.91 μs, which represents four cycles of the external clock
(4 ÷ 1.024 MHz = ~3.91 μs).
I used (Digilent) Analog Discovery 2 to provide an external clock 1.024 MHz and a SYNC signal 256 KHz ( 1.024 MHz / 4 ).
When I tried this I can not get any response from the sensor but it worked good with internal clock.
Can anyone help me to fix this problem?
My functions that I used is found below :backhand_index_pointing_down: ADXL355_Result Device_ID(SPI_HandleTypeDef* spix,GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
{
/****************** Check the Analog Devices ID, 0xAD *****************************************/
uint8_t DEVID_AD = (uint8_t)(ADXL355_DEVID_AD << 1 ) | 0x01;
uint8_t temp = 0;
HAL_GPIO_WritePin(GPIOx, GPIO_Pin , GPIO_PIN_RESET);
if(HAL_SPI_Transmit(spix, (uint8_t *)&DEVID_AD, 1, 100) != HAL_OK)
{
return ADXL355_Result_Error;
}
// Receive multiple byte
if(HAL_SPI_Receive(spix, &temp, 1, 100) != HAL_OK)
{
return ADXL355_Result_Error;
}
HAL_GPIO_WritePin(GPIOx, GPIO_Pin , GPIO_PIN_SET);
// Checking
while(temp != ADXL355_ID)
{
// Return error
return ADXL355_Result_DeviceInvalid;
}
return ADXL355_Result_Ok;
}
ADXL355_Result Dev_SYNC(SPI_HandleTypeDef* spix, GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin , uint16_t SYNC_Type )
{
uint8_t d[2];
SPI_HandleTypeDef* Handle = spix;
/// Format array to send
d[0] = (uint8_t )(ADXL355_Sync<<1) | 0x00;
d[1] = (0x00 | SYNC_Type ) ;
HAL_GPIO_WritePin(GPIOx, GPIO_Pin , GPIO_PIN_RESET);
if(HAL_SPI_Transmit(Handle, (uint8_t *)d, 2 , 100) != HAL_OK)
{
return ADXL355_Result_Error;
}
HAL_GPIO_WritePin(GPIOx, GPIO_Pin , GPIO_PIN_SET);
// Return OK
return ADXL355_Result_Ok;
}
ADXL355_Result ADXL355_SetDataRate(SPI_HandleTypeDef* spix, GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin , uint8_t rate)
{
uint8_t d[2];
SPI_HandleTypeDef* Handle = spix;
/// Format array to send
d[0] = (uint8_t )(ADXL355_Filter<<1) | 0x00;
d[1] = rate;
// Set data sample rate
HAL_GPIO_WritePin(GPIOx, GPIO_Pin , GPIO_PIN_RESET);
if(HAL_SPI_Transmit(Handle, (uint8_t *)d, 2 , 100) != HAL_OK)
{
return ADXL355_Result_Error;
}
HAL_GPIO_WritePin(GPIOx, GPIO_Pin , GPIO_PIN_SET);
// Return OK
return ADXL355_Result_Ok;
}
ADXL355_Result ADXL355_SetAccelerometer(SPI_HandleTypeDef* spix, GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin ,ADXL355* DataStruct, ADXL355_Accelerometer AccelerometerSensitivity)
{
uint8_t temp;
SPI_HandleTypeDef* Handle = spix;
uint8_t regAdd =(uint8_t )ADXL355_Range;
uint8_t d[2];
uint8_t Add =(uint8_t )(ADXL355_Range<<1) | 0x01;
HAL_GPIO_WritePin(GPIOx, GPIO_Pin , GPIO_PIN_RESET);
/* Config accelerometer */
while(HAL_SPI_Transmit(Handle, (uint8_t *)&Add, 1, 100) != HAL_OK)
{
return ADXL355_Result_Error;
}
while(HAL_SPI_Receive(Handle, (uint8_t *)&temp, 1, 100) != HAL_OK)
{
return ADXL355_Result_Error;
}
temp = (temp & 0xFC) | (uint8_t)AccelerometerSensitivity ;
d[0] = (regAdd<<1) | 0x00;
d[1] = temp;
while(HAL_SPI_Transmit(Handle, (uint8_t *)d, 2 , 100) != HAL_OK)
{
return ADXL355_Result_Error;
}
HAL_GPIO_WritePin(GPIOx, GPIO_Pin , GPIO_PIN_SET);
/* Set sensitivities for multiplying gyro and accelerometer data */
switch (AccelerometerSensitivity) {
case ADXL355_Accelerometer_2G:
DataStruct->Acce_Mult = (float)1 / ADXL355_ACCE_SENS_2;
break;
case ADXL355_Accelerometer_4G:
DataStruct->Acce_Mult = (float)1 / ADXL355_ACCE_SENS_4;
break;
case ADXL355_Accelerometer_8G:
DataStruct->Acce_Mult = (float)1 / ADXL355_ACCE_SENS_8;
break;
default:
break;
}
/* Return OK */
return ADXL355_Result_Ok;
}
ADXL355_Result ADXL355_START_meas(SPI_HandleTypeDef* spix, GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin )
{
uint8_t d[2];
SPI_HandleTypeDef* Handle = spix;
/// Format array to send
d[0] = (uint8_t )(ADXL355_POWER_CTL<<1) | 0x00;
d[1] = 0x00 ;
HAL_GPIO_WritePin(GPIOx, GPIO_Pin , GPIO_PIN_RESET);
if(HAL_SPI_Transmit(Handle, (uint8_t *)d, 2 , 100) != HAL_OK)
{
return ADXL355_Result_Error;
}
HAL_GPIO_WritePin(GPIOx, GPIO_Pin , GPIO_PIN_SET);
// Return OK
return ADXL355_Result_Ok;
}
ADXL355_Result ADXL355_ReadAcc_FIFO(SPI_HandleTypeDef* spix, GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin ,ADXL355* DataStruct , bool x)
{
uint8_t data[9] = {0, 0, 0, 0, 0, 0, 0, 0 , 0};
uint8_t reg = (uint8_t )(ADXL355_FIFO_DATA<<1) | 0x01;
SPI_HandleTypeDef* Handle = spix;
HAL_GPIO_WritePin(GPIOx, GPIO_Pin , GPIO_PIN_RESET);
/* Config accelerometer */
while(HAL_SPI_Transmit(Handle, (uint8_t *)®, 1, 100) != HAL_OK)
{
return ADXL355_Result_Error;
}
while(HAL_SPI_Receive(Handle, (uint8_t *)data, 9, 100) != HAL_OK)
{
return ADXL355_Result_Error;
}
HAL_GPIO_WritePin(GPIOx, GPIO_Pin , GPIO_PIN_SET);
DataStruct->Accelerometer_X = ((uint32_t)data[0] << 12) | ((uint32_t)data[1] << 4) | ((uint32_t)data[2] >> 4);
DataStruct->Accelerometer_Y = ((uint32_t)data[3] << 12) | ((uint32_t)data[4] << 4) | ((uint32_t)data[5] >> 4);
DataStruct->Accelerometer_Z = ((uint32_t)data[6] << 12) | ((uint32_t)data[7] << 4) | ((uint32_t)data[8] >> 4);
if (DataStruct->Accelerometer_X & 0x80000) {
DataStruct->Accelerometer_X = (DataStruct->Accelerometer_X & 0x7ffff) - 0x80000;
}
if (DataStruct->Accelerometer_Y & 0x80000) {
DataStruct->Accelerometer_Y = (DataStruct->Accelerometer_Y & 0x7ffff) - 0x80000;
}
if (DataStruct->Accelerometer_Z & 0x80000) {
DataStruct->Accelerometer_Z = (DataStruct->Accelerometer_Z & 0x7ffff) - 0x80000;
}
ADXL_AX = (float)DataStruct->Accelerometer_X*DataStruct->Acce_Mult;
ADXL_AY = (float)DataStruct->Accelerometer_Y*DataStruct->Acce_Mult;
ADXL_AZ = (float)DataStruct->Accelerometer_Z*DataStruct->Acce_Mult;
//* Return OK
return ADXL355_Result_Ok;
}
Solved! Go to Solution.
2021-03-29 04:49 AM
Hi @MHass.2 ,
I would first suggest you to try with the Analog devices support, since the ADXL355 product is from their portfolio.
Checking the datasheet, I see there are there are some possible configuration for the device synchronization with the external clock. In particular, I would select this configuration that looks to have no further configuration except SYNC register (external clock asynchronous to the internal clock).
But honestly, I don't know if you have to writhe the base device configurations (FS, ODR; Operating mode) before or after activating the external clock...
EXT_SYNC = 10, EXT_CLK = 0 --- External Synchronization with Interpolation
Synchronization using interpolation filters and an external ODR clock is commonly used when the external processor can provide a synchronization signal that is asynchronous to the internal clock, SYNC, at the desired ODR. In this case, an interpolation filter provides additional time resolution of 64 times the programmed ODR. Synchronization with the interpolation filter enabled (EXT_SYNC = 10) allows the sensor to operate on an internal clock and output data most closely associated with the SYNC rising edge. The advantage of this mode is that data is available at an arbitrary user defined SYNC sample rate and is asynchronous to the internal clock oscillator. The maximum sample rate cannot exceed 4000 SPS. The disadvantage of this mode is that the group delay is increased, with increased attenuation at the band edge. Additionally, because there is a limit to the time resolution, there is some distortion related to the mismatch of the external synchronization relative to the internal clock oscillator [...].
-Eleon
2021-03-29 04:49 AM
Hi @MHass.2 ,
I would first suggest you to try with the Analog devices support, since the ADXL355 product is from their portfolio.
Checking the datasheet, I see there are there are some possible configuration for the device synchronization with the external clock. In particular, I would select this configuration that looks to have no further configuration except SYNC register (external clock asynchronous to the internal clock).
But honestly, I don't know if you have to writhe the base device configurations (FS, ODR; Operating mode) before or after activating the external clock...
EXT_SYNC = 10, EXT_CLK = 0 --- External Synchronization with Interpolation
Synchronization using interpolation filters and an external ODR clock is commonly used when the external processor can provide a synchronization signal that is asynchronous to the internal clock, SYNC, at the desired ODR. In this case, an interpolation filter provides additional time resolution of 64 times the programmed ODR. Synchronization with the interpolation filter enabled (EXT_SYNC = 10) allows the sensor to operate on an internal clock and output data most closely associated with the SYNC rising edge. The advantage of this mode is that data is available at an arbitrary user defined SYNC sample rate and is asynchronous to the internal clock oscillator. The maximum sample rate cannot exceed 4000 SPS. The disadvantage of this mode is that the group delay is increased, with increased attenuation at the band edge. Additionally, because there is a limit to the time resolution, there is some distortion related to the mismatch of the external synchronization relative to the internal clock oscillator [...].
-Eleon