Fixed uart interrupt enable/disable
This commit is contained in:
parent
3ff1369352
commit
f45fca91fb
@ -659,6 +659,8 @@ int8_t uart_disable_interrupts(void)
|
|||||||
int8_t uart_enable_interrupts(void)
|
int8_t uart_enable_interrupts(void)
|
||||||
{
|
{
|
||||||
LL_LPUART_Enable(LPUART1);
|
LL_LPUART_Enable(LPUART1);
|
||||||
|
LL_LPUART_ClearFlag_IDLE(LPUART1);
|
||||||
|
LL_LPUART_ClearFlag_NE(LPUART1);
|
||||||
LL_LPUART_EnableIT_IDLE(LPUART1);
|
LL_LPUART_EnableIT_IDLE(LPUART1);
|
||||||
LL_LPUART_EnableIT_RXNE(LPUART1);
|
LL_LPUART_EnableIT_RXNE(LPUART1);
|
||||||
|
|
||||||
|
@ -66,6 +66,8 @@ int8_t scd4x_read_measurement(uint16_t * co2, int16_t *temperature, uint16_t *re
|
|||||||
}*/
|
}*/
|
||||||
|
|
||||||
|
|
||||||
|
// disable interrupts to prevent MODBUS/I2C conflict
|
||||||
|
uart_disable_interrupts();
|
||||||
// start measurement
|
// start measurement
|
||||||
buffer[0] = SCD4X_READ_MEASUREMENT >> 8;
|
buffer[0] = SCD4X_READ_MEASUREMENT >> 8;
|
||||||
buffer[1] = SCD4X_READ_MEASUREMENT & 0x00ff;
|
buffer[1] = SCD4X_READ_MEASUREMENT & 0x00ff;
|
||||||
@ -80,6 +82,7 @@ int8_t scd4x_read_measurement(uint16_t * co2, int16_t *temperature, uint16_t *re
|
|||||||
uart_disable_interrupts();
|
uart_disable_interrupts();
|
||||||
// read out
|
// read out
|
||||||
result = i2c_receive(SCD4X_I2C_ADDRESS<<1, buffer, 9);
|
result = i2c_receive(SCD4X_I2C_ADDRESS<<1, buffer, 9);
|
||||||
|
uart_enable_interrupts();
|
||||||
if (result != I2C_OK)
|
if (result != I2C_OK)
|
||||||
{
|
{
|
||||||
return SCD4X_ERROR;
|
return SCD4X_ERROR;
|
||||||
|
@ -23,6 +23,8 @@ int8_t sht4x_measure(int16_t *temperature, uint16_t *relative_humidity)
|
|||||||
uint8_t buffer[32];
|
uint8_t buffer[32];
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
|
// disable interrupts
|
||||||
|
uart_disable_interrupts();
|
||||||
// start measurement
|
// start measurement
|
||||||
buffer[0] = SHT4X_START_MEAS_HIGH_PRECISION;
|
buffer[0] = SHT4X_START_MEAS_HIGH_PRECISION;
|
||||||
result = i2c_transmit(SHT4X_I2C_ADDRESS<<1, buffer, 1);
|
result = i2c_transmit(SHT4X_I2C_ADDRESS<<1, buffer, 1);
|
||||||
@ -31,11 +33,14 @@ 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;
|
||||||
}*/
|
}*/
|
||||||
|
// enable interrupts while waiting
|
||||||
uart_enable_interrupts();
|
uart_enable_interrupts();
|
||||||
LL_mDelay(10); // 10 ms should be enough
|
LL_mDelay(10); // 10 ms should be enough
|
||||||
uart_disable_interrupts();
|
uart_disable_interrupts();
|
||||||
// read out
|
// read out
|
||||||
result = i2c_receive(SHT4X_I2C_ADDRESS<<1, buffer, 6);
|
result = i2c_receive(SHT4X_I2C_ADDRESS<<1, buffer, 6);
|
||||||
|
// enable interrupts again
|
||||||
|
uart_enable_interrupts();
|
||||||
if (result != I2C_OK) {
|
if (result != I2C_OK) {
|
||||||
return SHT4X_ERROR;
|
return SHT4X_ERROR;
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
@ -17,6 +17,8 @@ stm32l0xx_ll_lpuart.h:1233:22:LL_LPUART_SetDEAssertionTime 16 static
|
|||||||
stm32l0xx_ll_lpuart.h:1255:22:LL_LPUART_EnableDEMode 16 static
|
stm32l0xx_ll_lpuart.h:1255:22:LL_LPUART_EnableDEMode 16 static
|
||||||
stm32l0xx_ll_lpuart.h:1291:22:LL_LPUART_SetDESignalPolarity 16 static
|
stm32l0xx_ll_lpuart.h:1291:22:LL_LPUART_SetDESignalPolarity 16 static
|
||||||
stm32l0xx_ll_lpuart.h:1400:26:LL_LPUART_IsActiveFlag_TXE 16 static
|
stm32l0xx_ll_lpuart.h:1400:26:LL_LPUART_IsActiveFlag_TXE 16 static
|
||||||
|
stm32l0xx_ll_lpuart.h:1533:22:LL_LPUART_ClearFlag_NE 16 static
|
||||||
|
stm32l0xx_ll_lpuart.h:1555:22:LL_LPUART_ClearFlag_IDLE 16 static
|
||||||
stm32l0xx_ll_lpuart.h:1619:22:LL_LPUART_EnableIT_IDLE 16 static
|
stm32l0xx_ll_lpuart.h:1619:22:LL_LPUART_EnableIT_IDLE 16 static
|
||||||
stm32l0xx_ll_lpuart.h:1631:22:LL_LPUART_EnableIT_RXNE 16 static
|
stm32l0xx_ll_lpuart.h:1631:22:LL_LPUART_EnableIT_RXNE 16 static
|
||||||
stm32l0xx_ll_lpuart.h:1726:22:LL_LPUART_DisableIT_IDLE 16 static
|
stm32l0xx_ll_lpuart.h:1726:22:LL_LPUART_DisableIT_IDLE 16 static
|
||||||
@ -58,6 +60,6 @@ main.c:596:13:MX_GPIO_Init 32 static
|
|||||||
main.c:639:6:LPUART1_TX_Buffer 24 static,ignoring_inline_asm
|
main.c:639:6:LPUART1_TX_Buffer 24 static,ignoring_inline_asm
|
||||||
main.c:650:8:uart_disable_interrupts 8 static
|
main.c:650:8:uart_disable_interrupts 8 static
|
||||||
main.c:659:8:uart_enable_interrupts 8 static
|
main.c:659:8:uart_enable_interrupts 8 static
|
||||||
main.c:668:8:modbus_slave_callback 32 static
|
main.c:670:8:modbus_slave_callback 32 static
|
||||||
main.c:787:8:modbus_transmit_function 16 static
|
main.c:789:8:modbus_transmit_function 16 static
|
||||||
main.c:799:6:Error_Handler 8 static,ignoring_inline_asm
|
main.c:801:6:Error_Handler 8 static,ignoring_inline_asm
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -4,10 +4,10 @@ from sys import exit
|
|||||||
import minimalmodbus
|
import minimalmodbus
|
||||||
import serial
|
import serial
|
||||||
|
|
||||||
slave_address = 254
|
slave_address = 252
|
||||||
instrument = minimalmodbus.Instrument('/dev/rs485', slave_address, close_port_after_each_call=True) # port name, slave address (in decimal)
|
instrument = minimalmodbus.Instrument('/dev/rs485', slave_address, close_port_after_each_call=True) # port name, slave address (in decimal)
|
||||||
|
|
||||||
instrument.serial.baudrate = 19200
|
instrument.serial.baudrate = 115200
|
||||||
instrument.serial.bytesize = 8
|
instrument.serial.bytesize = 8
|
||||||
instrument.serial.parity = serial.PARITY_EVEN
|
instrument.serial.parity = serial.PARITY_EVEN
|
||||||
instrument.serial.stopbits = 1
|
instrument.serial.stopbits = 1
|
||||||
|
Loading…
Reference in New Issue
Block a user