Jump to content
  • 0

Arty a7 35t spi pmod


hdx

Question

Hi everyone,

I am having trouble getting SPI to work on the arty a7 35t dev board with a mc33972 module. I have created a design consisting of an AXI QUAD SPI module and created ports that are connected to the pmod ja port. When I connect the pins of the ja port to the mc33972 module and send a message I don't get any response back. The XSpi_Transfer function pass without any problem but there is nothing coming out on the ja port.

set_property -dict { PACKAGE_PIN G13   IOSTANDARD LVCMOS33 } [get_ports { SPI_CS }];
set_property -dict { PACKAGE_PIN B11   IOSTANDARD LVCMOS33 } [get_ports { SPI_MOSI }]; 
set_property -dict { PACKAGE_PIN A11   IOSTANDARD LVCMOS33 } [get_ports { SPI_MISO }]; 
set_property -dict { PACKAGE_PIN D12   IOSTANDARD LVCMOS33 } [get_ports { SPI_SCLK }]; 

spi.jpg.4fbe82f9fe9b88a6d2f83c215eb9e4cf.jpg

XStatus SpiInit(XSpi *SpiPtr) {
    XStatus Status;
    XSpi_Config *ConfigPtr;

    Xil_AssertNonvoid(SpiPtr != NULL);

    /*ConfigPtr = &SPIConfig;
    if (ConfigPtr == NULL) {
        return XST_DEVICE_NOT_FOUND;
    }*/

    ConfigPtr = XSpi_LookupConfig(XPAR_SPI_1_DEVICE_ID);
    if (ConfigPtr == NULL)
    {
        return XST_DEVICE_NOT_FOUND;
    }

    Status = XSpi_CfgInitialize(SpiPtr, ConfigPtr, ConfigPtr->BaseAddress);
    if (Status != XST_SUCCESS) {
        return XST_FAILURE;
    }

    Status = XSpi_SetOptions(SpiPtr,
            XSP_MASTER_OPTION | XSP_MANUAL_SSELECT_OPTION );
    if (Status != XST_SUCCESS) {
        return XST_FAILURE;
    }

    Status = XSpi_SetSlaveSelect(SpiPtr, 1);
    if (Status != XST_SUCCESS) {
        return XST_FAILURE;
    }

    // Start the SPI driver, enabling the device
    Status = XSpi_Start(SpiPtr);
    if (Status != XST_SUCCESS) {
        return XST_FAILURE;
    }
    return XST_SUCCESS;
}

XStatus SPIWrite(PmodSPI *InstancePtr, u32 WriteCmd, u8 **BufPtr)
{
    XStatus Status;
    // Prepare the buffer with write command data
    u8 Buffer[3] = {0};
    (*BufPtr)[0] = 0x0;
    Buffer[0] = (WriteCmd >> 16) & 0xff;
    Buffer[1] = (WriteCmd >>  8) & 0xff;
    Buffer[2] = (WriteCmd >>  0) & 0xff;

    Status = XSpi_Transfer(&InstancePtr->Spi, Buffer, NULL, 3);
    return Status;
}

int mc33972_init(PmodSPI *InstancePtr)
{
    u8 Status;
    u8 *ReadBufferPtr;

    Status = SPIWrite(InstancePtr, CMD_RST, &ReadBufferPtr );
    xil_printf("CMD_RST = %d\r\n", Status);
    if (Status != XST_SUCCESS)
    {
        xil_printf("CMD_RST failed %d buf = 0x%02x\r\n",Status);
        return XST_FAILURE;
    }

    sleep(1);

    Status = SPIWrite(InstancePtr, CMD_CALIB, &ReadBufferPtr );
    xil_printf("CMD_CALIB= %d\r\n", Status);
    sleep(1);

    Status = SPIWrite(InstancePtr, CMD_STATUS, &ReadBufferPtr );
    xil_printf("CMD_STATUS= %d\r\n", Status);
    sleep(1);

    xil_printf("mc33972 Done! status = %d\r\n", Status);
    return Status;
}

Am I missing something important that should also be specified?

Have also tried some of the spi pmod examples and used the correct ports out but still not seeing any data.

 

EDIT: Jan 23 15:57

I noticed that the code I used in spi_write returned XST_SUCCESS instead of status (Have changed it in the code above now). When I ran the code it returned error code 21 = busy.

So it seems like xspi_transfer is performed once successfully and then nothing afterwards, just error 21 (busy) rest of the time. I also noticed that I didn't have the XSpi_IntrGlobalDisable(); in the init. If  I added that to the init code, then the xspi_transfer() function wont return and will get stuck. Any idea why the function xspi_transfer won't return???

 

EDIT: Jan 24  08:50

Never mind the edit above, was my mistake. Had set the wrong base address and also id, therefore resulting in failing and not working. However, now xspi_transfer is returning with 0 = success but still not seeing anything on the oscilloscope or getting any response... Would appreciate any help I could get in order to get this working

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

Hello @hdx,

First of all I see that MC33972 module uses SPI mode 1 to send and receive the data.

Did you make sure you are using the correct SPI mode?

You should try using:

   u32 options = (XSP_MASTER_OPTION
         | XSP_CLK_ACTIVE_LOW_OPTION | XSP_CLK_PHASE_1_OPTION) | XSP_MANUAL_SSELECT_OPTION;
   Status = XSpi_SetOptions(SpiInstancePtr, options);

Let me know how it works!

Link to comment
Share on other sites

1 hour ago, Ana-Maria Balas said:

Hello @hdx,

First of all I see that MC33972 module uses SPI mode 1 to send and receive the data.

Did you make sure you are using the correct SPI mode?

You should try using:


   u32 options = (XSP_MASTER_OPTION
         | XSP_CLK_ACTIVE_LOW_OPTION | XSP_CLK_PHASE_1_OPTION) | XSP_MANUAL_SSELECT_OPTION;
   Status = XSpi_SetOptions(SpiInstancePtr, options);

Let me know how it works!

HI @Ana-Maria Balas

It was indeed what was causing the data to not be sent accordingly, noticed this after debugging with a logic analyzer.

I have managed to fix this and can now see the correct data when debugging with a Logic analyzer. 

Thanks for the help!

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...