R #9
|
@ -116,25 +116,58 @@ void Error_Handler(void);
|
|||
#define VL53LX 1
|
||||
#endif
|
||||
|
||||
/* DUAL TOF VL53L0 */
|
||||
/* -------------------- | -------------------- */
|
||||
/* | | | */
|
||||
/* | TOF-2 | TOF-1 | */
|
||||
/* -------------------- | ------------------ | */
|
||||
/* U4, PA-9,XSHUT | U3, PB-5,XSHUT | */
|
||||
|
||||
|
||||
/* SINGLE TOF VL53L0 */
|
||||
/* ----------------------------------------- */
|
||||
/* | | */
|
||||
/* | TOF-1 | */
|
||||
/* ----------------------------------------- | */
|
||||
/* | U3, PB-5 | */
|
||||
|
||||
|
||||
#if defined(VL53LX)||defined(VL53L0)
|
||||
#define TOF_C_INT_Pin GPIO_PIN_3
|
||||
#define TOF_C_INT_GPIO_Port GPIOB
|
||||
#define TOF_C_INT_EXTI_IRQn EXTI3_IRQn
|
||||
/* TOF-1 */
|
||||
/* | U3, PB-5 XSHUT | */
|
||||
/* INT PIN PB-3 | */
|
||||
#define TOF_C_INT_Pin GPIO_PIN_3
|
||||
#define TOF_C_INT_GPIO_Port GPIOB
|
||||
#define TOF_C_INT_EXTI_IRQn EXTI3_IRQn
|
||||
|
||||
#define TOF_C_XSHUT_Pin GPIO_PIN_5
|
||||
#define TOF_C_XSHUT_GPIO_Port GPIOB
|
||||
#define TOF_C_XSHUT_Pin GPIO_PIN_5
|
||||
#define TOF_C_XSHUT_GPIO_Port GPIOB
|
||||
|
||||
#define TOF_L_INT_Pin GPIO_PIN_3
|
||||
#define TOF_L_INT_GPIO_Port GPIOB
|
||||
#define TOF_L_INT_EXTI_IRQn EXTI3_IRQn
|
||||
|
||||
#define TOF_L_XSHUT_Pin GPIO_PIN_9
|
||||
#define TOF_L_XSHUT_GPIO_Port GPIOA
|
||||
#define TOF_INT_EXTI_PIN TOF_C_INT_Pin
|
||||
#define TOF_INT_EXTI_PORT TOF_C_INT_GPIO_Port
|
||||
|
||||
/* | TOF-2 | */
|
||||
/* U4, PA-9 XSHUT | */
|
||||
/* NT PIN PB-3 | */
|
||||
#define TOF_L_INT_Pin GPIO_PIN_3
|
||||
#define TOF_L_INT_GPIO_Port GPIOB
|
||||
#define TOF_L_INT_EXTI_IRQn EXTI3_IRQn
|
||||
|
||||
#define TOF_L_XSHUT_Pin GPIO_PIN_9
|
||||
#define TOF_L_XSHUT_GPIO_Port GPIOA
|
||||
|
||||
/* | TOF-3 | */
|
||||
/* EXT SOCKET PA-10, XSHUT | */
|
||||
/* NT PIN PB-3 | */
|
||||
#define TOF_R_INT_Pin GPIO_PIN_3
|
||||
#define TOF_R_INT_GPIO_Port GPIOB
|
||||
#define TOF_R_INT_EXTI_IRQn EXTI3_IRQn
|
||||
|
||||
#define TOF_R_XSHUT_Pin GPIO_PIN_10
|
||||
#define TOF_R_XSHUT_GPIO_Port GPIOA
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef STM32WLE5xx
|
||||
#define I2C2_SCL_PIN GPIO_PIN_12
|
||||
#define I2C2_SDA_PIN GPIO_PIN_11
|
||||
|
|
|
@ -79,6 +79,14 @@ void MX_GPIO_Init(void)
|
|||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
HAL_GPIO_Init(BUT3_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
/* STS-PME PB-4 */
|
||||
/*Configure GPIO pins : PBPin PBPin PBPin */
|
||||
GPIO_InitStruct.Pin = MEMS_POWER_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(MEMS_POWER_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
#if defined(VL53LX)||defined(VL53L0)
|
||||
/*Configure GPIO pins : TOF_C_INT_Pin TOF_R_INT_Pin */
|
||||
GPIO_InitStruct.Pin = TOF_C_INT_Pin;
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
#include "main.h"
|
||||
#include "app_lorawan.h"
|
||||
#include "gpio.h"
|
||||
|
||||
#include <stdio.h>
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
#include "i2c.h"
|
||||
|
@ -96,14 +96,14 @@ int main(void)
|
|||
|
||||
/* Initialize all configured peripherals */
|
||||
MX_GPIO_Init();
|
||||
|
||||
MX_I2C2_Init();
|
||||
MX_DMA_Init();
|
||||
|
||||
MX_LoRaWAN_Init();
|
||||
/* USER CODE BEGIN 2 */
|
||||
|
||||
|
||||
|
||||
APP_LOG(TS_OFF, VLEVEL_M, "\n\n --- STS_RR --- APP LOG --- \n\n");
|
||||
/* USER CODE END 2 */
|
||||
|
||||
/* Infinite loop */
|
||||
|
|
|
@ -120,6 +120,8 @@ void PWR_ExitStopMode(void)
|
|||
SRAM ctrls, DMAx, DMAMux, AES, RNG, HSEM */
|
||||
|
||||
/* Resume not retained USARTx and DMA */
|
||||
MX_I2C2_Init();
|
||||
MX_DMA_Init();
|
||||
vcom_Resume();
|
||||
/* USER CODE BEGIN ExitStopMode_2 */
|
||||
|
||||
|
|
|
@ -245,6 +245,19 @@ void EXTI1_IRQHandler(void)
|
|||
/* USER CODE END EXTI1_IRQn 1 */
|
||||
}
|
||||
|
||||
void EXTI3_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN EXTI3_IRQn 0 */
|
||||
|
||||
/* USER CODE END EXTI3_IRQn 0 */
|
||||
#ifdef STM32WLE5xx
|
||||
HAL_GPIO_EXTI_IRQHandler(TOF_INT_EXTI_PIN);
|
||||
#endif
|
||||
/* USER CODE BEGIN EXTI3_IRQn 1 */
|
||||
|
||||
/* USER CODE END EXTI3_IRQn 1 */
|
||||
}
|
||||
|
||||
/* I2C2 */
|
||||
/**
|
||||
* @brief This function handles DMA1 Channel 3 Interrupt.
|
||||
|
|
|
@ -379,8 +379,10 @@ void STS_YunhornSTSEventP4_Process(void)
|
|||
LED_OFF;
|
||||
#endif
|
||||
#if defined(TOF_1)||defined(TOF_2)||defined(VL53L0)
|
||||
APP_LOG(TS_OFF, VLEVEL_L, "\r\n TOF_1, TOF_2 RANGING Process\r\n");
|
||||
APP_LOG(TS_OFF, VLEVEL_M, "\r\n TOF_1, TOF_2 RANGING Process\r\n");
|
||||
PME_ON;
|
||||
STS_TOF_VL53L0X_Range_Process();
|
||||
PME_OFF;
|
||||
//MX_TOF_Process();
|
||||
#endif
|
||||
|
||||
|
@ -1633,14 +1635,16 @@ void STS_SENSOR_Function_Test_Process(void)
|
|||
#endif
|
||||
|
||||
#if (defined(YUNHORN_STS_R0_ENABLED)||defined(YUNHORN_STS_R5_ENABLED)||defined(YUNHORN_STS_R1_ENABLED))
|
||||
tstbuf[i++] = (uint8_t) (2)&0xff;
|
||||
tstbuf[i++] = (uint8_t) (4)&0xff;
|
||||
//MX_TOF_Process();
|
||||
#ifdef STS_P2
|
||||
MX_TOF_Init();
|
||||
MX_TOF_Ranging_Process();
|
||||
#endif
|
||||
#ifdef VL53L0
|
||||
PME_ON;
|
||||
STS_TOF_VL53L0X_Range_Process();
|
||||
PME_OFF;
|
||||
#endif
|
||||
|
||||
#ifdef TOF_1
|
||||
|
|
|
@ -59,7 +59,7 @@
|
|||
* can be @a XNUCLEO53L1A1_I2C1Configure() @sa XNUCLEO53L1A1_usage
|
||||
* @warning do not use any XNUCLEO53L1A1_xxx prior to a first init with valid i2c handle
|
||||
*/
|
||||
I2C_HandleTypeDef XNUCLEO53L1A1_hi2c;
|
||||
extern I2C_HandleTypeDef hi2c2;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -146,19 +146,19 @@ int XWL55_WLE5_53L0X_I2C2Configure() {
|
|||
GPIO_InitStruct.Alternate = GPIO_AF4_I2C2;
|
||||
HAL_GPIO_Init(I2C2_SDA_PORT, &GPIO_InitStruct);
|
||||
|
||||
XNUCLEO53L1A1_hi2c.Instance = I2C2;
|
||||
hi2c2.Instance = I2C2;
|
||||
//XNUCLEO53L1A1_hi2c.Init.Timing = 0x00300F38; /* set 400KHz fast mode i2c*/
|
||||
//XNUCLEO53L1A1_hi2c.Init.Timing = I2C2_FAST_400K; //UPDATE 2024-07-09
|
||||
XNUCLEO53L1A1_hi2c.Init.Timing = I2C2_STANDARD_100K; // UPDATE 2024-07-12
|
||||
hi2c2.Init.Timing = I2C2_STANDARD_100K; // UPDATE 2024-07-12
|
||||
//XNUCLEO53L1A1_hi2c.Init.Timing = 0x2010091A; //0x2010091A = 400K Fast Mode, 0x20303E5D, 100K Standard mode, 0x20000209 Fast Mode Plus, 1Mbps
|
||||
|
||||
XNUCLEO53L1A1_hi2c.Init.OwnAddress1 = 0;
|
||||
XNUCLEO53L1A1_hi2c.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
|
||||
XNUCLEO53L1A1_hi2c.Init.DualAddressMode = I2C_DUALADDRESS_DISABLED;
|
||||
XNUCLEO53L1A1_hi2c.Init.OwnAddress2 = 0;
|
||||
XNUCLEO53L1A1_hi2c.Init.GeneralCallMode = I2C_GENERALCALL_DISABLED;
|
||||
XNUCLEO53L1A1_hi2c.Init.NoStretchMode = I2C_NOSTRETCH_DISABLED;
|
||||
status = HAL_I2C_Init(&XNUCLEO53L1A1_hi2c);
|
||||
hi2c2.Init.OwnAddress1 = 0;
|
||||
hi2c2.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
|
||||
hi2c2.Init.DualAddressMode = I2C_DUALADDRESS_DISABLED;
|
||||
hi2c2.Init.OwnAddress2 = 0;
|
||||
hi2c2.Init.GeneralCallMode = I2C_GENERALCALL_DISABLED;
|
||||
hi2c2.Init.NoStretchMode = I2C_NOSTRETCH_DISABLED;
|
||||
status = HAL_I2C_Init(&hi2c2);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
|
|
@ -276,7 +276,7 @@ void XWL55_WLE5_53L0X_ResetId(uint8_t DevNo, int state);
|
|||
* <0 for error (invalid id)
|
||||
* >0 interrupt configured but with potential sharing on EXTI groups see @ref VL53L0X_GPIO1_MAP
|
||||
*/
|
||||
int XNUCLEO53L1A1_SetIntrStateId(int EnableIntr, int DevNo);
|
||||
//int XNUCLEO53L1A1_SetIntrStateId(int EnableIntr, int DevNo);
|
||||
int XWL55_WLE5_53L0X_SetIntrStateId(int EnableIntr, int DevNo);
|
||||
int sts_tof_vl53l0x_DetectSensors(void);
|
||||
void STS_TOF_VL53L0X_Range_Process(void);
|
||||
|
|
|
@ -143,7 +143,7 @@ int sts_tof_vl53l0x_DetectSensors(void)
|
|||
|
||||
for (i=0; i < MAX_TOF_COUNT; i++) {
|
||||
XWL55_WLE5_53L0X_ResetId(i,0);
|
||||
//XWL55_WLE5_53L0X_SetIntrStateId(1,i);
|
||||
XWL55_WLE5_53L0X_SetIntrStateId(1,i);
|
||||
}
|
||||
|
||||
/* detect all sensors (even on-board)*/
|
||||
|
@ -157,7 +157,7 @@ int sts_tof_vl53l0x_DetectSensors(void)
|
|||
HAL_Delay(3);
|
||||
FinalAddress = 0x52+(i+1)*2;
|
||||
|
||||
//APP_LOG(TS_OFF, VLEVEL_H, "\r\n Detect TOF sensors #%u with I2CDevAddr=0x%02x \r\n", i, pDev->I2cDevAddr);
|
||||
APP_LOG(TS_OFF, VLEVEL_M, "\r\n Detect TOF sensors #%u with I2CDevAddr=0x%02x \r\n", i, pDev->I2cDevAddr);
|
||||
|
||||
do {
|
||||
/* Set I2C standard mode (400 KHz) before doing the first register access */
|
||||
|
@ -166,42 +166,44 @@ int sts_tof_vl53l0x_DetectSensors(void)
|
|||
|
||||
/* Try to read one register using default 0x52 address */
|
||||
status = VL53L0X_RdWord(pDev, VL53L0X_REG_IDENTIFICATION_MODEL_ID, &Id);
|
||||
//APP_LOG(TS_OFF, VLEVEL_H, "#%u read id = %04x I2C ADDR=0x%2X\r\n",i, Id, pDev->I2cDevAddr);
|
||||
APP_LOG(TS_OFF, VLEVEL_M, "#%u read id = %04X I2C ADDR=0x%2X\r\n",i, Id, pDev->I2cDevAddr);
|
||||
if (status) {
|
||||
APP_LOG(TS_OFF, VLEVEL_H, "# Read id fail \r\n");
|
||||
APP_LOG(TS_OFF, VLEVEL_M, "# Read id fail \r\n");
|
||||
break;
|
||||
}
|
||||
if (Id == 0xEEAA) {
|
||||
/* Sensor is found => Change its I2C address to final one */
|
||||
APP_LOG(TS_OFF, VLEVEL_M, "\n Set Final i2c addr to %02X \r\n", FinalAddress);
|
||||
status = VL53L0X_SetDeviceAddress(pDev,FinalAddress);
|
||||
if (status != 0) {
|
||||
APP_LOG(TS_OFF, VLEVEL_H, "#i VL53L0X_SetDeviceAddress fail\r\n");
|
||||
APP_LOG(TS_OFF, VLEVEL_M, "#i VL53L0X_SetDeviceAddress fail\r\n");
|
||||
break;
|
||||
}
|
||||
pDev->I2cDevAddr = FinalAddress;
|
||||
APP_LOG(TS_OFF, VLEVEL_M, "\n pDev->I2CDevAddr set to: %02X \r\n", pDev->I2cDevAddr);
|
||||
/* Check all is OK with the new I2C address and initialize the sensor */
|
||||
status = VL53L0X_RdWord(pDev, VL53L0X_REG_IDENTIFICATION_MODEL_ID, &Id);
|
||||
// if (status !=0)
|
||||
//{
|
||||
// APP_LOG(TS_OFF, VLEVEL_H, "#i VL53L0X_RdWord fail\r\n");
|
||||
//break;
|
||||
//}
|
||||
if (status !=0)
|
||||
{
|
||||
APP_LOG(TS_OFF, VLEVEL_M, "#i VL53L0X_RdWord fail\r\n");
|
||||
break;
|
||||
}
|
||||
status = VL53L0X_DataInit(pDev);
|
||||
if( status == 0 ){
|
||||
pDev->Present = 1;
|
||||
//APP_LOG(TS_OFF, VLEVEL_H, "#%u VL53L0X_SetDeviceAddress to 0x%02x\r\n",i, pDev->I2cDevAddr);
|
||||
APP_LOG(TS_OFF, VLEVEL_M, "#%u VL53L0X_SetDeviceAddress to 0x%02x\r\n",i, pDev->I2cDevAddr);
|
||||
nDevPresent++;
|
||||
nDevMask |= 1 << i;
|
||||
pDev->Present = 1;
|
||||
APP_LOG(TS_OFF, VLEVEL_H, "VL53L0X %d Present and initiated to final 0x%2x, Position Mask=0x%02x\r\n", pDev->Id, pDev->I2cDevAddr, nDevMask);
|
||||
APP_LOG(TS_OFF, VLEVEL_M, "VL53L0X %d Present and initiated to final 0x%2x, Position Mask=0x%02x\r\n", pDev->Id, pDev->I2cDevAddr, nDevMask);
|
||||
}
|
||||
else{
|
||||
APP_LOG(TS_OFF, VLEVEL_H, "VL53L0X_DataInit %d fail\r\n", Id);
|
||||
APP_LOG(TS_OFF, VLEVEL_M, "VL53L0X_DataInit %d fail\r\n", Id);
|
||||
break;
|
||||
}
|
||||
|
||||
} else {
|
||||
APP_LOG(TS_OFF, VLEVEL_H, "# unknown ID %x\r\n", Id);
|
||||
APP_LOG(TS_OFF, VLEVEL_M, "# unknown ID %x\r\n", Id);
|
||||
status = 1;
|
||||
}
|
||||
} while(0);
|
||||
|
@ -356,6 +358,8 @@ void STS_TOF_VL53L0X_Range_Process(void)
|
|||
APP_LOG(TS_OFF, VLEVEL_M, "\r\n %u pcs sensor(s) online \r\n", nSensorPresent);
|
||||
}
|
||||
|
||||
APP_LOG(TS_OFF, VLEVEL_M, "\n\n nDevMask=%02X nSensorPresent = %02x \n\n", nDevMask, nSensorPresent);
|
||||
|
||||
#ifdef TOF_3
|
||||
sts_tof_distance_data[2] = 0;
|
||||
#endif
|
||||
|
@ -368,10 +372,11 @@ void STS_TOF_VL53L0X_Range_Process(void)
|
|||
sensor_data_ready = 0 ;
|
||||
for (i=0; i< MAX_TOF_COUNT; i++)
|
||||
{
|
||||
APP_LOG(TS_OFF, VLEVEL_M, "\n\n i=%u Present=%u DevAdd=%02x \n", i, VL53L0XDevs[i].Present, VL53L0XDevs[i].I2cDevAddr);
|
||||
if (VL53L0XDevs[i].Present ==1)
|
||||
{
|
||||
//uint8_t rep=0;
|
||||
//do {
|
||||
uint8_t rep=0;
|
||||
do {
|
||||
// rep++;
|
||||
status = VL53L0X_PerformSingleRangingMeasurement(&VL53L0XDevs[i], &RangingMeasurementData);
|
||||
if (status ==0)
|
||||
|
@ -380,36 +385,39 @@ void STS_TOF_VL53L0X_Range_Process(void)
|
|||
if( RangingMeasurementData.RangeStatus == 0 )
|
||||
{
|
||||
sts_tof_distance_data[i] = (int)VL53L0XDevs[i].LeakyRange;
|
||||
|
||||
nDevMask |= (1 << i);
|
||||
sensor_data_ready |= 1;
|
||||
} else
|
||||
{
|
||||
//HandleError(ERR_DEMO_RANGE_ONE);
|
||||
//APP_LOG(TS_OFF, VLEVEL_M,"\r\n#%u sensor ERR code = %04u\r\n",i, ERR_DEMO_RANGE_ONE);
|
||||
APP_LOG(TS_OFF, VLEVEL_M,"\r\n#%u sensor ERR code = %04u\r\n",i, ERR_DEMO_RANGE_ONE);
|
||||
}
|
||||
// ########## two conditions
|
||||
// ########## 1) return status ==0,
|
||||
// ########## 2) and ranging status for valid ranging value !!!!!!!!!!!!!!!!!
|
||||
}
|
||||
// HAL_Delay(1);
|
||||
//} while ((RangingMeasurementData.RangeStatus != 0)&&(rep <10));
|
||||
//sts_tof_distance_data[i] = (RangingMeasurementData.RangeStatus!=0)?STS_MAX_L0_RANGE:VL53L0XDevs[i].LeakyRange;
|
||||
}
|
||||
// ########## two conditions
|
||||
// ########## 1) return status ==0,
|
||||
// ########## 2) and ranging status for valid ranging value !!!!!!!!!!!!!!!!!
|
||||
}
|
||||
|
||||
HAL_Delay(1);
|
||||
|
||||
} while ((RangingMeasurementData.RangeStatus != 0)&&(rep++ < 10));
|
||||
sts_tof_distance_data[i] = (RangingMeasurementData.RangeStatus!=0)?STS_MAX_L0_RANGE:VL53L0XDevs[i].LeakyRange;
|
||||
}
|
||||
|
||||
HAL_Delay(30);
|
||||
} // for i < MAX_TOF_COUNT
|
||||
} // for i < MAX_TOF_COUNT
|
||||
|
||||
if (sensor_data_ready != 0) {
|
||||
if (sensor_data_ready != 0)
|
||||
{
|
||||
APP_LOG(TS_OFF, VLEVEL_M, "\r\n## Measured Range: \r\nTOF #0 = %4u mm, \r\nTOF #1 = %4u mm, \r\nTOF #2 = %4u mm\r\n",
|
||||
(int)sts_tof_distance_data[0],(int)sts_tof_distance_data[1],(int)sts_tof_distance_data[2]);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
// nSensorPresent >0
|
||||
sts_tof_distance_data[0] = STS_MAX_L0_RANGE;
|
||||
sts_tof_distance_data[1] = STS_MAX_L0_RANGE;
|
||||
sts_tof_distance_data[2] = STS_MAX_L0_RANGE;
|
||||
APP_LOG(TS_OFF, VLEVEL_M, "\n\n APP_LOG no ToF sensor online \n\n");
|
||||
}
|
||||
|
||||
// reset for next ranging
|
||||
|
|
|
@ -28,8 +28,9 @@ extern "C" {
|
|||
#include "stm32wlxx_hal.h"
|
||||
|
||||
/* Exported symbols ----------------------------------------------------------*/
|
||||
#define TOF_INT_EXTI_PIN (GPIO_PIN_3) // (GPIO_PIN_4)
|
||||
#define TOF_INT_EXTI_PORT (GPIOB)
|
||||
|
||||
//#define TOF_INT_EXTI_PIN (GPIO_PIN_3) // (GPIO_PIN_4)
|
||||
//#define TOF_INT_EXTI_PORT (GPIOB)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue