TI中文支持网
TI专业的中文技术问题搜集分享网站

C6748中的SPI FLASH

各位开发者:

    大家好。我最近在学习C6748下SPI接口的操作,运行TI公司提供的在D:\Program Files\Texas Instruments\pdk_C6748_2_0_0_0\biospsp_03_00_01_00\drivers\examples\evm6748\spi下的例程,在程序中发现有关于SPI FLASH的定义:

/* flash address where the data will be written and read */
#define SPI_FLASH_ADDR_MSB1 0x0A
#define SPI_FLASH_ADDR_MSB0 0x00
#define SPI_FLASH_ADDR_LSB 0x00

#define SPI_MAX_CMD_LEN 0x04

/* SPI flash opcode */
/* flash page write */
#define SPI_FLASH_PAGE_WRITE 0x02

/* flash data read */
#define SPI_FLASH_READ 0x03

/* read the status register */
#define SPI_FLASH_READ_STATUS_REG 0x05

/* write enable opcode */
#define SPI_FLASH_WRITE_ENABLE 0x06

/* sectore erase command */
#define SPI_FLASH_SECTOR_ERASE 0xD8

/* SPI HW conig macro's */
#define CS_DEFAULT_SPI 0x000000FFu
#define CHIP_NUMBER 1u
#define SPI_DATA_CHAR_LENGTH 8u

我想了解下这些定义的根据是什么?谢谢。

noaming:

你好,其中/* SPI flash opcode */部分是根据FLASH操作命令Instruction Set来设置的,开发板用的是W25X32,因此可以参考http://www.alldatasheet.com/datasheet-pdf/pdf/207471/WINBOND/W25X32.html  章节11.2.2 Instruction Set来设置。

shen liu:

回复 noaming:

Titan,你好。我在TI公司提供的SPI例程中,发现一个如下定义:

/* chip select for the spi flash */#define SPI_CHIPSELECT_SPIFLASH 0x01

我用的开发板是TMDXLCDK6748,调试TI提供的D:\Program Files\Texas Instruments\pdk_C6748_2_0_0_0\biospsp_03_00_01_00\drivers\examples\evm6748\spi下的例程时,发现在Console结果无法达到它在C6748_BIOSPSP_Userguide.pdf中SPI driver描述的那样,程序执行到:

while (TRUE == Spi_Flash_IsBusy(&dataparam, &eb)) { Task_sleep(1000); }

就一直卡在这里,请教一下这是什么回事?需要进行硬件上的设置吗?

Dean Ma:

回复 noaming:

你好,Titan

       现在正在学习C6748的SPI操作,用的TMDXLCDK6748,使用下面这个路径里的SPI实例:

\pdk_C6748_2_0_0_0\C6748_StarterWare_1_20_03_03\examples\lcdkC6748\spi

想通过spi0与其他设备进行通信,中断都触发了,但是引脚没有输出,不知道问题出在哪里,求指点

#include <string.h>#include "soc_C6748.h"#include "hw_psc_C6748.h"#include "lcdkC6748.h"#include "uart.h"#include "spi.h"#include "psc.h"#include "interrupt.h"#include "uartStdio.h"

/********************************************************************************                      INTERNAL MACRO DEFINITIONS*******************************************************************************//* value to configure SMIO,SOMI,CLK and CS pin as functional pin */#define SIMO_SOMI_CLK_CS        0x00000E20#define CHAR_LENGTH             0x8

/********************************************************************************                      INTERNAL FUNCTION PROTOTYPES*******************************************************************************/static void SPIConfigDataFmtReg(unsigned int dataFormat);static void SpiTransfer(void);static void SetUpInt(void);static void SetUpSPI(void);static void GetStatusCommand(void);static void ResetCommand(void);void SPIIsr(void);

