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.

c6748 LCDK- SPI0_CLK enable problem

Hello,

I need to establish one way SPI connection for communication between c6748 lcdk and AD5932.

In my code I use drivers, examples and h-files from C6748_StarterWare_1_20_03_03.

I wanted to varify the frequency of SPI0_CLK on oscilloscope, but there is no signal.

Please could you have a look into my code and write where is the mistake? I can not see where the mistake is.

Thank you.

Petr Duga

#include "hw_psc_C6748.h"
#include "psc.h"
#include "soc_C6748.h"
#include "lcdkC6748.h"
#include "spi.h"
#include "gpio.h"
#include "hw_gpio.h"
/*value needed to write log 1 to SIMO and CLK bits in Pin Control Register 0 (SPIPC0)*/
#define SIMO_CLK   (0x00000600)
unsigned int *val;

/*character length value*/
#define CHAR_LENGTH             (0x10)

/*
 * main.c
 */
int main(void) {
    
 /* Waking up the SPI0 instance. The local PSC number for SPI0 is 4. SPI0 belongs to PSC0 module*/
 PSCModuleControl(SOC_PSC_0_REGS, HW_PSC_SPI0, PSC_POWERDOMAIN_ALWAYS_ON, PSC_MDCTL_NEXT_ENABLE);

 /* The Local PSC number for GPIO is 3. GPIO belongs to PSC1 module.*/
 PSCModuleControl(SOC_PSC_1_REGS, HW_PSC_GPIO, PSC_POWERDOMAIN_ALWAYS_ON, PSC_MDCTL_NEXT_ENABLE);

 /*Pin multiplexing SPI0 and GPIO*/
 SPI0_CLKPinMuxSetup();
 SPI0_SIMOPinMuxSetup();
 GPIOBank8Pin10PinMuxSetup();
 GPIOBank8Pin12PinMuxSetup();

 /*SPI0 set up*/
 SPIReset(SOC_SPI_0_REGS);
 SPIOutOfReset(SOC_SPI_0_REGS);

 /*LCDK board is MASTER*/
 SPIModeConfigure(SOC_SPI_0_REGS, SPI_MASTER_MODE);

 /*Setting of register SPIPC0 to enable SIMO and CLK signals of SPI*/
 *val=SIMO_CLK;
 SPIPinControl(SOC_SPI_0_REGS, 0, 0, val);

 /*Setting of SPI clock frequency*/
 SPIClkConfigure(SOC_SPI_0_REGS, 228000000, 40000000, SPI_DATA_FORMAT0);

 /*Setting of clock format*/
 SPIConfigClkFormat(SOC_SPI_0_REGS,(SPI_CLK_POL_LOW | SPI_CLK_OUTOFPHASE),SPI_DATA_FORMAT0);

 SPIShiftMsbFirst(SOC_SPI_0_REGS, SPI_DATA_FORMAT0);
 SPICharLengthSet(SOC_SPI_0_REGS, CHAR_LENGTH, SPI_DATA_FORMAT0);
 

/*I expected, that after this method will appear CLK signal on SPI0_CLK in J15 - this does not work */
 SPIEnable(SOC_SPI_0_REGS);

 GPIODirModeSet(SOC_GPIO_0_REGS, 139, GPIO_DIR_OUTPUT);

/*spying on GPIO8[10] in J15 with oscilloscope - this works*/
/*
 while(1)
 {
 GPIOPinWrite(SOC_GPIO_0_REGS, 139, GPIO_PIN_HIGH);
//int delay=1000;
 //while(delay)
    // delay--;
 GPIOPinWrite(SOC_GPIO_0_REGS, 139, GPIO_PIN_LOW);
 }

*/





}

  • I believe SPICLK is on only during data tranmission. Try sending data in your loop. The StarterWare SPI driver and examples do not support polling. Just IRQ and EDMA. For polling you want something like this:

    unsigned int SPITransfer(unsigned int baseAdd, unsigned int data)
    {
      unsigned int rx;

      HWREG(baseAdd + SPI_SPIDAT1) =
            (HWREG(baseAdd + SPI_SPIDAT1) & ~ SPI_SPIDAT1_TXDATA) | data;

      do
        rx = HWREG(baseAdd + SPI_SPIBUF);
      while(rx &SPI_SPIBUF_RXEMPTY);

      return(rx &  SPI_SPIBUF_RXDATA);
    }
    ...
    int main(void) {
    volatile unsigned int rx;
    ...
    while(1)
     {
     GPIOPinWrite(SOC_GPIO_0_REGS, 139, GPIO_PIN_HIGH);
     rx = SPITransfer(SOC_SPI_0_REGS, 0x5555)
     GPIOPinWrite(SOC_GPIO_0_REGS, 139, GPIO_PIN_LOW);
     }

    ...

  • Thank you Norman Wong for your quick answer.

    I tried to send some data in this cycle:

    while(1){
     SPITransmitData1(SOC_SPI_0_REGS, 0xAAAA);
     }

    but there is no change on SPI0_CLK pin.

  • Hi Petr Duga,

    Can you also make sure that you are "retuning" the clock for SPI0.

    SPI0 vs SPI1 have a difference in how they are clocked in the device.

    Perhaps this post helps,

    http://e2e.ti.com/support/dsp/omap_applications_processors/f/42/t/67264.aspx

    I think on LCDK SPI0 is mux'd with other functions on the board, so to use it reliably, you might need some board mods and proper pin muxing settings.

    Thanks.

  • Using SPITransmitData1() in a loop like that won't work. That function does not wait for the data to be sent. I would expect SPITransmitData1() will just continally reset the SPI's internal state machine and nothing is transmitted. I suggest trying the SPITransfer() in my earlier post. That code will poll the status bit and wait for  data to be transferred.

  • Norman Wong.

    I have problem to build this part of your code:

    HWREG(baseAdd + SPI_SPIDAT1) =
            ((HWREG(baseAdd + SPI_SPIDAT1) & ~ SPI_SPIDAT1_TXDATA) | data);

    the error is:
    #138 expression must be a modifiable lvalue   

    Can you correct it please?

    Thanks

  • Sorry. I don't have access to the LCDK/StarterWare development machine at this moment to do a test compile. I am at a loss why that did not compile. That line is just SPITransmitData1() extracted out. You could replace that line of code with the SPITransmitData1() call.

    unsigned int SPITransfer(unsigned int baseAdd, unsigned int data)
    {
      unsigned int rx;

      SPITransmitData1(baseAdd, data);
      do
        rx = HWREG(baseAdd + SPI_SPIBUF);
      while(rx &SPI_SPIBUF_RXEMPTY);

      return(rx &  SPI_SPIBUF_RXDATA);
    }

  • I am sorry Norman Wong. I forgot to include "hw_types.h" in my code. That was the reason, why I could not compile your code. Your code is correct. But there is something rotten in setting up of register SPIPC0 through SPIPinControl().

    I need to activate SPI0_SIMO and SPI0_CLK pins thus I need to write a value 0x00000600 (SIMO_CLK in my code) into SPIPC0. I set up a breakpoint on SPIClkConfigure(). Debug the code and watch in register view what happend in SPIPC0. After passing SPIPinControl() the value of SPIPC0 was 0x00010726 instead of 0x00000600.

    Do you have any idea where is the mistake?

  • Hi Rajasekaran K.

    I think I have mux´d SPI0_CLK and _SIMO pins properly.

    I take GPIO MUX routine from example "gpioCardDetect.c" and rewrite it for SPI.

    In "spi.c" example I replace all SPI1 registers with SPI0 registers and set the SPI0 module frequency to 228 MHz, that is the correct value for SPI0. (spruh79a/Table 7-1. System PLLC Output Clocks/pg 136 ) .

    But I did not set up PLL module. I let it in the default configuration.

    Should I configure PLL module too?

    Thanks for your answer.

  • Looking more closely at you code, you haven't allocated space for variable "val" to point to. Your first post has this:

    unsigned int *val;
    *val=SIMO_CLK;
    SPIPinControl(SOC_SPI_0_REGS, 0, 0, val);

    The varible val is uninitialized. Probably 0. You are probably writing SIMO_CLK to address zero. Not sure that location is writeable. The function SPIPinControl() will read whatever the memory bus returns. Probably 0x00010726 . I think you want this:

    unsigned int val;
    val=SIMO_CLK;
    SPIPinControl(SOC_SPI_0_REGS, 0, 0, &val);

    I think what Rajasekaran K means is that on the LCDK, all the SPI0 pins are permanently connected to the LAN8710A chip. They cannot be moved to the J15 connector without soldering on resistors, turning the LAN chip off or unsoldering the resistors to the LAN chip.

  • Hi petr duga,

    Please refer the similar thread in which user is able access the spi0 on lcdk.

    http://e2e.ti.com/support/dsp/omap_applications_processors/f/42/t/291319.aspx

    Thanks.

  • Just remembered other threads about SPI on the LCDK. You might be better off using SPI1 through J16 instead of SPI0. This depend on the version of your LCDK board. If it is a newer one, the AES850 (U26) chip will not be installed and cannot interfere with SPI1 pins. Your code will have to use SPI1_SCSn_3. I haven't checked if R208 is installed on the later version boards. That resistor is required to connect SPI1_SCSn_3 to J16.

    http://e2e.ti.com/support/dsp/omap_applications_processors/f/42/t/234899.aspx
    http://e2e.ti.com/support/dsp/omap_applications_processors/f/42/t/282306.aspx

  • Thank you Norman Wong and Rajasekaran K.

    I have suggested, that  SPI0 is connected with J15. I did not recognize it from the scheme.

    I will try to emulate SPI signals with GPIO pins on J15 or will use SPI1 on J16.

    Regards.

    Petr Duga

  • Please Norman Wong, have a look at the following post.

    http://e2e.ti.com/support/dsp/omap_applications_processors/f/42/t/292235.aspx

    Thank you.

    Petr Duga

  • I'll reply here. There is tendency for people to not reply is somebody else has. Summary of the schematic

    SPI1_SCSn_1/EPWM1A connected to J15:40
    SPI1_SCSn_0/EPWM1B connected to J15:44
    SPI1_SCSn_2 used as ? to AES850 via R205
    SPI1_SCSn_3 used as J16:34 via R208
    SPI1_SCSn_4 used as UART2_TXD to FT232RQ
    SPI1_SCSn_5 used as UART2_RXD to FT232RQ
    SPI1_SCSn_6 used as I2C0_SDA to TXS0102DCUR,TVP5147M1PFP,TLV320AIC3106IRGZ, J16:30, J15:15
    SPI1_SCSn_7 used as I2C0_SCL to TXS0102DCUR,TVP5147M1PFP,TLV320AIC3106IRGZ, J16:29, J15:13
    SPI1_SOMI->AES850 via R204,J16:31
    SPI1_CLK->AES850 via R200, J16:32
    SPI1_SIMO->AES850,J16:36

    My experience is with the A6 version of the LCDK. On that version, the AES850 chip is not populated. If I wanted use SPI1 I would have to add R208 to connect SPI1_SCSn_3 to J16.

    On the A5 version of the LCDK board, the AES850 chip is populated. It will interfere with use of SPI1. Particularily SPI1_SIMO which connects directly to AES850. The other SPI1 lines are connected to the AEC850 via resistors. To use SPI1 on this version, would probably require removal of the AES850 chip. That's my guess. Removing a chip is always risky. You might ruin the board.

    Other threads have suggested SPI0 via J15 can be used without the LAN8710A-EZK chip interfering and without any extra code. Some of the people did add code to shutdown the LAN8710A-EZK to avoid conflict.

  • Do you know the values for R214-19?

    I do not understand the marking "OR, DNI" in scheme.

    Schould they have 0 Ohm?

    Schould they be 100E/1% 1/10W like R172-184?

    Thanks for answer.

    Petr Duga

  • I deal primarily with firmware, so you're nearing the limits of my knowledge. I believe OR,DNI is a typo. It should be 0R,DNI which means 0 Ohms, Do Not Install. Anywhere you see DNI, that means the option is there but the component is not installed for production. So for SPI0, R214-R219 should be 0 Ohm resistors. See R200 for an example of 0 ohm resistor specification.

  • Hi Norman Wong,

    finally I have soldered resistors R214-19.

    I have used 0Ohm resistors RC0402JR-070RL yageo note.

    http://datasheet.octopart.com/RC0402JR-070RL-Yageo-datasheet-10408619.pdf

    I did not removed R172-84.

    I have following problem:

    I measure with oscilloscope signal SPIO_CLK on J15.

    The signal seems to be very attenuated (mean voltage: 376mV, peak to peak:352mV) and distorted.

    The signal frequency of SPIO_CLK is always 25MHz, SPIClkConfigure() has no effect although the PINMUX register for SPI0(PINMUX3), should be set correctly(0x00001001 for SPI0_CLK and SPI0_SIMO). I think, the SPIO_CLK comes from U23´s RX_CLK not from SPI0_CLK.

    The signal attenuation and distortion could be matter of OSC probes.

    Please, can you give me some pieces of advice how to set up the frequency of SPIO_CLK?

    Do you think the reason for those distortion and strong attenuation could be in something else than in probes?

    Thank you for answers.

    Petr Duga

  • The pinmux setting 0x00001001 for SPI0_CLK and SPI0_SIMO looks okay.

    The SPI clock frequency is set with SPIClkConfigure(). The code in your above posts has this

    SPIClkConfigure(SOC_SPI_0_REGS, 228000000, 40000000, SPI_DATA_FORMAT0);

    I think on the LCDK the default input clock is 150Mhz. It should defined as SOC_SPI_0_MODULE_FREQ from soc_C6748.h. With 228000000 and 40000000 the divider would be 5. For the actual 150Mhz module clock, a divider of 5 would give 30Mhz. You are probably right in thinking you are seeing U23´s RX_CLK. Perhaps you should ask Yacob Hassidim what exactly he did in firmware to shutdown U23. See here:

    http://e2e.ti.com/support/dsp/omap_applications_processors/f/42/t/234899.aspx

    Definitely not a good thing to have two clocks trying to drive the same line. Hopefully you don't have to remove R178.

    Using SOC_SPI_0_MODULE_FREQ should result in a line like this:

    SPIClkConfigure(SOC_SPI_0_REGS, SOC_SPI_0_MODULE_FREQ, 40000000, SPI_DATA_FORMAT0);

    I am not hardware guy. I cannot say about the scope probes.

  • Hello,

    I found reduction in a DVD recorder, so now I can work with with SPI1 signals of J16 on my breadboard.

    But some problems appeared during the writing of SPI communications routine. So I have some questions on you.

    1) Is it possible to use only 2-pin SPI?

    I need to configure slave device via SPI, I belive, that communication from slave to master (DSP) is not necessary.

    I thought that I can use just SPI1_CLK and SPI1_SIMO signals, but in "spruh79a" is minimum 3 pin.

    I modified example spi.c in starterware, but there is some kind of slave to master communication, even though I want to transmit data from master to slave. (ResetCommand)

    If the answer from slave device is needed:

    2) Is it possible to simulate data transmission from Master to Slave without Slave device?

    I don´t have the components needed for connection of Slave device yet. I want to test my code so, that I let display SPI1_SIMO signal on oscilloscope to check the data sequence.

    Thanks for your answer.

    Petr Duga

  • My SPI experience is only with my side as master. I've never had to code a slave side driver. With the driver as master, the driver does not know if the slave exists. There is no ack or handshaking. So the slave does not have to exist at all. The driver code would be sending out to nowhere and receiving whatever that is being applied to the SOMI line.

    I believe the StarterWare SPI example is talking to SPI flash in which communication is both ways. If your slave device is one-way, you can have a 2-pin SPI. You don't have to mux all the pads to the SPI controller in that case. Note that SPI tranasctions always send and receive even if you only use one of the directions. Your code would send or receive dummy bytes to keep the controller moving data.