3
« 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.
#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?