"

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Using Digilent PmodMTDS with ARC EM SK v2

Hi,
I've been trying to get the PmodMTDS touch screen to work with ARCEM SK v2 for a bit now and I'm quite at an impasse here. The board software that I'm trying to use can be seen here: https://reference.digilentinc.com/reference/software/mtds/start . In that SDK, the MtdsHal.cpp and MtdsHal.h are th efiles that need to be changed. They have an example working with XSpi (https://github.com/Digilent/vivado-library/blob/master/ip/Pmods/PmodMTDS_v1_0/drivers/PmodMTDS_v1_0/src/MtdsHal.cpp), but I just do not know how to adapt that to embARC SDK itself. I suspect that the initialization mechanism I am getting wrong.

The board is using PMOD5 to connect to the ARC board. What I have right now, the most important bits are:

#define EMSK_MTDS_SPI_ID DW_SPI_0_ID
#define EMSK_MTDS_0_SPI_LINE EMSK_SPI_LINE_1
#define EMSK_MTDS_0_GPIO_ID EMSK_GPIO_PORT_A


#define EMSK_MTDS_0_CS_PIN (18)
#define EMSK_MTDS_0_MOSI_PIN (19)
#define EMSK_MTDS_0_MISO_PIN (20)
#define EMSK_MTDS_0_SCLK_PIN (21)

#define MTDS_GPIO_INT_PIN_OFS (24)
#define MTDS_GPIO_RST_PIN_OFS (25)
#define MTDS_GPIO_STSA_PIN_OFS (26)
#define MTDS_GPIO_STSB_PIN_OFS (27)
#define MTDS_GPIO_RST_PIN_MASK (1<<MTDS_GPIO_RST_PIN_OFS)
#define MTDS_GPIO_INT_PIN_MASK (1<<MTDS_GPIO_INT_PIN_OFS)
#define MTDS_GPIO_STSA_PIN_MASK (1<<MTDS_GPIO_STSA_PIN_OFS)
#define MTDS_GPIO_STSB_PIN_MASK (1<<MTDS_GPIO_STSB_PIN_OFS)

void MtdsHalInit(int pinSel) {
dev_gpio = gpio_get_dev(EMSK_MTDS_0_GPIO_ID);
if(!dev_gpio)
{
MTDS_DEBUG("Cannot get GPIO device\n");
return;
}
uint32_t direction = (GPIO_DIR_OUTPUT << MTDS_GPIO_RST_PIN_OFS);
int32_t ercd = dev_gpio->gpio_open(direction);
if ((ercd != E_OK) && (ercd != E_OPNED)) {
MTDS_DEBUG("Cannot open GPIO device\n");
return;
}
MTDS_DEBUG("GPIO RST\n");
dev_gpio->gpio_control(GPIO_CMD_SET_BIT_DIR_INPUT, CONV2VOID(MTDS_GPIO_INT_PIN_MASK));
//dev_gpio->gpio_write(HIGH<<MTDS_GPIO_INT_PIN_OFS, 1<<MTDS_GPIO_INT_PIN_OFS);
dev_gpio->gpio_control(GPIO_CMD_SET_BIT_DIR_INPUT, CONV2VOID(MTDS_GPIO_RST_PIN_MASK));
dev_gpio->gpio_control(GPIO_CMD_SET_BIT_DIR_OUTPUT, CONV2VOID(MTDS_GPIO_STSA_PIN_MASK));
dev_gpio->gpio_control(GPIO_CMD_SET_BIT_DIR_OUTPUT, CONV2VOID(MTDS_GPIO_STSB_PIN_MASK));
}

