diff --git a/esphome/components/spi/spi.h b/esphome/components/spi/spi.h index 64364d70c9..05c64150cc 100644 --- a/esphome/components/spi/spi.h +++ b/esphome/components/spi/spi.h @@ -112,20 +112,34 @@ class SPIComponent : public Component { template uint8_t transfer_byte(uint8_t data) { - if (this->hw_spi_ != nullptr) { - return this->hw_spi_->transfer(data); + if (this->miso_ != nullptr) { + if (this->hw_spi_ != nullptr) { + return this->hw_spi_->transfer(data); + } else { + return this->transfer_(data); + } } - return this->transfer_(data); + this->write_byte(data); + return 0; } template void transfer_array(uint8_t *data, size_t length) { if (this->hw_spi_ != nullptr) { - this->hw_spi_->transfer(data, length); + if (this->miso_ != nullptr) { + this->hw_spi_->transfer(data, length); + } else { + this->hw_spi_->writeBytes(data, length); + } return; } - for (size_t i = 0; i < length; i++) { - data[i] = this->transfer_byte(data[i]); + + if (this->miso_ != nullptr) { + for (size_t i = 0; i < length; i++) { + data[i] = this->transfer_byte(data[i]); + } + } else { + this->write_array(data, length); } }