Disable UART IRQs during sensor readout
This commit is contained in:
parent
3abe7568b0
commit
a290f52d4d
@ -75,6 +75,8 @@ extern "C" {
|
|||||||
void Error_Handler(void);
|
void Error_Handler(void);
|
||||||
|
|
||||||
/* USER CODE BEGIN EFP */
|
/* USER CODE BEGIN EFP */
|
||||||
|
int8_t uart_disable_interrupts(void);
|
||||||
|
int8_t uart_enable_interrupts(void);
|
||||||
|
|
||||||
/* USER CODE END EFP */
|
/* USER CODE END EFP */
|
||||||
|
|
||||||
|
@ -269,15 +269,17 @@ int main(void)
|
|||||||
if (baudrate_changed)
|
if (baudrate_changed)
|
||||||
{
|
{
|
||||||
while (!LL_LPUART_IsActiveFlag_TXE(LPUART1));
|
while (!LL_LPUART_IsActiveFlag_TXE(LPUART1));
|
||||||
LL_LPUART_Disable(LPUART1);
|
uart_disable_interrupts();
|
||||||
LL_LPUART_DisableIT_IDLE(LPUART1);
|
// LL_LPUART_Disable(LPUART1);
|
||||||
LL_LPUART_EnableIT_RXNE(LPUART1);
|
// LL_LPUART_DisableIT_IDLE(LPUART1);
|
||||||
|
// LL_LPUART_EnableIT_RXNE(LPUART1);
|
||||||
|
|
||||||
LL_LPUART_SetBaudRate(LPUART1, SYSTICK_FREQ_HZ, config_baudrates[sensor_config.baudrate_index]);
|
LL_LPUART_SetBaudRate(LPUART1, SYSTICK_FREQ_HZ, config_baudrates[sensor_config.baudrate_index]);
|
||||||
|
|
||||||
LL_LPUART_Enable(LPUART1);
|
// LL_LPUART_Enable(LPUART1);
|
||||||
LL_LPUART_EnableIT_IDLE(LPUART1);
|
// LL_LPUART_EnableIT_IDLE(LPUART1);
|
||||||
LL_LPUART_EnableIT_RXNE(LPUART1);
|
// LL_LPUART_EnableIT_RXNE(LPUART1);
|
||||||
|
uart_enable_interrupts();
|
||||||
LL_LPUART_EnableDirectionRx(LPUART1);
|
LL_LPUART_EnableDirectionRx(LPUART1);
|
||||||
LL_LPUART_EnableDirectionTx(LPUART1);
|
LL_LPUART_EnableDirectionTx(LPUART1);
|
||||||
baudrate_changed = 0;
|
baudrate_changed = 0;
|
||||||
@ -645,6 +647,24 @@ void LPUART1_TX_Buffer(uint8_t* buffer_tx, uint16_t buffer_tx_len)
|
|||||||
__enable_irq();
|
__enable_irq();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int8_t uart_disable_interrupts(void)
|
||||||
|
{
|
||||||
|
LL_LPUART_Disable(LPUART1);
|
||||||
|
LL_LPUART_DisableIT_IDLE(LPUART1);
|
||||||
|
LL_LPUART_EnableIT_RXNE(LPUART1);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int8_t uart_enable_interrupts(void)
|
||||||
|
{
|
||||||
|
LL_LPUART_Enable(LPUART1);
|
||||||
|
LL_LPUART_EnableIT_IDLE(LPUART1);
|
||||||
|
LL_LPUART_EnableIT_RXNE(LPUART1);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int8_t modbus_slave_callback(modbus_transaction_t *transaction)
|
int8_t modbus_slave_callback(modbus_transaction_t *transaction)
|
||||||
{
|
{
|
||||||
uint16_t register_number = transaction->register_number;
|
uint16_t register_number = transaction->register_number;
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "scd4x.h"
|
#include "scd4x.h"
|
||||||
|
#include "main.h" /* for uart_disable_interrupts() */
|
||||||
|
|
||||||
int8_t scd4x_send_cmd(scd4x_cmd_t cmd)
|
int8_t scd4x_send_cmd(scd4x_cmd_t cmd)
|
||||||
{
|
{
|
||||||
@ -74,8 +75,9 @@ int8_t scd4x_read_measurement(uint16_t * co2, int16_t *temperature, uint16_t *re
|
|||||||
/*if (result != I2C_OK) {
|
/*if (result != I2C_OK) {
|
||||||
return SCD4X_ERROR;
|
return SCD4X_ERROR;
|
||||||
}*/
|
}*/
|
||||||
|
uart_disable_interrupts();
|
||||||
LL_mDelay(1); // 10 ms should be enough
|
LL_mDelay(1); // 10 ms should be enough
|
||||||
|
uart_enable_interrupts();
|
||||||
// read out
|
// read out
|
||||||
result = i2c_receive(SCD4X_I2C_ADDRESS<<1, buffer, 9);
|
result = i2c_receive(SCD4X_I2C_ADDRESS<<1, buffer, 9);
|
||||||
if (result != I2C_OK)
|
if (result != I2C_OK)
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "sht4x.h"
|
#include "sht4x.h"
|
||||||
|
#include "main.h" /* for uart_disable_interrupts() */
|
||||||
|
|
||||||
int8_t sht4x_send_cmd(sht4x_cmd_t cmd)
|
int8_t sht4x_send_cmd(sht4x_cmd_t cmd)
|
||||||
{
|
{
|
||||||
@ -30,7 +31,9 @@ int8_t sht4x_measure(int16_t *temperature, uint16_t *relative_humidity)
|
|||||||
if (result != I2C_OK) {
|
if (result != I2C_OK) {
|
||||||
return SHT4X_ERROR;
|
return SHT4X_ERROR;
|
||||||
}*/
|
}*/
|
||||||
|
uart_disable_interrupts();
|
||||||
LL_mDelay(10); // 10 ms should be enough
|
LL_mDelay(10); // 10 ms should be enough
|
||||||
|
uart_enable_interrupts();
|
||||||
// read out
|
// read out
|
||||||
result = i2c_receive(SHT4X_I2C_ADDRESS<<1, buffer, 6);
|
result = i2c_receive(SHT4X_I2C_ADDRESS<<1, buffer, 6);
|
||||||
if (result != I2C_OK) {
|
if (result != I2C_OK) {
|
||||||
|
Loading…
Reference in New Issue
Block a user