SPI with Unity - Red Amber - How does it work?

Something's not clear? Encountered a bug or an error? This is the place to report.
Posts: 1
Joined: Sat Apr 08, 2017 6:41 pm

SPI with Unity - Red Amber - How does it work?

Postby thiemo » Sat Apr 08, 2017 7:17 pm


I am trying to control a ATMEL QTouch AT42QT1111 via Unity (Android 4.4 smartphone) and SPI.

If I request the Device ID, the slave should return the value 59.
Only gem.WriteReadSpi(0,new byte[0xC9,0x00]) returns data: 55,C9 . But there should be a response like: 55,59 according to the Atmel datasheet.
Actually, 55 means that the Atmel received the request and C9 is the command I sent. I don't know, why it returns the byte I sent to the slave and not the byte 59.
Here is my test code:

Code: Select all

public void  SPI_DeviceID()
      //Read 1 byte from SPI bus. Request ID is 0xCA
      gem.WriteReadSpi (0,new byte[] {0xC9,0x00});
      gem.OnSpiData += (SpiData data) => {
         byte[] lastPacket = data.Data;
         string bytetest ="";
         int len = lastPacket.Length;
         for (int i =0; i < len; i++){
               bytetest +=",";
            bytetest += lastPacket[i].ToString("X");
         ConsoleText.text = bytetest;
         Debug.Log ("The byte is: " + bytetest);

I tried also to use gem.WriteSpi and gem.ReadSpi - there was no response from the SPI slave - I have no Idea how to use gem.WriteSpi and gem.ReadSpi. I also don't understand the usage of the requestID.
The AT42QT1111 SPI Interface can operate at speed of up to 750kHz - do I need to change any value here for the SPI communication?
see page4: http://ww1.microchip.com/downloads/en/AppNotes/doc42040.pdf
Do you have more information about the SPI commands and setup you are using for the red amber?

Thank you for your feedback!

Gemsense Team
Gemsense Team
Posts: 7
Joined: Wed Jan 20, 2016 12:06 pm

Re: SPI with Unity - Red Amber - How does it work?

Postby michael » Wed Apr 12, 2017 7:44 am


You code looks fine. I suppose there's might be something wrong about NSS (chip select) pin. Is it connected to Atmel chip?

You have data transfer working, but the Atmel chip doesn't see where is the start of a command, what usually depends on NSS pin

Best regards,
Michael Shtutman
Android, Unity and firmware developer in Gemsense

Return to “Support”

Who is online

Users browsing this forum: No registered users and 1 guest