如何在程序初始化期间(有效)和 LoRaWAN 工作周期期间(无效)重复读取 ST 传感器的 WhoAmI 寄存器?
How to read the WhoAmI register of an ST-sensor during both initialization of the program (works) and repeatedly during LoRaWAN duty cycle (doesn't)?
我一直在尝试将 Seeed studio 的 LoRa-E5-Mini 上的 STM32WL55JC1 微控制器编程为 LoRaWAN 端节点,并将气压数据从 ST LPS22HH 传感器中继到物联网。
我认为我遇到的问题一定是在代码中。原因是在初始化时,读取传感器的 WhoAmI 寄存器会产生结果。但之后每次,根据 LoRaWAN 节点的工作周期,调用该函数都不会产生任何结果,我无法连接到传感器。这保持不变,无法读取 WhoAmI 寄存器的每个 Tx 事件。
每次我重置 MCU 时,都会在 Sensor_Init() 时读取寄存器(一次、两次或中间有延迟)。但是从 Tx 计时器事件调用相同的函数不会产生任何结果。我试过直接调用 I2C_id() 函数,或者在启动时调用相同的 Sensor_Init() 函数。
传感器节点以前工作过,因为我已经从传感器获得了一些看似正确的数据的上行链路,但这充其量只是偶尔发生,我无法重现。
低于典型的串行读取输出。它在重置后启动。占空比设置为一分钟。可能值得一提的是,加入通常需要多次尝试,而且看起来成功的传输通常不会显示在 TTN 控制台中。
13:46:11.479 -> APP_VERSION: V1.1.0
13:46:11.479 -> MW_LORAWAN_VERSION: V2.3.0
13:46:11.479 -> MW_RADIO_VERSION: V1.1.0
13:46:11.479 -> ###### OTAA ######
13:46:11.479 -> ###### AppKey: F1:06:29:B9:4E:43:E4:98:**:**:**:**:**:**:**:**
13:46:11.479 -> ###### NwkKey: F2:62:58:D1:C9:0C:89:F4:**:**:**:**:**:**:**:**
13:46:11.479 -> ###### ABP ######
13:27:48.576 -> ###### AppSKey: 00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00
13:27:48.576 -> ###### NwkSKey: 00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00
13:27:48.576 -> ###### DevEui: 70:B3:D5:7E:D0:04:AB:31
13:27:48.576 -> ###### AppEui: 87:65:43:21:12:34:56:78
13:27:48.576 -> ###### DevAddr: 00:1F:28:32
13:27:48.576 -> 0s040:TX on freq 868500000 Hz at DR 0
13:27:48.576 -> Sensor_Init------------------------
13:27:48.576 -> WhoAmI ID: 0xB3
13:27:50.027 -> 1s527:MAC txDone
13:27:53.583 -> WhoAmI ID: 0xB3
13:27:58.595 -> 10s079:RX_1 on freq 868500000 Hz at DR 0
13:27:58.784 -> 10s277:IRQ_RX_TX_TIMEOUT
13:27:58.784 -> 10s277:MAC rxTimeOut
13:27:58.784 ->
13:27:58.784 -> ###### = JOIN FAILED
13:28:49.519 -> Kan geen verbinding maken met de sensor (read)!
13:28:49.519 -> WhoAmI ID: 0x0
13:28:49.519 -> Sensor_Init------------------------
13:28:50.505 -> Kan geen verbinding maken met de sensor (read)!
13:28:50.505 -> WhoAmI ID: 0x0
13:28:56.511 -> Kan geen verbinding maken met de sensor (read)!
13:28:56.511 -> WhoAmI ID: 0x0
13:28:56.511 -> 67s977:temp= 21
13:28:56.511 ->
67s977:VDDA= 254
13:28:56.511 -> 67s982:TX on freq 868500000 Hz at DR 0
13:28:56.511 -> Sensor_Init------------------------
13:28:57.450 -> Kan geen verbinding maken met de sensor (read)!
13:28:57.450 -> WhoAmI ID: 0x0
13:28:57.967 -> 69s469:MAC txDone
13:29:03.451 -> Kan geen verbinding maken met de sensor (read)!
13:29:03.451 -> WhoAmI ID: 0x0
13:29:08.472 -> 79s975:RX_1 on freq 868500000 Hz at DR 0
13:29:08.663 -> 80s173:IRQ_RX_TX_TIMEOUT
13:29:08.663 -> 80s173:MAC rxTimeOut
13:29:08.663 ->
13:29:08.663 -> ###### = JOIN FAILED
.
.
.
自定义文件:
void Sensor_Init(void){
APP_LOG(TS_OFF, VLEVEL_M, "Sensor_Init------------------------\r\n")
I2C_id(); //both of these work
HAL_Delay(5000);
I2C_id(); //both of these work
return;
}
uint8_t I2C_id(void){
static const uint8_t WhoAmI = 0x0F; // WhoAmI register
HAL_StatusTypeDef ret;
ret=8;
uint8_t var[1];
var[0]=0x0;
ret=platform_read(&hi2c2, WhoAmI, var, 1);
APP_LOG(TS_OFF, VLEVEL_M, "WhoAmI ID: 0x%X\n",var[0]);
}
static int32_t platform_read(void *handle, uint8_t Reg, uint8_t *Bufp, uint16_t len){
HAL_StatusTypeDef ret;
uint8_t reg[1];
reg[0]=Reg;
ret=HAL_I2C_Master_Transmit(&hi2c2, addr_write, reg, 1, 1000);
if(len>0 && !ret){
ret=HAL_I2C_Master_Receive(&hi2c2, addr_read, Bufp, len, 1000);
}
else if(ret){
// error
}
return ret;
}
lora_app.c:
LoRaWAN_Init(void){
.
.
.
UTIL_SEQ_RegTask((1 << CFG_SEQ_Task_ApplicatieInit), UTIL_SEQ_RFU, Sensor_Init);
UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_ApplicatieInit), CFG_SEQ_Prio_0); //this calls Sensor_Init() and succesfully runs I2C_id()
.
.
.
}
static void OnTxTimerEvent(void *context)
{
/* USER CODE BEGIN OnTxTimerEvent_1 */
I2C_id(); //this does not work
//==================================================================
UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_ApplicatieInit), CFG_SEQ_Prio_0); //this calls Sensor_Init() but doesn't succesfully run I2C_id()
//==================================================================
/* USER CODE END OnTxTimerEvent_1 */
UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_LoRaSendOnTxTimerOrButtonEvent), CFG_SEQ_Prio_0);
/*Wait for next tx slot*/
UTIL_TIMER_Start(&TxTimer);
}
希望有人能给我指出正确的方向。
@kkrambo 的评论似乎指向了正确的方向。我没有从 OnTxTimerEvent() 函数中调用我的函数,而是在软件中调用它,其中传感器数据被编码为 LoRaWAN 消息。
我一直在尝试将 Seeed studio 的 LoRa-E5-Mini 上的 STM32WL55JC1 微控制器编程为 LoRaWAN 端节点,并将气压数据从 ST LPS22HH 传感器中继到物联网。
我认为我遇到的问题一定是在代码中。原因是在初始化时,读取传感器的 WhoAmI 寄存器会产生结果。但之后每次,根据 LoRaWAN 节点的工作周期,调用该函数都不会产生任何结果,我无法连接到传感器。这保持不变,无法读取 WhoAmI 寄存器的每个 Tx 事件。
每次我重置 MCU 时,都会在 Sensor_Init() 时读取寄存器(一次、两次或中间有延迟)。但是从 Tx 计时器事件调用相同的函数不会产生任何结果。我试过直接调用 I2C_id() 函数,或者在启动时调用相同的 Sensor_Init() 函数。
传感器节点以前工作过,因为我已经从传感器获得了一些看似正确的数据的上行链路,但这充其量只是偶尔发生,我无法重现。
低于典型的串行读取输出。它在重置后启动。占空比设置为一分钟。可能值得一提的是,加入通常需要多次尝试,而且看起来成功的传输通常不会显示在 TTN 控制台中。
13:46:11.479 -> APP_VERSION: V1.1.0
13:46:11.479 -> MW_LORAWAN_VERSION: V2.3.0
13:46:11.479 -> MW_RADIO_VERSION: V1.1.0
13:46:11.479 -> ###### OTAA ######
13:46:11.479 -> ###### AppKey: F1:06:29:B9:4E:43:E4:98:**:**:**:**:**:**:**:**
13:46:11.479 -> ###### NwkKey: F2:62:58:D1:C9:0C:89:F4:**:**:**:**:**:**:**:**
13:46:11.479 -> ###### ABP ######
13:27:48.576 -> ###### AppSKey: 00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00
13:27:48.576 -> ###### NwkSKey: 00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00
13:27:48.576 -> ###### DevEui: 70:B3:D5:7E:D0:04:AB:31
13:27:48.576 -> ###### AppEui: 87:65:43:21:12:34:56:78
13:27:48.576 -> ###### DevAddr: 00:1F:28:32
13:27:48.576 -> 0s040:TX on freq 868500000 Hz at DR 0
13:27:48.576 -> Sensor_Init------------------------
13:27:48.576 -> WhoAmI ID: 0xB3
13:27:50.027 -> 1s527:MAC txDone
13:27:53.583 -> WhoAmI ID: 0xB3
13:27:58.595 -> 10s079:RX_1 on freq 868500000 Hz at DR 0
13:27:58.784 -> 10s277:IRQ_RX_TX_TIMEOUT
13:27:58.784 -> 10s277:MAC rxTimeOut
13:27:58.784 ->
13:27:58.784 -> ###### = JOIN FAILED
13:28:49.519 -> Kan geen verbinding maken met de sensor (read)!
13:28:49.519 -> WhoAmI ID: 0x0
13:28:49.519 -> Sensor_Init------------------------
13:28:50.505 -> Kan geen verbinding maken met de sensor (read)!
13:28:50.505 -> WhoAmI ID: 0x0
13:28:56.511 -> Kan geen verbinding maken met de sensor (read)!
13:28:56.511 -> WhoAmI ID: 0x0
13:28:56.511 -> 67s977:temp= 21
13:28:56.511 ->
67s977:VDDA= 254
13:28:56.511 -> 67s982:TX on freq 868500000 Hz at DR 0
13:28:56.511 -> Sensor_Init------------------------
13:28:57.450 -> Kan geen verbinding maken met de sensor (read)!
13:28:57.450 -> WhoAmI ID: 0x0
13:28:57.967 -> 69s469:MAC txDone
13:29:03.451 -> Kan geen verbinding maken met de sensor (read)!
13:29:03.451 -> WhoAmI ID: 0x0
13:29:08.472 -> 79s975:RX_1 on freq 868500000 Hz at DR 0
13:29:08.663 -> 80s173:IRQ_RX_TX_TIMEOUT
13:29:08.663 -> 80s173:MAC rxTimeOut
13:29:08.663 ->
13:29:08.663 -> ###### = JOIN FAILED
.
.
.
自定义文件:
void Sensor_Init(void){
APP_LOG(TS_OFF, VLEVEL_M, "Sensor_Init------------------------\r\n")
I2C_id(); //both of these work
HAL_Delay(5000);
I2C_id(); //both of these work
return;
}
uint8_t I2C_id(void){
static const uint8_t WhoAmI = 0x0F; // WhoAmI register
HAL_StatusTypeDef ret;
ret=8;
uint8_t var[1];
var[0]=0x0;
ret=platform_read(&hi2c2, WhoAmI, var, 1);
APP_LOG(TS_OFF, VLEVEL_M, "WhoAmI ID: 0x%X\n",var[0]);
}
static int32_t platform_read(void *handle, uint8_t Reg, uint8_t *Bufp, uint16_t len){
HAL_StatusTypeDef ret;
uint8_t reg[1];
reg[0]=Reg;
ret=HAL_I2C_Master_Transmit(&hi2c2, addr_write, reg, 1, 1000);
if(len>0 && !ret){
ret=HAL_I2C_Master_Receive(&hi2c2, addr_read, Bufp, len, 1000);
}
else if(ret){
// error
}
return ret;
}
lora_app.c:
LoRaWAN_Init(void){
.
.
.
UTIL_SEQ_RegTask((1 << CFG_SEQ_Task_ApplicatieInit), UTIL_SEQ_RFU, Sensor_Init);
UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_ApplicatieInit), CFG_SEQ_Prio_0); //this calls Sensor_Init() and succesfully runs I2C_id()
.
.
.
}
static void OnTxTimerEvent(void *context)
{
/* USER CODE BEGIN OnTxTimerEvent_1 */
I2C_id(); //this does not work
//==================================================================
UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_ApplicatieInit), CFG_SEQ_Prio_0); //this calls Sensor_Init() but doesn't succesfully run I2C_id()
//==================================================================
/* USER CODE END OnTxTimerEvent_1 */
UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_LoRaSendOnTxTimerOrButtonEvent), CFG_SEQ_Prio_0);
/*Wait for next tx slot*/
UTIL_TIMER_Start(&TxTimer);
}
希望有人能给我指出正确的方向。
@kkrambo 的评论似乎指向了正确的方向。我没有从 OnTxTimerEvent() 函数中调用我的函数,而是在软件中调用它,其中传感器数据被编码为 LoRaWAN 消息。