This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

ICE v2 AM3359 SPI1 connection problems

Other Parts Discussed in Thread: TMDSICE3359

Dear Community!

We are trying to establish a SPI connection with an ICEv2 board (TMDSICE3359). We are trying to use the SPI1 connectors on J3(pins 12, 14, 16, 18).

I have a problem to establish a transmission with my code(is attached below). I can’t measure a clock signal with an oscilloscope. Could you help to find the fault please. The project development sticks because of the SPI interface.

Thank you in advance!

#include "tiesc_appreload.h"
#include "soc_AM335x.h"
#include "osdrv_oledlcd.h"
#include "osdrv_mcspi.h"

Uint8 uartInstance = 0;
Uint8 boardType = 0;

Void main() {

	uartInstance = 3; // 5 for ICE, 3 for ICEv2
	UartOpen(uartInstance, NULL);

	char t_str[8];
	UARTPutString(uartInstance, "\nSPI Example");

	sprintf(t_str, "%d", UTILsGetArmClockRate());
	UARTPutString(uartInstance, "\n\rARM Clock rate \t: ");
	UARTPutString(uartInstance, t_str);

	//--------------------------------------------HIER Beginn SPI Kommunikation
	char t_str1[8];

	//INITIALISIERUNG / CONFIG
	McSPIClkConfig( SOC_SPI_1_REGS , MCSPI_IN_CLK , MCSPI_OUT_FREQ , MCSPI_CHANNEL_0 , MCSPI_CLK_MODE_0 );
    McSPIReset(SOC_SPI_1_REGS);//mcspi
    McSPICSEnable(SOC_SPI_1_REGS);//mcspi
    McSPIMasterModeEnable(SOC_SPI_1_REGS);//mcspi

    //unsigned int baseAddress = SOC_SPI_1_REGS;
	sprintf(t_str1,"%d",SOC_SPI_1_REGS);//plat_mcspi
	UARTPutString(uartInstance,"\n\rBaseAddress SPI \t: ");
	UARTPutString(uartInstance , t_str1);


    if( McSPIMasterModeConfig(SOC_SPI_1_REGS , MCSPI_MULTI_CH , MCSPI_TX_RX_MODE , MCSPI_DATA_LINE_COMM_MODE_2 , MCSPI_CHANNEL_0) )//mcspi
    	UARTPutString(uartInstance,"\n\rMasterConfig \t: TRUE");
    else
    	UARTPutString(uartInstance,"\n\rMasterConfig \t: FALSE");

    UARTPutString(uartInstance,"\n\r Clock Config Done");

    McSPICSPolarityConfig( SOC_SPI_1_REGS , MCSPI_CS_POL_LOW , MCSPI_CHANNEL_0);
    McSPITxFIFOConfig(SOC_SPI_1_REGS, MCSPI_TX_FIFO_ENABLE, MCSPI_CHANNEL_0);
    McSPIRxFIFOConfig(SOC_SPI_1_REGS, MCSPI_RX_FIFO_ENABLE, MCSPI_CHANNEL_0);

	unsigned int data_rx = 0;

	UARTPutString(uartInstance, "\n\r Read \t: ");
	sprintf(t_str1, "%u , %X", data_rx, data_rx);
	UARTPutString(uartInstance, t_str1);

	while (1) {
		int i = 0;

		//for(i=0;i<0xFFFFFFF;i++);
		McSPIWordLengthSet( SOC_SPI_1_REGS, MCSPI_WORD_LENGTH(29), MCSPI_CHANNEL_1);
		McSPICSAssert( SOC_SPI_1_REGS, MCSPI_CHANNEL_1);	//mcspi
		McSPIChannelEnable( SOC_SPI_1_REGS, MCSPI_CHANNEL_1);
		while (MCSPI_INT_TX_EMPTY(MCSPI_CHANNEL_1) != (McSPIIntStatusGet(SOC_SPI_1_REGS) & MCSPI_INT_TX_EMPTY(MCSPI_CHANNEL_1)));
		McSPITransmitData(SOC_SPI_1_REGS, 0xff00, MCSPI_CHANNEL_1);

		while (MCSPI_INT_RX_FULL(MCSPI_CHANNEL_1) != (SOC_SPI_1_REGS & MCSPI_INT_RX_FULL(MCSPI_CHANNEL_1)));
		//data_rx = McSPIReceiveData(McSPIGetBaseAddressSOC_SPI_1_REGS), MCSPI_CHANNEL_1);
		//data_rx = McSPIReceiveData(0x800e, MCSPI_CHANNEL_1);
		data_rx = McSPIReceiveData(SOC_SPI_1_REGS, MCSPI_CHANNEL_1);

		//AUSGABE BUFFER
		UARTPutString(uartInstance, "\n\rDATA SPI \t: ");
		sprintf(t_str1, "%u , %X \n", data_rx, data_rx);
		UARTPutString(uartInstance, t_str1);
	}
}

  • Hello,

    I don't see any MMU and Pinmux configurations done here. Are those done correctly?

    Regards,
    Vinesh
  • Sorry, I forgot to include the PinMuxConfig line... I use the following:

    MUX_CONFIG mux[] = {
    { 0x0990 , 3 , AM335X_PIN_OUTPUT | AM335X_PIN_INPUT_PULLDOWN }, // spi1_sclk_mux2/CLK mcasp0_aclkx . IMPORTATN: You need to enable both, input and output. Input clock is feed back into the RX logic of SPI.
    { 0x0994 , 3 , AM335X_PIN_OUTPUT }, // spi1_d0_mux2/SIMO mcasp0_fsx
    { 0x0998 , 3 , AM335X_PIN_INPUT_PULLUP }, // spi1_d1_mux2/SOMI mcasp0_axr0
    { 0x099c , 3 , AM335X_PIN_OUTPUT }, // spi1_cs0_mux4: spi1_cs0 mode
    };
  • Taking a quick look at the code, I see the configuration is done for Channel 0, but the read is done for Channel 1. Can you try using the drivers already available in SDK?

    Regards,
    Vinesh
  • That was a good point! i tried the osdrv version. We have a clear clock and chip select now, but no data transmission (fig: below the data on ch1 and clock on ch2). Do you see any sources of possible errors in our code now?

        unsigned char *charbuff;
        unsigned char x = 173;
    
        charbuff = &x;
    
        McSPIInit(1, 128, 1, 0, 0);
    
        while (1) {
            McSPIWrite(1, &charbuff, 8, 0);
        }


    Thank you for your strong support!

  • A few things I'm not sure here -

    • Konstantin Klein said:
      McSPIInit(1, 128, 1, 0, 0);

    The spiClockDiv is given a value of 128 - is this correct? Note that in McSPIInit, the clock is configure like this
    /* Configure the McSPI bus clock depending on clock mode. */
    McSPIClkConfig(baseAdd, MCSPI_IN_CLK, MCSPI_IN_CLK/spiClockDiv , chNum, MCSPI_CLK_MODE_3);

  • Are the other values correct? - spiDir and chMode?

Regards,
Vinesh

  • ClkDiv beteen 32 and 128 is fine. We have a clock rate between 1,5 mhz and 375 khz then. I am also aware of the content of the osdrv_mcspi.c of course. The dir value lead us to MCSPI_DATA_LINE_COMM_MODE_6 and chMode to multi chanel. To aussure us that the code works and to test the effect of the parameters, we have also tried out different values.

    Thank you,

    Konstantin

  • It works all now!

    In my posted code snipped, the initialization of the variable charbuf was wrong. Just put in the the loop have it initialized on every cycle.



    McSPIInit(1, 128, 1, 0, 0);

    while (1) {
    unsigned char *charbuff;
    unsigned char x = 173;

    charbuff = &x;
    McSPIWrite(1, &charbuff, 8, 0);
    }
  • Glad that you got it working and thanks for sharing!

    Regards,

    Vinesh