piface/libmcp23s17

libmcp23s17 gets There was a error during the SPI transaction on read_reg / write_reg operations

DougieLawson opened this issue · 3 comments

I'm running Raspbian with the 3.18.4+ kernel and the device tree. There's a bug where read_reg or write_reg gets a "error during the SPI transaction".

I've chased the bug to mcp23s17.c and can fix it with this patch

--- /shared/Raspi/libmcp23s17~/src/mcp23s17.c   2015-01-29 23:23:28.967496000 +0000
+++ mcp23s17.c  2015-01-29 22:33:48.777496000 +0000
@@ -72,6 +72,7 @@
     uint8_t rx_buf[sizeof tx_buf];

     struct spi_ioc_transfer spi;
+    memset (&spi, 0, sizeof(spi));
     spi.tx_buf = (unsigned long) tx_buf;
     spi.rx_buf = (unsigned long) rx_buf;
     spi.len = sizeof tx_buf;
@@ -98,6 +99,7 @@
     uint8_t rx_buf[sizeof tx_buf];

     struct spi_ioc_transfer spi;
+    memset (&spi, 0, sizeof(spi));
     spi.tx_buf = (unsigned long) tx_buf;
     spi.rx_buf = (unsigned long) rx_buf;
     spi.len = sizeof tx_buf;

That's great news, would you mind submitting a pull request to merge this in?

Sorry, I don't know what that means.

A pull request is basically github's way of merging patches. Don't worry, I've added it in. Thanks for the patch. :)