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.

Getting SPI1 going with StarterWare

Hi guys!

I just got SPI0 working on my BeagleBone with StarterWare (took it out via the channels labeled UART2_RXD, UART2_TXD, I2C1_SDA and I2C1_SCL). I used the examples from the EVM, just removed the profile checks. Now, I'm trying to get SPI1 working as well (I going to try to get DMA running on both of them). What confounds me is that pretty much all the defines I've found are easily changeable from SPI0 to SPI1, by just replacing the text, but as far as I've understood it I need to mux the SPI1 interface as well.

So basically, the functions McSPIPinMuxSetup and McSPI0CSPinMuxSetup (can be seen in mcspi.c in the platform project for EVM) have a bunch of defines that exists only for SPI0, for example CONTROL_CONF_SPI0_CS0. Now my question is, what should I replace these with to get it working with SPI1, or is there something else I'm missing?

Cheers!

/Lars

  • Hi Lars

    PinMux and Module clock configuration support for McSPI Instance 1 was not provided because on EVMAM335x McSPI Instance 0 was connected to SPI-Flash.

    To enable pin mux and clock to McSPI Instance 1 these are the changes to be done -

     Replace these lines of code(in the platform file)-

          /* PinMux for SPI1 CLK */

    1)  HWREG(SOC_CONTROL_REGS + CONTROL_CONF_SPI0_SCLK) =  (CONTROL_CONF_SPI0_SCLK_CONF_SPI0_SCLK_PUTYPESEL |
                                                                                                                                            CONTROL_CONF_SPI0_SCLK_CONF_SPI0_SCLK_RXACTIVE);

         with

         HWREG(SOC_CONTROL_REGS + CONTROL_CONF_MII1_COL) = 0x32;

         /* PinMux for SPI1 D0*/

    2) HWREG(SOC_CONTROL_REGS + CONTROL_CONF_SPI0_D0) =  (CONTROL_CONF_SPI0_SCLK_CONF_SPI0_SCLK_PUTYPESEL |
                                                                                                                                      CONTROL_CONF_SPI0_SCLK_CONF_SPI0_SCLK_RXACTIVE);

          with

          HWREG(SOC_CONTROL_REGS + CONTROL_CONF_MII1_CRS) = 0x32;

         /* PinMux for SPI1 D1 */

    3) HWREG(SOC_CONTROL_REGS + CONTROL_CONF_SPI0_D1) =  (CONTROL_CONF_SPI0_SCLK_CONF_SPI0_SCLK_PUTYPESEL |
                                                                                                                                      CONTROL_CONF_SPI0_SCLK_CONF_SPI0_SCLK_RXACTIVE); 

          with

         HWREG(SOC_CONTROL_REGS + CONTROL_CONF_MII1_RXERR) = 0x32;

     

    4) HWREG(SOC_CONTROL_REGS + CONTROL_CONF_SPI0_CS0) = (CONTROL_CONF_SPI0_SCLK_CONF_SPI0_SCLK_PUTYPESEL |
                                                                                                                                        CONTROL_CONF_SPI0_SCLK_CONF_SPI0_SCLK_RXACTIVE);

         with

         HWREG(SOC_CONTROL_REGS + CONTROL_CONF_RMII1_REFCLK) = 0x32;

         0x32 stands for MUXMODE - 2, PullUp/PullDwn Enabled, PullUP Selected, Rx Enabled

     

    5) In McSPI0ModuleClkConfig function replace the below lines of code

        HWREG(SOC_CM_PER_REGS + CM_PER_SPI0_CLKCTRL) &= ~CM_PER_SPI0_CLKCTRL_MODULEMODE;

        HWREG(SOC_CM_PER_REGS + CM_PER_SPI0_CLKCTRL) |= CM_PER_SPI0_CLKCTRL_MODULEMODE_ENABLE;

       while((HWREG(SOC_CM_PER_REGS + CM_PER_SPI0_CLKCTRL) & CM_PER_SPI0_CLKCTRL_MODULEMODE) !=    CM_PER_SPI0_CLKCTRL_MODULEMODE_ENABLE);

    with

    HWREG(SOC_CM_PER_REGS + CM_PER_SPI1_CLKCTRL) &= ~CM_PER_SPI1_CLKCTRL_MODULEMODE;

    HWREG(SOC_CM_PER_REGS + CM_PER_SPI1_CLKCTRL) |= CM_PER_SPI1_CLKCTRL_MODULEMODE_ENABLE;

        while((HWREG(SOC_CM_PER_REGS + CM_PER_SPI1_CLKCTRL) &
          CM_PER_SPI1_CLKCTRL_MODULEMODE) != CM_PER_SPI1_CLKCTRL_MODULEMODE_ENABLE);

    Also in the McSPI application file replace the macro SOC_SPI_0_REGS with SOC_SPI_1_REGS.

     

    Regards

    Jeethan

  • Hi Jeethan,

    Thank you for your reply. Unfortunately it seems that altering the code as you suggested did not result in the interface working. I started looking into what your commands did. Looking at my beaglebone schematics I can see that MCASP0 ACLKX lies on the same pin as SPI1 CLK, so I tried swapping your CONTROL_CONF_MII1_COL with CONTROL_CONF_MCASP0_ACLKX, and the rest of them accordingly. This at least caused the pins to go from low to high when their respective commands were executed according to my logic analyzer.


    However, it still seems that the actual transmission will not go through, the pins stay high after their muxing... I'm attaching my files. If you have any possibility to shine some more light on the problem that would be greatly appreciated! Do note that I have not changed function names accordingly, they still claim it's SPI0 even though I modified their contents to SPI1.

    0081.BONE_SCH.pdf

    7140.SPI.zip

    Kind regards

    Lars

  • Ok, I finally solved it :)

    It seemed that the schematics from beaglebone tricked me. I thought the mux setting I was supposed to use was 0x32, but as I zoomed in on the schematics I saw that the SPI stuff had a //, causing the mux settings to need 0x33. And to those who are doing the same thing, pull out the SPI1 via the MCASP0 pins, since those are the ones connected to the correct header on the board.

    Thanks for the help Jeethan :)

    Kind regards

    Lars

  • Lars

    Great news :)

    Anytime for help :)

    Regards

    Jeethan

  •   

          I am really glade that I found your message about getting SPI1 functional. I am designing a Cape card for the BeagleBone and need to control it from SPI1. I had struggled for several hours/days to get it working. Most of the problem was with StarterWare itself. Those imbedded Libraries should not be allowed and since each project has its own, makes it even more confusing.  Anyway, I have my SPI1 now functional thanks to your inputs and messages.

    Best regards

    Larry

  • Good to hear I'm not the only one who had troubles getting it to work, I'm glad my posts could be of assistance Larry :)

    Kind regards

    Lars

  •   I did have one other problem, The MOSI & MISO default were backwards. I added the command McSPIDataPinDirectionConfig to reverse them. When i looked at schematic, I saw SP1_D0 and SPI_D1. i assumed that that was a DO & DI, its not.  Its really is D0(zero)  &D1(one).  I then found in the AM335 data sheet that they can be made as an input or output and there is a command to reverse them.

     

    Best Regards

    Larry

  • Hi Jeethan,

     

    I have a question that is related:

    Why are all the pins set up with the RXACTIVE field set as "1 = receiver enabled"?

    The SPI clock pin, chip select pin and MOSI pin are outputs so I'd expect these to have the RXACTIVE field set as "0 = receiver disabled".  I've tried using this set up and it didn't work, I'd just like to understand why.

     

    Thanks,

     

    Rog

  • Hi Roger,

    As per my understanding the internal SPI clock is sourced through the output buffer to the AM335x IO pad and looped back into the device through the input buffer.  This is done so the internal SPI logic operates with a clock that has similar timing as the SPI device. Otherwise the AM335x output buffer delay would cause the internal SPI clock to appear several ns early relative to the other SPI signals.

    Regards,

    Jeethan

  • Hi Lars L.

    We are having difficulties as well with SPI

    But we aren't able to get SPI0 to work..

    Could you please send us your working source files?

    It would be alot of help to us!

    Thanks in advice,

    YEVDG

  • Hi Jeethan,

    I've also witnessed some odd effects when clearing the RXACTIVE bit for pins that are outputs.  I now just keep the RXACTIVE bit set for all pins.

    Are there any circumstances when the RXACTIVE bit should be cleared?

    Regards,

    Chris

     

     

  • Hi Lars,

    Your post is of very much help. I need some more help please. I have CS0 for SPI1 on UART0_RTSn. Can you please suggest CSpin mux setup for this.

    Thanks n Regards

    Chandra Kant

  • Hello Lars,

    I have the same problem : Code working on SPI0 but not on SPI1.

    I have done all the changes given in the previous post but still, I don't get any signal out there...

    What do you mean by : "pull out the SPI1 via the MCASP0 pins" ? 

    I'm plugged on the SPI1 pins given by the BeagleBone datasheet and it doesn't work, are MCASP0 pins in a different location ? 

    Thanks by advance for your answer,

    Kind regards, 

    Cedric.

    PS : I can send my code if you want to...

  • Hello, 

    I have my SPI1 working correctly with CS0 and CS1 separately. I need to communicate alternatively with two ADCs so I need to get the two CS working alternatively.

    I can't find a way to Assert/Deassert alternatively the CS so I can read the data on the MISO pin of the BeagleBone continuously. Is there any way to adress the right CS when doing the Assert/Deassert command ?

    Kind regards.