void MtdsHalInitSpi(uint32_t pspiInit, uint32_t frq) {
dev_spi = spi_get_dev(EMSK_MTDS_SPI_ID);
if(!dev_spi)
{
MTDS_DEBUG("Cannot get SPI device\n");
return;
}
int32_t ercd = dev_spi->spi_open(DEV_MASTER_MODE,frq);
if ((ercd != E_OK) && (ercd != E_OPNED)) {
MTDS_DEBUG("Cannot open SPI device\n");
return;
}
//ercd = dev_spi->spi_control(SPI_CMD_DIS_DEV, CONV2VOID(EMSK_MTDS_0_SPI_LINE));
//MTDS_DEBUG("MtdsHalInitSpi %d\n",ercd);
ercd = dev_spi->spi_control(SPI_CMD_MST_SEL_DEV, CONV2VOID(EMSK_MTDS_0_SPI_LINE));
MTDS_DEBUG("MtdsHalInitSpi %d\n",ercd);
ercd = dev_spi->spi_control(SPI_CMD_ENA_DEV, CONV2VOID(EMSK_MTDS_0_SPI_LINE));
MTDS_DEBUG("MtdsHalInitSpi %d\n",ercd);
ercd = dev_spi->spi_control(SPI_CMD_SET_CLK_MODE, CONV2VOID(SPI_CLK_MODE_DEFAULT));
MTDS_DEBUG("MtdsHalInitSpi %d\n",ercd);
ercd = dev_spi->spi_control(SPI_CMD_MST_SET_FREQ, CONV2VOID(frq));
MTDS_DEBUG("MtdsHalInitSpi %d\n",ercd);
ercd = dev_spi->spi_control(SPI_CMD_FLUSH_RX, 0);
MTDS_DEBUG("MtdsHalInitSpi %d\n",ercd);
ercd = dev_spi->spi_control(SPI_CMD_FLUSH_TX, 0);
MTDS_DEBUG("MtdsHalInitSpi %d\n",ercd);
}

void MtdsHalEnableSlave(bool fEn) {
if (fEn) {
dev_spi->spi_control(SPI_CMD_MST_SEL_DEV, CONV2VOID(EMSK_MTDS_0_SPI_LINE));
}
else {
dev_spi->spi_control(SPI_CMD_MST_DSEL_DEV, CONV2VOID(EMSK_MTDS_0_SPI_LINE));
}
}

uint8_t MtdsHalPutSpiByte(uint8_t bSnd) {
uint8_t bRcv;
while(dev_spi->spi_write(&bSnd, 1) == 0);
while(dev_spi->spi_read(&bRcv, 1) == 0);
return bRcv;
}


I have reached for support to Digilent but they were unable to help me, to point what I'm doing wrong. When I compile and run the code, the screen flashes, the led under the screen lights up, but that's all. The MtdsHalPutSpiByte responds to a sync command with "initialization not ready" .

Your help is appreciated.

Comments

  • have you configured your mux on Pmod5 to make it work as SPI? Quoted below:
    Using Pmod5 (J5) As an SPI Master (Four-Pin Interfaces Using CS1_N)
    Set PM5[0] = 1 – Pmod5[4:1] are connected to DW SPI Master signals using CS1_N.
    This allows you to connect an SPI slave to the DW SPI Master. Additional SPI slaves can be connected to the same DW SPI Master at Pmod6.
    the PMOD_MUX_CTRL register might be checked. Also remember it's a master SPI. I looked at the resource you pointed it's communicating with host processor with SPI protocol, should be straight forward.
    HTH.
  • I believe I did. In emsk_init.c I have:

    set_pmod_mux(mux_regs, PM1_UR_UART_0 | PM1_LR_SPI_S \
    | PM2_I2C_HRI \
    | PM3_GPIO_AC \
    | PM4_I2C_GPIO_D \
    | PM5_UR_SPI_M1 | PM5_LR_GPIO_A \
    | PM6_UR_SPI_M0 | PM6_LR_GPIO_A );

    uint32_t uart_value = 0x9c;
    set_uart_map(mux_regs, uart_value);

    Anything else I may be missing?

    Anything wrong you're seeing in my code so far?

    Thank you.
  • Hi,
    Thank you for the help so far, but unfortunately I'm not making any headway with this. You were saying about the adaptation from their XSpi code being straightforward. Any pointers in that direction would be very appreciated.

    Thank you.
Sign In or Register to comment.