目录
1、初始化
2、数据传输
1、初始化
Perform the following procedure for initializing the SPI:
1. Reset the SPI by clearing the RESET bit in the SPI global control register 0 (SPIGCR0) to 0.
2. Take the SPI out of reset by setting SPIGCR0.RESET to 1.
3. Configure the SPI for master mode by configuring the CLKMOD and MASTER bits in the SPI global control register 1 (SPIGCR1).
4. Configure the SPI for 3-pin or 4-pin with chip select mode by configuring the SPI pin control register 0 (SPIPC0).
5. Choose the SPI data format register n (SPIFMTn) to be used by configuring the DFSEL bit in the SPI transmit data register (SPIDAT1).
6. Configure the SPI data rate, character length, shift direction, phase, polarity and other format options using SPIFMTn selected in step 5.
7. In master mode, configure the master delay options using the SPI delay register (SPIDELAY).
8. Select the error interrupt notifications by configuring the SPI interrupt register (SPIINT0) and the SPI interrupt level register (SPILVL).
9. Enable the SPI communication by setting the SPIGCR1.ENABLE to 1.
10. Setup and enable the DMA for SPI data handling and then enable the DMA servicing for the SPI data requests by setting the SPIINT0.DMAREQEN to 1.
11. Handle SPI data transfer requests using DMA and service any SPI error conditions using the interrupt service routine.
SpiRegsHandle = (CSL_SpiRegsOvly)CSL_SPI_REGS;//0x20bf0000
// reset SPI//1、重置为0
SpiRegsHandle->SPIGCR0 = 0x00000000;
//take the SPI out of reset//2、跳出复位,reset to 1
SpiRegsHandle->SPIGCR0 = 0x00000001;
//configure the SPI for master mode//3、模式设置为master 83?
SpiRegsHandle->SPIGCR1 = 0x00000083;
//configure the SPI for 4-pin//4、选择片选模式
SpiRegsHandle->SPIPC0 = 0x00000E01;//cs0\cs1低八位设置片选个数,两个片选应该设置03
//set the SPI date format//5、通过SPIDEF和SPIDAT1来选择SPIFMTn
//6、通过SPIFMT[]的选择来确定SPI data rate, character length, shift direction, phase, polarity and other format options
SpiRegsHandle->SPIFMT[0] = 0x3F000708;//3F个delay,1G/6/21
//choose the SPI data format for SPIFMT0
SpiRegsHandle->SPIDEF = 0x00000001;//低为不传输
SpiRegsHandle->SPIDAT1 =0x04000000;//delay可使能
//configure master delay ( 2 spi module clk)//7、设置master delay
SpiRegsHandle->SPIDELAY = 0x00000000;
//Select the error interrupt notifications //8、
//SpiRegsHandle->SPIINT0 = 0x00010000;
//SpiRegsHandle->SPILVL = 0x00000000;
//enable spi//9、使能SPI setting the SPIGCR1.ENABLE to 1
SpiRegsHandle->SPIGCR1 = CSL_FINST(SpiRegsHandle->SPIGCR1, SPI_SPIGCR1_ENABLE, ENABLE);
//Setup and enable the DMA //10、setting the SPIINT0.DMAREQEN to 1.
SpiRegsHandle->SPIINT0 = 0x00010000;
//11、Handle SPI data transfer requests
2、数据传输
SPI传输数据分为线上直接收发和通过EDMA的数据传输两种。第一种是直接将数据放在线上(SPIDAT1),在寄存器(SPIBUF)中写入命令实现数据的收发;第二种需要配置EDMA,将数据buffer直接作为EDMA的数据源进行传输,其需要配置的参数和中断与EDMA一致。