2525 * THE SOFTWARE.
2626 */
2727#include <stdbool.h>
28+ #include <string.h>
2829
2930#include "shared-bindings/busio/SPI.h"
3031#include "py/mperrno.h"
@@ -340,7 +341,7 @@ bool common_hal_busio_spi_write(busio_spi_obj_t *self,
340341 if (self -> mosi == NULL ) {
341342 mp_raise_ValueError (translate ("No MOSI Pin" ));
342343 }
343- HAL_StatusTypeDef result = HAL_SPI_Transmit (& self -> handle , (uint8_t * )data , (uint16_t )len , HAL_MAX_DELAY );
344+ HAL_StatusTypeDef result = HAL_SPI_Transmit (& self -> handle , (uint8_t * )data , (uint16_t )len , HAL_MAX_DELAY );
344345 return result == HAL_OK ;
345346}
346347
@@ -349,7 +350,13 @@ bool common_hal_busio_spi_read(busio_spi_obj_t *self,
349350 if (self -> miso == NULL ) {
350351 mp_raise_ValueError (translate ("No MISO Pin" ));
351352 }
352- HAL_StatusTypeDef result = HAL_SPI_Receive (& self -> handle , data , (uint16_t )len , HAL_MAX_DELAY );
353+ HAL_StatusTypeDef result = HAL_OK ;
354+ if (self -> mosi == NULL ) {
355+ result = HAL_SPI_Receive (& self -> handle , data , (uint16_t )len , HAL_MAX_DELAY );
356+ } else {
357+ memset (data , write_value , len );
358+ result = HAL_SPI_TransmitReceive (& self -> handle , data , data , (uint16_t )len , HAL_MAX_DELAY );
359+ }
353360 return result == HAL_OK ;
354361}
355362
@@ -358,7 +365,7 @@ bool common_hal_busio_spi_transfer(busio_spi_obj_t *self,
358365 if (self -> miso == NULL || self -> mosi == NULL ) {
359366 mp_raise_ValueError (translate ("Missing MISO or MOSI Pin" ));
360367 }
361- HAL_StatusTypeDef result = HAL_SPI_TransmitReceive (& self -> handle ,
368+ HAL_StatusTypeDef result = HAL_SPI_TransmitReceive (& self -> handle ,
362369 (uint8_t * ) data_out , data_in , (uint16_t )len ,HAL_MAX_DELAY );
363370 return result == HAL_OK ;
364371}
0 commit comments