Driving an SPI device that needs a Control/Data signal.

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
PeterO
Posts: 3
Joined: Fri Jul 14, 2017 1:10 pm

Driving an SPI device that needs a Control/Data signal.

Post by PeterO » Fri Jul 14, 2017 3:56 pm

Hi,

My first post :-) I've been using a Bit:2:Pi board from 4tronix.co.uk to drive an RPi Hat from a micro:bit. So far I've only tried an I2C device but I have that working OK. I'm using the "mu" editor on an PI3 to develop my code.

Now I'd like to move on to driving an Adafruit 3.5" TFT display. This uses SPI and I've been looking at the driver code in the RPI kernel sources and the HX8357 datasheet. The problem I see is that it is hard-wired to use a 4 wire interface with a "Control/Data" line that needs to be set low for the first bit of a command byte.

I'm and experienced C programmer so I think I should be able to tackle this, but I'm as yet unfamiliar with the MicroPython code base so I'm not sure where to start looking to add the required functionality so a few pointers to appropriate bits of the code would be helpful.

Thanks in advance
Peter Onion

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Driving an SPI device that needs a Control/Data signal.

Post by pythoncoder » Sat Jul 15, 2017 9:33 am

You need to look at the Pin class in the machine module http://docs.micropython.org/en/latest/e ... e.Pin.html.
Peter Hinch
Index to my micropython libraries.

PeterO
Posts: 3
Joined: Fri Jul 14, 2017 1:10 pm

Re: Driving an SPI device that needs a Control/Data signal.

Post by PeterO » Sun Jul 16, 2017 11:15 am

The machine import doesn't seem to be available on the version of MicroPython included with Mu 0.9.13 :-(
PeterO

User avatar
deshipu
Posts: 1388
Joined: Thu May 28, 2015 5:54 pm

Re: Driving an SPI device that needs a Control/Data signal.

Post by deshipu » Sun Jul 16, 2017 10:11 pm

You might want to take a look at how it's handled in the Adafruit's display libraries at https://github.com/adafruit/micropython ... gb-display

PeterO
Posts: 3
Joined: Fri Jul 14, 2017 1:10 pm

Re: Driving an SPI device that needs a Control/Data signal.

Post by PeterO » Mon Jul 17, 2017 5:46 am

[quote="deshipu"]You might want to take a look at how it's handled in the Adafruit's display libraries at https://github.com/adafruit/micropython ... gb-display[/quote]

Thanks, that's very helpful ! I had worked out some of the stuff I need already, and even though they don't include exactly the device I have it will be a good starting point :-)

PeterO

User avatar
deshipu
Posts: 1388
Joined: Thu May 28, 2015 5:54 pm

Re: Driving an SPI device that needs a Control/Data signal.

Post by deshipu » Tue Jul 18, 2017 9:51 am

If you get it working with that library, a pull request would be great!

Post Reply