• Join
  • Sign In with my.TI Login
Texas Instruments
  • Products
  • Applications
  • Tools & Software
  • Support & Community
  • Sample & Buy
  • About TI
Sample & Purchase Cart Sample & Purchase Cart
  • Search
  • Advanced
TI E2E™ Community
  • Support Forums
  • Blogs
  • Groups
  • Videos
  • 简体中文
  • More ...
TI Home » TI E2E Community » Support Forums » Microcontrollers » C2000™ Microcontrollers » C2000 32-bit Microcontrollers Forum » McBSP Transmit
Share
C2000™ Microcontrollers
  • Forums
  • Announcements
  • E2E Wiki
Options
  • Subscribe via RSS
C2000 Resources
  • Product Folder
  • C2000 Training Portal
  • C2000 Technical Training Catalog
  • C2000 Datasheets, App Notes, User Guides
  • C2000 Hardware Design Kits
  • controlSUITE for C2000 Software Library


  • InstaSPIN Resources
  • What is InstaSPIN?
  • Videos and Support


  • InstaSPIN-FOC and InstaSPIN-MOTION Resources
  • What is InstaSPIN-FOC?
  • What is InstaSPIN-MOTION?
  • Product Folder: F28069F, F28068F, F28062F, F28068M, F28069M
  • User’s Guide
  • Technical User’s Manual
  • Tools
  • Forums

    McBSP Transmit

    This question is answered
    ALESSANDRO GUERRESCHI
    Posted by ALESSANDRO GUERRESCHI
    on Mar 22 2012 08:17 AM
    Intellectual580 points

    Hi, 

    I am using the McBSP in SPI mode, with my TMSF28335 for communicate with the DAC8568. 

    I have configured the McBSP for use the DSP as a Master and I send a package of 32bit. 

    This is the configuration:

    void InitMcBSPa(void)
    {
    McbspaRegs.SPCR2.all=0x0000; // Reset FS generator, sample rate generator & transmitter
    McbspaRegs.SPCR1.all=0x0000; // Reset Receiver, Right justify word, Digital loopback dis.
    McbspaRegs.PCR.all=0x0F08; // (CLKXM=CLKRM=FSXM=FSRM= 1, FSXP = 1)
    McbspaRegs.SPCR1.bit.DLB = 1;
    McbspaRegs.SPCR1.bit.CLKSTP = 2;
    McbspaRegs.PCR.bit.CLKXP = 1; // IF 0 Transmit data is sampled on the rising edge of CLKX.
    McbspaRegs.PCR.bit.CLKRP = 1; // IF 1 Receive data is sampled on the rising edge of MCLKR.
    McbspaRegs.RCR2.bit.RDATDLY = 1; // FSX setup time 1 in master mode. 0 for slave mode (Receive)
    McbspaRegs.XCR2.bit.XDATDLY = 1; // FSX setup time 1 in master mode. 0 for slave mode (Transmit)

    McbspaRegs.RCR1.bit.RWDLEN1 = 0x5; // 32-bit word
    McbspaRegs.XCR1.bit.XWDLEN1 = 0x5; // 32-bit word

    McbspaRegs.SRGR2.all = 0x2000; // CLKSM=1, FPER = 1 CLKG periods
    McbspaRegs.SRGR1.bit.FWID = 0; // Frame Width = 1 CLKG period
    McbspaRegs.SRGR1.bit.CLKGDV = 99; // CLKG frequency = LSPCLK/(CLKGDV+1) = 30MHz / 100 = 300kHz

    McbspaRegs.SPCR2.bit.GRST = 1; // Enable the sample rate generator
    delay_loop(100); // Wait at least 2 SRG clock cycles
    McbspaRegs.SPCR2.bit.XRST = 1; // Release TX from Reset
    McbspaRegs.SPCR1.bit.RRST = 1; // Release RX from Reset
    McbspaRegs.SPCR2.bit.FRST = 1; // Frame Sync Generator reset
    }
    
    
    void InitMcBSPaGpio(void)
    {
    EALLOW;
    // Configure McBSPa as SPI

    EALLOW;
    GpioCtrlRegs.GPAMUX2.bit.GPIO20 = 2; // GPIO20 = MDXA (SPISIMO)
    GpioCtrlRegs.GPAMUX2.bit.GPIO21 = 2; // GPIO21 = MDRA (SPISOMI)
    GpioCtrlRegs.GPAMUX2.bit.GPIO22 = 2; // GPIO22 = MCLKXA (SPISIMO)
    GpioCtrlRegs.GPAMUX2.bit.GPIO23 = 2; // GPIO23 = MFSXA (SPISTE)


    GpioCtrlRegs.GPAPUD.bit.GPIO20 = 0; // Enable pull-up

    GpioCtrlRegs.GPAPUD.bit.GPIO21 = 0; // Enable pull-up
    GpioCtrlRegs.GPAQSEL2.bit.GPIO21 = 3; // Asynch input GPIO21 (MDRA)

    GpioCtrlRegs.GPAPUD.bit.GPIO22 = 0; // Enable pull-up
    GpioCtrlRegs.GPAQSEL2.bit.GPIO22 = 3; // Asynch input GPIO22 (MCLKXA)

    GpioCtrlRegs.GPAPUD.bit.GPIO23 = 0; // Enable pull-up


    EDIS;
    }
    
    
    For send data:
    
    
    void send_DAC_McBSPa(Uint32 send_data){

    // send 1 packages with McBSPa (in SPI mode)
    while( McbspaRegs.SPCR2.bit.XRDY == 0 ) {} // wait for any previous SPI transactions to clear
    McbspaRegs.DXR1.all = send_data;

    }
    
    
    I have tried to send instead 32 bit package, two 16 bit packages. But the MFSXA goes high between the two packages and the DAC lost the communication.

    This is a screenshot of what I see with the scope, is a fragment of the 32bit package, the last 16 bit are always low. (the CLK has 32 edges, so the DAC 
    can read correctly the package, but the value of the package result wrong being the last 16 bit at 0)

    Could someone help me please? Thank you!
    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    All Replies
    • Kris Parrent
      Posted by Kris Parrent
      on Mar 22 2012 14:13 PM
      Expert5985 points

      Alessandro,

      The last few lines of your post describing your actual problem got cut off.  This tends to happen when copy and pasting code.  Please just shorten those lines so I can read the full description.  Thanks,

      Kris

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • ALESSANDRO GUERRESCHI
      Posted by ALESSANDRO GUERRESCHI
      on Mar 22 2012 14:39 PM
      Intellectual580 points
      Hi! Thanks! So:

      The problem is that I have seen on the scope that at the output pin the package of 32 bit 
      that I send using the istruction:
      while( McbspaRegs.SPCR2.bit.XRDY == 0 ) {} // wait for any previous SPI transactions to clear
      McbspaRegs.DXR1.all = send_data;

      has the first 16 bit correct, but the other 16 bits are all 0!
      I can't understand why! The variable send_data is Uint32 and should be works!
      
      
      Thank you for your help!
      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Kris Parrent
      Posted by Kris Parrent
      on Mar 22 2012 14:48 PM
      Verified Answer
      Verified by ALESSANDRO GUERRESCHI
      Expert5985 points

      Alessandro,

      Ah I believe this is a simple fix.  When you are using 32 bit mode, you need to use both the DXR1 and DXR2 registers.  Each register is 16 bits, but they will send continuously.  Note, the order in which you read and write both the DXR and DRR registers is important.  I believe if you change your transmit to something similar to:

      void mcbsp_xmit(int a, int b)
      {
      McbspaRegs.DXR2.all = b;
      McbspaRegs.DXR1.all = a;
      }
      Then this should work.  Basically, DXR2 wasn't being written and had a value of '0'
       so you were sending all '0's for those 16 bits.
      Kris
      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • ALESSANDRO GUERRESCHI
      Posted by ALESSANDRO GUERRESCHI
      on Mar 22 2012 15:04 PM
      Intellectual580 points

      Ah, thanks!

      Now here it is evening, tomorrow I will come back to the office and I will proof immideately this change!

      Ah, so with this configuration:

       McbspaRegs.RCR1.bit.RWDLEN1 = 0x5; // 32-bit word
      McbspaRegs.XCR1.bit.XWDLEN1 = 0x5; // 32-bit word

      It send the data that has been written in DXR1 and in DXR2, and if I have to send only 16 bit
       (changing these register)
      it send the data that has been written only in DXR1. 
      Thanks, I will update you tomorrow!
      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • ALESSANDRO GUERRESCHI
      Posted by ALESSANDRO GUERRESCHI
      on Mar 23 2012 10:30 AM
      Intellectual580 points

      Yes, it works! Thank you Kris!

      For people who have to use the DAC8568 with McBSP as SPI, the right configuration is:

      McbspaRegs.SPCR1.bit.CLKSTP = 2;
      McbspaRegs.PCR.bit.CLKXP = 0;
      McbspaRegs.PCR.bit.CLKRP = 0;
      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Kris Parrent
      Posted by Kris Parrent
      on Mar 23 2012 12:57 PM
      Expert5985 points

      Great, glad I could help.  Thank you for following up with the solution.

      Kris

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    TI E2E™ Community
    • Support Forums
    • Blogs
    • Videos
    • Groups
    • Site Support & Feedback
    • Settings
    TI E2E™ Community Groups
    • TI University Program
    • Make the Switch
    • Microcontroller Projects
    • Motor Drive & Control
    Other Communities
    • Deyisupport
    • Designsomething.org
    • beagleboard.org
    • TI on Element 14
    • TI on TechXchangeSM
    Other Technical & Support Resources
    • WEBENCH® Design Center
    • Product Information Centers
    • Technical Documents
    • TI Design Network
    • TI Technical Articles
    • TI Training

    All content and materials on this site are provided "as is". TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with regard to these materials, including but not limited to all implied warranties and conditions of merchantability, fitness for a particular purpose, title and non-infringement of any third party intellectual property right. TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with respect to these materials. No license, either express or implied, by estoppel or otherwise, is granted by TI. Use of the information on this site may require a license from a third party, or a license from TI.

    Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Terms of Use of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms of Use of this site. TI, its suppliers and providers of content reserve the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.

    Follow Us Texas Instruments on Facebook Texas Instruments on Twitter Texas Instruments on LinkedIn Texas Instruments on Google+
    TI Worldwide | Contact Us | my.TI Login | Site Map | Corporate Citizenship | mobile m.ti.com (Mobile Version)

    TI is a global semiconductor design and manufacturing company. Innovate with 100,000+ analog ICs and
    embedded processors, along with software, tools and the industry’s largest sales/support staff.

    © Copyright 1995-2013 Texas Instruments Incorporated. All rights reserved.
    Trademarks | Privacy Policy | Terms of Use