From c3efcd9c8d1177019711c776bc925645a6ea6b0b Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Fri, 4 Jan 2019 22:26:34 -0500 Subject: [PATCH] bus: Set all SPI CS pins high before first config_spi message If an SPI device is shared among many devices, then all the device's CS pins should be set high prior to setting up the clk pin. (Otherwise, there's a chance a device could interpret the clk pin setup as part of a transmission.) Signed-off-by: Kevin O'Connor --- klippy/extras/bus.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/klippy/extras/bus.py b/klippy/extras/bus.py index 9721a591..6df95ee5 100644 --- a/klippy/extras/bus.py +++ b/klippy/extras/bus.py @@ -17,12 +17,14 @@ class MCU_SPI: shutdown_msg = "".join(["%02x" % (x,) for x in shutdown_seq]) self.oid = self.mcu.create_oid() if pin is None: - self.mcu.add_config_cmd( + self.config_msg = ( "config_spi_without_cs oid=%d bus=%d mode=%d rate=%d" " shutdown_msg=%s" % ( self.oid, bus, mode, speed, shutdown_msg)) else: - self.mcu.add_config_cmd( + # Set all CS pins high before first config_spi + self.mcu.add_config_cmd("set_digital_out pin=%s value=1" % (pin,)) + self.config_msg = ( "config_spi oid=%d bus=%d pin=%s mode=%d rate=%d" " shutdown_msg=%s" % ( self.oid, bus, pin, mode, speed, shutdown_msg)) @@ -36,6 +38,7 @@ class MCU_SPI: def get_command_queue(self): return self.cmd_queue def build_config(self): + self.mcu.add_config_cmd(self.config_msg) self.spi_send_cmd = self.mcu.lookup_command( "spi_send oid=%c data=%*s", cq=self.cmd_queue) self.spi_transfer_cmd = self.mcu.lookup_command(