2767 views|0 replies

6547

Posts

0

Resources
The OP
 

TMS320F28335——SPI usage notes [Copy link]

1. SPI hardware interface

  

  GPIO54 ------- SPISIMOA

  GPIO55 ------- SPISOMIA

  GPIO56 ------- SPCLK

  GPIO57 ------- SPSTEA

  Configure IO functions:

  As shown in the figure above, if you need to configure the IO to SPI mode, just write the corresponding bit to 1. The code is as follows

    GpioCtrlRegs.GPBMUX2.bit.GPIO54 = 1; // Configure GPIO54 as SPISIMOA
    GpioCtrlRegs.GPBMUX2.bit.GPIO55 = 1; // Configure GPIO55 as SPISOMIA
    GpioCtrlRegs.GPBMUX2.bit.GPIO56 = 1; // Configure GPIO56 as SPICLKA
    GpioCtrlRegs.GPBMUX2.bit.GPIO57 = 1; // Configure GPIO57 as SPISTEA

2. Set SPI related registers

   SPI register description document: http://www.ti.com/lit/ug/sprueu3a/sprueu3a.pdf

  1. Initialize SPI FIFO related registers

  SPIFFTX: FIFO transmit register

  SPIFFRX: FIFO Receive Register

  SPIFFCT: FIFO Control Register

  The code is as follows:

void spi_fifo_init()                                        
{
    SpiaRegs.SPIFFTX.all=0xE040; //Enable FIFO; Clear the transmit interrupt flag; Disable FIFO transmit interrupt;
                                //The sending interrupt level is defined as 0;
    SpiaRegs.SPIFFRX.all=0x204f; //Clear FF overflow flag; Clear overflow accept interrupt flag; Disable
                                //FF accepts interrupt; the interrupt level is 16;
    SpiaRegs.SPIFFCT.all=0x0; //SPITXBUF to shift register transfer without delay;
}  

  2. Set SPI related registers

  SPICCR: Configuration Control Register

  SPICTL: Run Control Register

  SPIBRR: Baud Rate Register

  SPIPRI: Priority Control Register

  Initialization code:

// Initialize SPI function
void spi_init()
{    
    SpiaRegs.SPICCR.all = 0x004F; // SPI software reset, polarity bit is 1 (falling edge sends data), each shift
                                // 16-bit word length in and out; disable SPI internal loopback (LOOKBACK) function;
    SpiaRegs.SPICTL.all = 0x0006; // Enable host mode, normal phase, enable host transmission, disable reception
                                //Overflow interrupt, disable SPI interrupt;
                                   
    SpiaRegs.SPIBRR = 0x007F; //SPI baud rate = 25M/128 = 195.3KHZ;                            
    SpiaRegs.SPICCR.all = 0x00CF; //Stop SPI software reset and prepare to receive or send; disable loopback mode;
    SpiaRegs.SPIPRI.bit.FREE = 1; // Free running     
}

3. Send data using SPI

  Sending data is relatively simple. You only need to write data to SPITXBUF.

  

//Send SPI data
void spi_xmit(Uint16 a)
{
    SpiaRegs.SPITXBUF=a;
}    
This post is from DSP and ARM Processors
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list