title: Golang and SPI - trying to init RF522 drive
body: <p>I have a simple Python code that does initalize <a href="https://www.nxp.com/docs/en/data-sheet/MFRC522.pdf" rel="nofollow noreferrer">MFRC522</a> device properly:</p>
  
  <pre><code>    import spidev
  
      mode_reset = 0x0F
  
      def spi_transfer(data):
          r = spi.xfer2(data)
          return r
  
      def dev_write(address, value):
          r = spi_transfer([(address &lt;&lt; 1) &amp; 0x7E, value])
          print("&gt;&gt;",[(address &lt;&lt; 1) &amp; 0x7E, value], r)
          return r
  
      def reset():
          dev_write(0x01, mode_reset)
  
      spi = spidev.SpiDev()
      spi.open(0, 0)
      spi.max_speed_hz = 1000000
      print(spi.mode, spi.bits_per_word, spi.lsbfirst)
      reset()
  </code></pre>
  
  <p>that works perfectly fine - it returns the command code back <code>15</code>, but the same initialization routine implemented in Go doesn't really work:</p>
  
  <pre><code>    package main
  
      import (
          "fmt"
          "golang.org/x/exp/io/spi"
          "log"
      )
  
      func main() {
  
          spiDev, err := spi.Open(&amp;spi.Devfs{
              Dev:      "/dev/spidev0.0",
              Mode:     spi.Mode(spi.Mode0),
              MaxSpeed: int64(1000000),
          })
  
          spiDev.SetMode(spi.Mode0)
          spiDev.SetBitOrder(spi.MSBFirst)
          spiDev.SetBitsPerWord(8)
  
          if err != nil {
              log.Fatal(err)
          }
  
          writeSpiData := func(dataIn []byte) (out []byte, err error) {
              out = make([]byte, len(dataIn))
              err = spiDev.Tx(dataIn, out)
              return
          }
  
          devWrite := func(address int, data byte) (err error) {
              newData := [2]byte{(byte(address) &lt;&lt; 1) &amp; 0x7E, data}
              readBuf, err := writeSpiData(newData[0:])
              fmt.Println("&gt;&gt;", newData, readBuf)
              return
          }
  
          if err != nil {
              log.Fatal(err)
          }
  
          devWrite(0x01, 0x0F)
  
          fmt.Println("Done")
  
      }
  </code></pre>
  
  <p>This one returns <code>[0 0]</code> which is wrong. Does anyone know what might be wrong there?</p>