/********************************************************************************                      INTERNAL VARIABLE DEFINITIONS*******************************************************************************/volatile unsigned int flag = 1;unsigned int tx_len;unsigned int rx_len;unsigned char vrf_data[260];unsigned char tx_data[260];volatile unsigned char rx_data[260];unsigned char *p_tx;volatile unsigned char *p_rx;volatile unsigned char StatusResponseMessage[16];

/********************************************************************************                      INTERNAL FUNCTION DEFINITIONS*******************************************************************************/int main(void){    /* Waking up the SPI1 instance. */    PSCModuleControl(SOC_PSC_0_REGS, HW_PSC_SPI0, PSC_POWERDOMAIN_ALWAYS_ON,                     PSC_MDCTL_NEXT_ENABLE);

    /* Initializing the UART instance for serial communication. */    UARTStdioInit();

    UARTPuts("Welcome to StarterWare SPI application.\r\n\r\n", -1);    UARTPuts("Here the SPI controller on the SoC communicates with", -1);    UARTPuts(" the Fingerprint Sensor present on the LCDK.\r\n\r\n", -1);

    /* Performing the Pin Multiplexing for SPI1. */    SPIPinMuxSetup(0);

    /*    ** Using the Chip Select(CS) 0 pin of SPI1 to communicate with the Fingerprint Sensor.    */    SPI0CSPinMuxSetup(0);

    /* Enable use of SPI1 interrupts. */    SetUpInt();

    /* Configuring and enabling the SPI1 instance. */    SetUpSPI();

 tx_data[0] = 0x80; tx_data[1] = 0x10; tx_data[2] = 0xBA; tx_data[3] = 0x07; tx_data[4] = 0x00; tx_data[5] = 0x00; tx_data[6] = 0x00; tx_data[7] = 0xFF; tx_data[8] = 0xFF; tx_data[9] = 0xFF; tx_data[10] = 0xFF; tx_data[11] = 0xFF; tx_data[12] = 0xFF; tx_data[13] = 0xFF; tx_data[14] = 0xFF; tx_data[15] = 0xFF; tx_data[16] = 0xFF; tx_data[17] = 0xFF; tx_data[18] = 0xFF; tx_data[19] = 0xFF; tx_data[20] = 0xFF; tx_data[21] = 0xFF; tx_data[22] = 0xFF;

 tx_len = 23; rx_len = 23;

    for(;;)    {     SpiTransfer();//     for(; i<100000; i++);    }}

/*** Configures ARM interrupt controller to generate SPI interrupt***/static void SetUpInt(void){ // Setup the ARM or DSP interrupt controller

#ifdef _TMS320C6X // Initialize the DSP interrupt controller IntDSPINTCInit();

 // Register the ISR in the vector table IntRegister(C674X_MASK_INT4, SPIIsr);

 // Map system interrupt to the DSP maskable interrupt IntEventMap(C674X_MASK_INT4, SYS_INT_SPI0_INT);

 // Enable the DSP maskable interrupt IntEnable(C674X_MASK_INT4);

 // Enable DSP interrupts globally IntGlobalEnable();#else    /* Initialize the ARM Interrupt Controller.*/    IntAINTCInit();

    /* Register the ISR in the Interrupt Vector Table.*/    IntRegister(SYS_INT_SPINT1, SPIIsr);

    /* Set the channnel number 2 of AINTC for system interrupt 56.     * Channel 2 is mapped to IRQ interrupt of ARM9.    */    IntChannelSet(SYS_INT_SPINT1, 2);

    /* Enable the System Interrupts for AINTC.*/    IntSystemEnable(SYS_INT_SPINT1);

    /* Enable IRQ in CPSR.*/    IntMasterIRQEnable();

    /* Enable the interrupts in GER of AINTC.*/    IntGlobalEnable();

    /* Enable the interrupts in HIER of AINTC.*/    IntIRQEnable();#endif}

 

//** Configures SPI Controllerstatic void SetUpSPI(void){ unsigned char cs = 0x20;//0x04;****************** unsigned char dcs = 0x20;//0x04;****************** unsigned int val = SIMO_SOMI_CLK_CS; SPIReset(SOC_SPI_0_REGS);

 SPIOutOfReset(SOC_SPI_0_REGS);

 SPIModeConfigure(SOC_SPI_0_REGS, SPI_MASTER_MODE);

 SPIClkConfigure(SOC_SPI_0_REGS, 150000000, 1000000, SPI_DATA_FORMAT0);//SCLK原为1M

 SPIPinControl(SOC_SPI_0_REGS, 0, 0, &val);

 SPIDefaultCSSet(SOC_SPI_0_REGS, dcs);

 /* Configures SPI Data Format Register */ SPIConfigDataFmtReg(SPI_DATA_FORMAT0);

 /* Selects the SPI Data format register to used and Sets CSHOLD * to assert CS pin(line) */ SPIDat1Config(SOC_SPI_0_REGS, (SPI_CSHOLD | SPI_DATA_FORMAT0), cs);

 /* map interrupts to interrupt line INT1 */ SPIIntLevelSet(SOC_SPI_0_REGS, SPI_RECV_INTLVL | SPI_TRANSMIT_INTLVL);

 /* Enable SPI communication */ SPIEnable(SOC_SPI_0_REGS);}//** Configures Data Format register of SPIstatic void SPIConfigDataFmtReg(unsigned int dataFormat){ /* Configures the polarity and phase of SPI clock */ SPIConfigClkFormat(SOC_SPI_0_REGS,(SPI_CLK_POL_HIGH | SPI_CLK_INPHASE),dataFormat);//SPI_CLK_POL_HIGH SPI_CLK_OUTOFPHASE //SPIConfigClkFormat(SOC_SPI_0_REGS,(SPI_CLK_POL_LOW | SPI_CLK_INPHASE),dataFormat);

 /* Configures SPI to transmit MSB bit First during data transfer */ SPIShiftMsbFirst(SOC_SPI_0_REGS, dataFormat);

 /* Sets the Charcter length */ SPICharLengthSet(SOC_SPI_0_REGS, CHAR_LENGTH, dataFormat);}

//** Enables SPI Transmit and Receive interrupt.** Deasserts Chip Select line.static void SpiTransfer(void){ p_tx = &tx_data[0]; p_rx = &rx_data[0];

 SPIIntEnable(SOC_SPI_0_REGS, (SPI_RECV_INT | SPI_TRANSMIT_INT));// while(flag);// flag = 1; /* Deasserts the CS pin(line) */ SPIDat1Config(SOC_SPI_0_REGS, SPI_DATA_FORMAT0, 0x20);}

//** Data transmission and receiption SPIIsrvoid SPIIsr(void){ unsigned int intCode = 0;

 IntEventClear(SYS_INT_SPI0_INT);

 intCode = SPIInterruptVectorGet(SOC_SPI_0_REGS);

 while (intCode) {

  if(intCode == SPI_TX_BUF_EMPTY)  {   tx_len–;   SPITransmitData1(SOC_SPI_0_REGS, *p_tx);   p_tx++;   if (!tx_len)   {    tx_len = 23;    SPIIntDisable(SOC_SPI_0_REGS, SPI_TRANSMIT_INT);    break;   }  }

        if(intCode == SPI_RECV_FULL)        {            rx_len–;            *p_rx = (char)SPIDataReceive(SOC_SPI_0_REGS);            p_rx++;            if (!rx_len)            {                flag = 0;                SPIIntDisable(SOC_SPI_0_REGS, SPI_RECV_INT);            }        }

        intCode = SPIInterruptVectorGet(SOC_SPI_0_REGS); }}

Oscar Ou:

回复 Dean Ma:

Dean Ma,你好。我刚入门C6748,发现sysbios的驱动是基于biospsp开发的,对psp的使用不是很了解。请问biospsp是如何使用的?如何才能把biospsp的例程运行起来?

不胜感激!

赞(0)
未经允许不得转载:TI中文支持网 » C6748中的SPI FLASH
分享到: 更多 (0)