How to communicate with 40 bit SPI

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
Meekdai
Posts: 21
Joined: Mon Jan 29, 2018 12:45 pm

How to communicate with 40 bit SPI

Post by Meekdai » Tue Nov 06, 2018 9:19 am

pyb SPI bits can be 8 or 16, but TMC5130-TA is use 40 bit SPI. Does Pyboard have a way to communicate with this chip?
datasheet:https://www.trinamic.com/fileadmin/asse ... ev1.15.pdf
Chapter 4 on page 21, description of SPI

Thanks

loboris
Posts: 286
Joined: Fri Oct 02, 2015 6:19 pm

Re: How to communicate with 40 bit SPI

Post by loboris » Tue Nov 06, 2018 10:02 am

Just sent 5 bytes (= 40 bits).

Meekdai
Posts: 21
Joined: Mon Jan 29, 2018 12:45 pm

Re: How to communicate with 40 bit SPI

Post by Meekdai » Wed Nov 07, 2018 8:59 am

Here is my code, but it doesn't works.

Code: Select all

    def writeReg(self,regaddr,data):
        self.tmc_cs.low()
        self.spi.send(regaddr|0x80)
        self.spi.send(0xFF & (data>>24))
        self.spi.send(0xFF & (data>>16))
        self.spi.send(0xFF & (data>>8))
        self.spi.send(0xFF & (data>>0))
        self.tmc_cs.high()

loboris
Posts: 286
Joined: Fri Oct 02, 2015 6:19 pm

Re: How to communicate with 40 bit SPI

Post by loboris » Wed Nov 07, 2018 9:39 am

Pack your regaddr and data to one 5-byte bytearray and send it in one SPI transaction.

Meekdai
Posts: 21
Joined: Mon Jan 29, 2018 12:45 pm

Re: How to communicate with 40 bit SPI

Post by Meekdai » Thu Nov 08, 2018 1:58 am

Code: Select all

    def writeReg(self,regaddr,data):
        self.tmc_cs.low()
        ba=bytes([regaddr|0x80,0xFF&(data>>24),0xFF&(data>>16),0xFF&(data>>8),0xFF&data])
        reg_val=self.spi.send_recv(ba)
        self.tmc_cs.high()
        self.reg_status=reg_val[0]>>32
        return reg_val
It works well , thanks !

Post Reply