From 5c182ab460fef614e2b987c808d4b4e2c4240a4f Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 12 Nov 2022 19:35:26 -0800 Subject: [PATCH] altos/ms5607: Use duplex for fetching data Much more efficient than send/recv Signed-off-by: Keith Packard --- src/drivers/ao_ms5607.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/drivers/ao_ms5607.c b/src/drivers/ao_ms5607.c index 46da4e83..1e4cd159 100644 --- a/src/drivers/ao_ms5607.c +++ b/src/drivers/ao_ms5607.c @@ -154,8 +154,7 @@ ao_ms5607_isr(void) static uint32_t ao_ms5607_get_sample(uint8_t cmd) { - uint8_t reply[3]; - uint8_t read; + uint8_t reply[4]; ao_ms5607_done = 0; @@ -179,12 +178,12 @@ ao_ms5607_get_sample(uint8_t cmd) { #endif ao_ms5607_start(); - read = AO_MS5607_ADC_READ; - ao_spi_send(&read, 1, AO_MS5607_SPI_INDEX); - ao_spi_recv(&reply, 3, AO_MS5607_SPI_INDEX); + memset(reply, 0, sizeof(reply)); + reply[0] = AO_MS5607_ADC_READ; + ao_spi_duplex(&reply, &reply, 6, AO_MS5607_SPI_INDEX); ao_ms5607_stop(); - return ((uint32_t) reply[0] << 16) | ((uint32_t) reply[1] << 8) | (uint32_t) reply[2]; + return ((uint32_t) reply[1] << 16) | ((uint32_t) reply[2] << 8) | (uint32_t) reply[3]; } #ifndef AO_MS5607_BARO_OVERSAMPLE -- 2.30.2