Ti工程师您好!
现在我遇到一个问题,SPI用片选1连接外设AD,但是现在SPI没有输出信号,clock也没有输出信号。
程序是我在例程里修改的,例程里是用SPI往EEPROM里写数据,把例程用ezdsp开发板仿真,也是没有数据的。
不知道哪里出问题了。我下载了好几个版本的例程都不行。
#include <stdio.h> #include <csl_spi.h> #include <cslr_spi.h> #include <csl_sysctrl.h> #include <csl_general.h> #include <spirom.h> #define CSL_TEST_FAILED(1) #define CSL_TEST_PASSED(0) #define CSL_SPI_BUF_LEN (64) #define SPI_CLK_DIV (10000) #define SPI_FRAME_LENGTH (1) Uint16 spiWriteBuff[CSL_SPI_BUF_LEN]; Uint16 spiReadBuff[CSL_SPI_BUF_LEN]; Uint16 byteBuf[1]; Uint16 cmdBuffer[3] = {0, 0, 0}; long delay_i; extern void spirom_write( Uint32 src, Uint16 dst, Uint32 length ); CSL_SpiHandle hSpi; Int16 spi_sample(void) { Int16 status = CSL_TEST_FAILED; Int16 result; SPI_Config hwConfig; Uint16 looper; /*Uint16 value = 0; Uint16 pageNo = 0x0000; Uint16 pollStatus; Uint16 delay; Uint16 fnCnt;*/ result = SPI_init(); if(CSL_SOK != result) { status = CSL_TEST_FAILED; return (status); } else { printf ("SPI Instance Intialize successfully\n"); } hSpi = SPI_open(SPI_CS_NUM_1, SPI_POLLING_MODE); if(NULL == hSpi) { return (CSL_TEST_FAILED); } else { printf ("SPI Instance Opened successfully\n"); } /** Set the hardware configuration */ hwConfig.spiClkDiv = SPI_CLK_DIV; hwConfig.wLen = SPI_WORD_LENGTH_8; hwConfig.frLen = SPI_FRAME_LENGTH; hwConfig.wcEnable = SPI_WORD_IRQ_ENABLE; hwConfig.fcEnable = SPI_FRAME_IRQ_DISABLE; hwConfig.csNum = SPI_CS_NUM_1; hwConfig.dataDelay = SPI_DATA_DLY_1; hwConfig.csPol = SPI_CSP_ACTIVE_LOW; hwConfig.clkPol = SPI_CLKP_LOW_AT_IDLE; hwConfig.clkPh = SPI_CLK_PH_FALL_EDGE; result = SPI_config(hSpi, &hwConfig); if(CSL_SOK != result) { return (CSL_TEST_FAILED); } else { printf ("SPI Instance Configured successfully\n"); } byteBuf[0] = 0xABCD; for(looper = 0; looper < 64; ) { spiWriteBuff[looper] = 0x0011; spiWriteBuff[(looper + 1)] = 0x00AB; spiReadBuff[looper] = 0x0000; spiReadBuff[(looper + 1)] = 0x00CD; looper += 2; } return (status); } void main(void) { Int16status;pll_sample();//时钟初始化status = spi_sample();while(1) { delay_i = 50000; while(delay_i--);SPI_dataTransaction(hSpi ,spiWriteBuff, CSL_SPI_BUF_LEN, SPI_WRITE); } }
Shine:
请问用的是哪里的例程?一般我们提供的例程都是在开发板上验证过的。
YUDONG WANG2:
回复 Shine:
就是光盘里自带的例程,下边的是例程的全部代码。CSL_SPI_Example_Out / csl_spi_example.c
我用这个程序返回的是: SPI Sample Test Failed!!!
/*============================================================================*Copyright (c) Texas Instruments Inc 2002, 2003, 2004, 2005, 2008**Use of this software is controlled by the terms and conditions found in the*license agreement under which this software has been supplied.*============================================================================*//** @file csl_spi_exampale.c**@brief I2S functional layer sample source file**Path: \(CSLPATH)\example\spi\src*//* ============================================================================* Revision History* ================* 09-Sept-2008 Created* ============================================================================*/#include "csl_spi.h" #include <stdio.h>#define CSL_TEST_FAILED(1) #define CSL_TEST_PASSED(0)#define CSL_SPI_BUF_LEN(64) #define SPI_CLK_DIV(8)#define SPI_FRAME_LENGTH(1)Uint16 spiWriteBuff[CSL_SPI_BUF_LEN]; Uint16 spiReadBuff[CSL_SPI_BUF_LEN]; Uint16 byteBuf[1]; Uint16 cmdBuffer[3] = {0, 0, 0};Int16 spi_sample(void) {Int16status = CSL_TEST_FAILED;Int16result;CSL_SpiHandle hSpi;SPI_ConfighwConfig;Uint16looper;Uint16value = 0;Uint16pageNo = 0x0000;Uint16pollStatus;Uint16delay;Uint16fnCnt;result = SPI_init();if(CSL_SOK != result){status = CSL_TEST_FAILED;return (status);}else{printf ("SPI Instance Intialize successfully\n");}hSpi = SPI_open(SPI_CS_NUM_0, SPI_POLLING_MODE);if(NULL == hSpi){return (CSL_TEST_FAILED);}else{printf ("SPI Instance Opened successfully\n");}/** Set the hardware configuration*/hwConfig.spiClkDiv = SPI_CLK_DIV;hwConfig.wLen= SPI_WORD_LENGTH_8;hwConfig.frLen= SPI_FRAME_LENGTH;hwConfig.wcEnable = SPI_WORD_IRQ_ENABLE;hwConfig.fcEnable = SPI_FRAME_IRQ_DISABLE;hwConfig.csNum= SPI_CS_NUM_0;hwConfig.dataDelay = SPI_DATA_DLY_0;hwConfig.csPol= SPI_CSP_ACTIVE_LOW;hwConfig.clkPol= SPI_CLKP_LOW_AT_IDLE;hwConfig.clkPh= SPI_CLK_PH_FALL_EDGE;result = SPI_config(hSpi, &hwConfig);if(CSL_SOK != result){return (CSL_TEST_FAILED);}else{printf ("SPI Instance Configured successfully\n");}/****************************************************************************//** This configuration for the EPROM*/do { /* Check for bsy status */value=CSL_FEXT(CSL_SPI_REGS->SPISTAT1,SPI_SPISTAT1_BSY);}while(value & 0x01==1);CSL_FINS(CSL_SPI_REGS->SPICMD1,SPI_SPICMD1_FLEN,1);/* set one word *//* Send Read Status Command */CSL_FINS(CSL_SPI_REGS->SPIDR2,SPI_SPIDR2_DATA,0x0500);CSL_FINS(CSL_SPI_REGS->SPIDR1,SPI_SPIDR1_DATA,0x0);/* set start CMD - Read */CSL_FINS(CSL_SPI_REGS->SPICMD2,SPI_SPICMD2_CMD,CSL_SPI_SPICMD2_CMD_READ);do { /* Check for Word Complete status */value=CSL_FEXT(CSL_SPI_REGS->SPISTAT1,SPI_SPISTAT1_CC);}while(value & 0x02==0);do { /* Check for bsy status */value=CSL_FEXT(CSL_SPI_REGS->SPISTAT1,SPI_SPISTAT1_BSY);}while(value & 0x01==1);//Read the Status --- Dummy clock cyclesCSL_FINS(CSL_SPI_REGS->SPIDR2,SPI_SPIDR2_DATA,0x0);CSL_FINS(CSL_SPI_REGS->SPICMD2,SPI_SPICMD2_CMD,0x01);do { /* Check for Word Complete status */value=CSL_FEXT(CSL_SPI_REGS->SPISTAT1,SPI_SPISTAT1_CC);}while(value & 0x02==0);do { /* Check for bsy status */value=CSL_FEXT(CSL_SPI_REGS->SPISTAT1,SPI_SPISTAT1_BSY);}while(value & 0x01==1);// Enable write using WREN commandCSL_FINS(CSL_SPI_REGS->SPICMD1,SPI_SPICMD1_FLEN,0x0);/* Write Enable command */CSL_FINS(CSL_SPI_REGS->SPIDR2,SPI_SPIDR2_DATA,0x0600);CSL_FINS(CSL_SPI_REGS->SPIDR1,SPI_SPIDR1_DATA,0x0000);/* set start CMD - Write */CSL_FINS(CSL_SPI_REGS->SPICMD2,SPI_SPICMD2_CMD,0x02);do { /* Check for Word Complete status */value=CSL_FEXT(CSL_SPI_REGS->SPISTAT1,SPI_SPISTAT1_CC);}while(value & 0x02==0);do { /* Check for bsy status */value=CSL_FEXT(CSL_SPI_REGS->SPISTAT1,SPI_SPISTAT1_BSY);}while(value & 0x01==1);cmdBuffer[0] = 0x02;/* eeprom address - MSB */cmdBuffer[1] = (pageNo >> 0x08);/* eeprom address - LSB */cmdBuffer[2] = (pageNo & 0xFF);CSL_FINS(CSL_SPI_REGS->SPICMD1,SPI_SPICMD1_FLEN, CSL_SPI_BUF_LEN+3-1);/* Set Command for write */for(fnCnt = 0; fnCnt < 3; fnCnt++){CSL_SPI_REGS->SPIDR2 = (Uint16)(cmdBuffer[fnCnt] <<0x08);CSL_SPI_REGS->SPIDR1 = 0x0000;CSL_SPI_REGS->SPICMD2 = (((CSL_SPI_REGS->SPICMD2) & (Uint16)(~CSL_SPI_SPICMD2_CMD_MASK))| ((Uint16)(2 << CSL_SPI_SPICMD2_CMD_SHIFT)));do{pollStatus = (CSL_SPI_REGS->SPISTAT1);}while(((pollStatus & 0x02) != 0x01) && ((pollStatus & 0x01) == 0x01));}/****************************************************************************/byteBuf[0] = 0xABCD;for(looper = 0; looper < 64; ){spiWriteBuff[looper] = 0x0011;spiWriteBuff[(looper + 1)] = 0x00AB;spiReadBuff[looper] = 0x0000;spiReadBuff[(looper + 1)] = 0x00CD;looper += 2;}result = SPI_dataTransaction(hSpi ,spiWriteBuff, CSL_SPI_BUF_LEN, SPI_WRITE);if(CSL_SOK != result){return (CSL_TEST_FAILED);}else{printf ("SPI Instance Write successfully\n");}/******************************************************************************/for (delay = 0; delay < 35000; delay++) {/* no operation */}/* Configure the SPI for read from EEprom *//* read command */cmdBuffer[0] = 0x03;/* eeprom address - MSB */cmdBuffer[1] = (pageNo >> 0x08);/* eeprom address - LSB */cmdBuffer[2] = (pageNo & 0xFF);CSL_FINS(CSL_SPI_REGS->SPICMD1,SPI_SPICMD1_FLEN, CSL_SPI_BUF_LEN+3-1);/* Set Command for write */for(fnCnt = 0; fnCnt < 3; fnCnt++){CSL_SPI_REGS->SPIDR2 = (Uint16)(cmdBuffer[fnCnt] <<0x08);CSL_SPI_REGS->SPIDR1 = 0x0000;CSL_SPI_REGS->SPICMD2 = (((CSL_SPI_REGS->SPICMD2) & (Uint16)(~CSL_SPI_SPICMD2_CMD_MASK))| ((Uint16)(2 << CSL_SPI_SPICMD2_CMD_SHIFT)));do{pollStatus = (CSL_SPI_REGS->SPISTAT1);}while(((pollStatus & 0x02) != 0x01) && ((pollStatus & 0x01) == 0x01));}/******************************************************************************/result = SPI_dataTransaction(hSpi ,spiReadBuff, CSL_SPI_BUF_LEN, SPI_READ);if(CSL_SOK != result){return (CSL_TEST_FAILED);}else{printf ("SPI Instance Read successfully\n");}result = SPI_deInit();if(CSL_SOK != result){return (CSL_TEST_FAILED);}else{printf ("SPI Instance deIntialize successfully\n");}result = SPI_close(hSpi);if(CSL_SOK != result){return (CSL_TEST_FAILED);}else{printf ("SPI Instance Close successfully\n");}for(looper=0; looper < 64; looper++){if(spiReadBuff[looper] != spiWriteBuff[looper]){status = CSL_TEST_FAILED;break;}else{status = CSL_TEST_PASSED;}}if(status == CSL_TEST_PASSED){printf ("SPI Writen & Read buffer matching\n");}return (status); }void main(void) {Int16status;status = spi_sample();if(status != CSL_TEST_PASSED){printf("SPI Sample Test Failed!!\n");}else{printf("SPI Sample Test Passed!!\n");} }
Shine:
回复 YUDONG WANG2:
跑到是下面到例程么?
Test Code
http://support.spectrumdigital.com/boards/usbstk5505/revb/
YUDONG WANG2:
回复 Shine:
我之前用SPI的方式将程序拷到eeprom里了,用示波器看是可以看到clock有数据的,但是用例程只是把SPI简单的输出就不行了
Tony Tang:
回复 YUDONG WANG2:
是不是EBSR的PPMODE设置不对啊。还有PCGCR1里对SPI的时钟使能。