Skip to content

Commit ba7c85d

Browse files
narangmayanknashif
authored andcommitted
drivers: sensor: lis2de12: fix read accel via spi
The lis2de12 sensor driver spi interface was calling spi read api. This leads to a single byte operation on reading acceleration data which is a multi byte operation. Fix it by adding a call to spi read incr api instead. Added a length check to handle both single and multi byte read properly. Signed-off-by: Mayank Narang <[email protected]> (cherry picked from commit 7b062f5)
1 parent 4aa3e56 commit ba7c85d

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

drivers/sensor/st/lis2de12/lis2de12.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ static int lis2de12_init(const struct device *dev)
435435

436436
#define LIS2DE12_CONFIG_SPI(inst) \
437437
{ \
438-
STMEMSC_CTX_SPI(&lis2de12_config_##inst.stmemsc_cfg), \
438+
STMEMSC_CTX_SPI_INCR(&lis2de12_config_##inst.stmemsc_cfg), \
439439
.stmemsc_cfg = { \
440440
.spi = SPI_DT_SPEC_INST_GET(inst, LIS2DE12_SPI_OP, 0), \
441441
}, \

drivers/sensor/st/stmemsc/stmemsc_spi.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ int stmemsc_spi_write(const struct spi_dt_spec *stmemsc,
6363
int stmemsc_spi_read_incr(const struct spi_dt_spec *stmemsc,
6464
uint8_t reg_addr, uint8_t *value, uint8_t len)
6565
{
66-
reg_addr |= STMEMSC_SPI_ADDR_AUTO_INCR;
66+
if (len > 1) {
67+
reg_addr |= STMEMSC_SPI_ADDR_AUTO_INCR;
68+
}
69+
6770
return stmemsc_spi_read(stmemsc, reg_addr, value, len);
6871
}
6972

0 commit comments

Comments
 (0)