FTDI Community

Please login or register.

Login with username, password and session length.
Advanced Search  

News:

Welcome to the FTDI Community!

Please read our Welcome Note

Technical Support enquires
please contact the team
@ FTDI Support


New Bridgetek Community is now open

Please note that we have created the Bridgetek Community to discuss all Bridgetek products e.g. EVE, MCU.

Please follow this link and create a new user account to get started.

Bridgetek Community

Author Topic: Using MM900EV-LITE as SPI Slave  (Read 230 times)

LOstrander

  • Newbie
  • *
  • Posts: 8
    • View Profile
Using MM900EV-LITE as SPI Slave
« on: June 20, 2019, 04:15:18 PM »

I have a touchscreen and controller that I'm using as an HMI in a larger system.  I want to use the MM900EV-LITE as a SPI Slave to send some data from the touchscreen to the main controller.  For some reason, whenever I try to write to the SPI_DATA register, the controller resets.

I'm using the exact same code as the example from the FT9xx Toolchain for a SPI Slave.

Code: [Select]
#include "GoButton.h"
#include "FT_Platform.h"
#include "FT_ESD.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "ff.h"
#include "FT_Platform_FT900.h"

#ifndef ESD_SIMULATION
#include "ft900.h"
#include "ft900_spi.h"
#endif

ESD_FUNCTION(GoButton_SendData)
ESD_PARAMETER(fptr, Type = int)
void GoButton_SendData(fptr)
{
#ifndef ESD_SIMULATION
#define APP_BUFFER_SIZE (8)

#define SPIS_FIFOSIZE (64)

uint8_t* spis_dev_buffer;
uint8_t spis_dev_buffer_size;
uint8_t spis_dev_buffer_ptr;

    // Enable the SPI Slave device...
    sys_enable(sys_device_spi_slave0);

    // Set GPIO36 to SPIS0_CLK, GPIO37 to SPIS0_SS, GPIO38 to SPIS0_MOSI and GPIO39 to SPIS0_MISO...
    gpio_function(36, pad_spis0_clk);
    gpio_function(37, pad_spis0_ss);
    gpio_function(38, pad_spis0_mosi);
    gpio_function(39, pad_spis0_miso);

gpio_function(66, pad_gpio66);

    // Configure directions for the SPI slave 0 pins
    gpio_dir(36, pad_dir_input);
    gpio_dir(37, pad_dir_input);
    gpio_dir(38, pad_dir_input);
    gpio_dir(39, pad_dir_output);

gpio_dir(66, pad_dir_output);
gpio_pull(66, pad_pull_none);

    // Enable the SPI Slave Device...
    spi_init(
        SPIS0,          // Device
        spi_dir_slave,  // Direction
        spi_mode_0,     // SPI mode
        4);             // Ignored

    // Enable the FIFOs on the SPI Slave...
    spi_option(SPIS0, spi_option_fifo, 1);
spi_option(SPIS0,spi_option_fifo_size,SPIS_FIFOSIZE);
spi_option(SPIS0,spi_option_fifo_receive_trigger,1);

// Global variables initialization
//    spis_dev_buffer = buffer;
    spis_dev_buffer_size = APP_BUFFER_SIZE;
    spis_dev_buffer_ptr = 0;

    ...

//Setup data for transfer
uint8_t SendBuf[8] = {Diameter, Angle, Base >> 8, Base & 0xFF, Nose >> 8, Nose & 0xFF, Amount, Interval};
spis_dev_buffer = SendBuf;

//Load first byte
SPIS0->SPI_DATA = spis_dev_buffer[0];

//Tell the MCU to start transfering
gpio_write(66, 1);

//Wait for the Slave Select to go low
do{
asm_noop();
}
while(gpio_read(37) == true);

    // Load the SPIS0 buffer...
for(i=1;i<APP_BUFFER_SIZE;i++)
{
SPIS0->SPI_DATA = spis_dev_buffer[i];
}

//Make sure "Go button" is reset
gpio_write(66, 0);
#endif

}

From what I can tell, I'm not doing anything different besides leaving out the UART and looping functions from the example.  Is there something I missed?  or a file I need to include?
Logged

LOstrander

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Using MM900EV-LITE as SPI Slave
« Reply #1 on: June 21, 2019, 02:20:36 PM »

I've added the ft900_registers.h file to the project, and now it at least gets through the function and loads the next screen without crashing.

However, this has pointed out a new issue: It doesn't seem to actually be setting the SPI Slave pins as such.  Specifically, the CLK line seems to be convinced it's an output, and idles high at 3.3V.  The SS and MOSI lines appear to be working.  The MISO line is hard to tell because it requires the CLK line to work for it to work.  When my SPI Master is disconnected from the MM900EV-LITE, it functions perfectly (besides the MISO for obvious reasons).

Does anyone have a pinout of the CN2 connector that explicitly shows which pin is which number?  I'm 99% sure I'm right in assuming it's left column odd, right column even, but I want to rule that out.  The next pin down (Pad 66) is my "Go" signal, and it works perfectly.
Logged

FTDI Community

  • Administrator
  • Sr. Member
  • *****
  • Posts: 282
    • View Profile
Re: Using MM900EV-LITE as SPI Slave
« Reply #2 on: June 21, 2019, 04:37:06 PM »

Hello,

We are currently discussing your issues by email. You can post any resolution here to help other users.

Also, Our new Bridgetek Community is now open.
We have created the Bridgetek Community to discuss all Bridgetek products e.g. EVE, MCU.

Please follow this link and create a new user account to get started.

Bridgetek Community

Best Regards,
FTDI Community
Logged

LOstrander

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Using MM900EV-LITE as SPI Slave
« Reply #3 on: June 21, 2019, 05:25:45 PM »

At least part of my issue was solved: It looks like you can't have the programmer attached to CN5 if you have a SPI Slave on CN2.  I assume this has something to do with how the programmer uses the same pad.  I disconnected the programmer, and my CLK and MISO lines reappeared!

I still get a crash when I try to send certain things over SPI (might be the datatype I'm trying to send, since regular old numbers seem to work fine), and if I try to make the variables static it seems to complain, but it looks like the SPI problem is pretty much solved.
Logged

FTDI Community

  • Administrator
  • Sr. Member
  • *****
  • Posts: 282
    • View Profile
Re: Using MM900EV-LITE as SPI Slave
« Reply #4 on: June 25, 2019, 04:30:36 PM »

Hello Logan,

Yes the following signals are all connected to the programmer module via CN7 which are then connected to PortB of the FT4232H on the UMFTPD2A, so I can see why there would be some contention on the SPI lines:

SPIS0_CLK/GPIO36
SPIS0_SS/GPIO37
SPIS0_MOSI/GPIO38
SPIS0_MISO/GPIO39

As I have mentioned in my emails, please check out the SPI master to SPI slave example in AN_360 FT9xx Example Applications which can be used as a reference.

Best Regards,
FTDI Community
Logged