为什么28027的spi自测程序一点没反应,而且程序就停留在了while(SPI_getRxFifoStatus(mySpi) == SPI_FifoStatus_Empty){
}这一句,好奇怪还是c2000自带的自测程序啊
#include "DSP28x_Project.h" // Device Headerfile and Examples Include Files
////////////////////////////////////////////////////////////////////////////////
#include "f2802x_common/include/clk.h"
#include "f2802x_common/include/flash.h"
#include "f2802x_common/include/gpio.h"
#include "f2802x_common/include/pie.h"
#include "f2802x_common/include/pll.h"
#include "f2802x_common/include/wdog.h"
#include "f2802x_common/include/spi.h"
//#include "f2802x_common/include/pie_init.h"
////////////////////////////////////////////
void Gpio_setup(void);
void Spi_setup(void);
void Spi_init(void);
void Spi_fifo_init(void);
/////////////////////////
//全局变量
uint16_t count;
uint16_t flag;
////////////////////////
ADC_Handle myAdc;
CLK_Handle myClk;
FLASH_Handle myFlash;
GPIO_Handle myGpio;
PIE_Handle myPie;
SPI_Handle mySpi;
/////////////////////////
void main(void)
{
uint16_t sdata; // send data
uint16_t rdata; // received data
CPU_Handle myCpu;
PLL_Handle myPll;
WDOG_Handle myWDog;
// Initialize all the handles needed for this application
myAdc = ADC_init((void *)ADC_BASE_ADDR, sizeof(ADC_Obj));
myClk = CLK_init((void *)CLK_BASE_ADDR, sizeof(CLK_Obj));
myCpu = CPU_init((void *)NULL, sizeof(CPU_Obj));
myFlash = FLASH_init((void *)FLASH_BASE_ADDR, sizeof(FLASH_Obj));
myGpio = GPIO_init((void *)GPIO_BASE_ADDR, sizeof(GPIO_Obj));
myPie = PIE_init((void *)PIE_BASE_ADDR, sizeof(PIE_Obj));
myPll = PLL_init((void *)PLL_BASE_ADDR, sizeof(PLL_Obj));
mySpi = SPI_init((void *)SPIA_BASE_ADDR, sizeof(SPI_Obj));
myWDog = WDOG_init((void *)WDOG_BASE_ADDR, sizeof(WDOG_Obj));
// Perform basic system initialization
WDOG_disable(myWDog);
CLK_enableAdcClock(myClk);
(*Device_cal)();
//Select the internal oscillator 1 as the clock source
CLK_setOscSrc(myClk, CLK_OscSrc_Internal);
// Setup the PLL for x10 /2 which will yield 50Mhz = 10Mhz * 10 / 2
PLL_setup(myPll, PLL_Multiplier_10, PLL_DivideSelect_ClkIn_by_2);
// Disable the PIE and all interrupts
PIE_disable(myPie);
PIE_disableAllInts(myPie);
CPU_disableGlobalInts(myCpu);
CPU_clearIntFlags(myCpu);
Gpio_setup();
Spi_setup();
PIE_enable(myPie);
Spi_fifo_init();
Spi_init ();
sdata = 0x0000;
/////////////////////////////////////////////
//主循环
while(1)
{
// Transmit data
SPI_write(mySpi, sdata);
// Wait until data is received
while(SPI_getRxFifoStatus(mySpi) == SPI_FifoStatus_Empty){
}
// Check against sent data
rdata = SPI_read(mySpi);
if(rdata != sdata) {GPIO_setLow(myGpio, GPIO_Number_2);GPIO_setHigh(myGpio, GPIO_Number_3);}
else {GPIO_setLow(myGpio, GPIO_Number_3);GPIO_setHigh(myGpio, GPIO_Number_2);}
sdata++;
DELAY_US(1000000);
}
}
/////////////////////////////////////////////
void Gpio_setup(void)
{
GPIO_setPullUp(myGpio, GPIO_Number_2, GPIO_PullUp_Disable);
GPIO_setMode(myGpio, GPIO_Number_2, GPIO_0_Mode_GeneralPurpose);
GPIO_setDirection(myGpio, GPIO_Number_2, GPIO_Direction_Output);
GPIO_setPullUp(myGpio, GPIO_Number_3, GPIO_PullUp_Disable);
GPIO_setMode(myGpio, GPIO_Number_3, GPIO_0_Mode_GeneralPurpose);
GPIO_setDirection(myGpio, GPIO_Number_3, GPIO_Direction_Output);
}
//////////////////////////////////////////////////////////////
void Spi_setup(void)
{
//初始化外设接口上拉电阻使能
GPIO_setPullUp(myGpio, GPIO_Number_16, GPIO_PullUp_Enable);
GPIO_setPullUp(myGpio, GPIO_Number_17, GPIO_PullUp_Enable);
GPIO_setPullUp(myGpio, GPIO_Number_18, GPIO_PullUp_Enable);
GPIO_setPullUp(myGpio, GPIO_Number_19, GPIO_PullUp_Enable);
//异步输入,不校验
GPIO_setQualification(myGpio, GPIO_Number_16, GPIO_Qual_ASync);
GPIO_setQualification(myGpio, GPIO_Number_17, GPIO_Qual_ASync);
GPIO_setQualification(myGpio, GPIO_Number_18, GPIO_Qual_ASync);
GPIO_setQualification(myGpio, GPIO_Number_19, GPIO_Qual_ASync);
//设置为SPI总线功能的模式
GPIO_setMode(myGpio, GPIO_Number_16, GPIO_16_Mode_SPISIMOA);
GPIO_setMode(myGpio, GPIO_Number_17, GPIO_17_Mode_SPISOMIA);
GPIO_setMode(myGpio, GPIO_Number_18, GPIO_18_Mode_SPICLKA);
GPIO_setMode(myGpio, GPIO_Number_19, GPIO_19_Mode_SPISTEA_NOT);
}
//////////////////
void Spi_init(void)
{
/*//开启spi时钟
CLK_enableSpiaClock(myClk);
//SPICCR-SPICHAR3-0复位spi外设,上升沿输入数据,设置8位长度
SPI_setCharLength(mySpi, SPI_CharLength_8_Bits);
//SPICTL-master/slave使能主机,正常spi时钟方式
SPI_setMode(mySpi, SPI_Mode_Master);
//SPICTL-talk发送时能,关闭spi中断
SPI_enableTx(mySpi);
//SPIBRR使能波特率500K
SPI_setBaudRate(mySpi, SPI_BaudRate_500_KBaud);
//用于内部自测SPICCR-spilbk
SPI_enableLoopBack(mySpi);
//从复位中恢复SPICCR-spi sw reset
SPI_enable(mySpi);//为什么这个函数没有原型
//自由运行忽视中断挂起
SPI_setPriority(mySpi, SPI_Priority_FreeRun);//SPIPRI-spi susp soft/free*/
CLK_enableSpiaClock(myClk);
// Reset on, rising edge, 16-bit char bits
SPI_setCharLength(mySpi, SPI_CharLength_16_Bits);
// Enable master mode, normal phase,
// enable talk, and SPI int disabled.
SPI_setMode(mySpi, SPI_Mode_Master);
SPI_enableTx(mySpi);
SPI_setBaudRate(mySpi, SPI_BaudRate_1_MBaud);
// Relinquish SPI from Reset
SPI_enableLoopBack(mySpi);
SPI_enable(mySpi);
// Set so breakpoints don't disturb xmission
SPI_setPriority(mySpi, SPI_Priority_FreeRun);
}
///////////////////////////
void Spi_fifo_init(void)
{
/*//初始化SPI FIFO 寄存器
//SPIRST使能发送和接收通道
SPI_enableChannels(mySpi);
//SPIFFENA使能spi fifo寄存器使能
SPI_enableFifoEnh(mySpi);
//TXFIFO Reset复位先写0再置位
SPI_resetTxFifo(mySpi);
//TXFFINT CLR清除TXFFINT中断标志
SPI_clearTxFifoInt(mySpi);
//默认是TXFFIENA=0不匹配
///////////////////////////////
//RXFIFO Reset写0再写1复位
SPI_resetRxFifo(mySpi);
//RXFFINT CLR清除RXFFINT中断标志
SPI_clearRxFifoInt(mySpi);
//设置RX的深度为4级
SPI_setRxFifoIntLevel(mySpi, SPI_FifoLevel_4_Words);
//RXfifo在接受数据大于4时中断标志置位
//TXfifo在发送数据小于等于0时才置位
//设定fifo写延时
SPI_setTxDelay(mySpi,10);*/
// Initialize SPI FIFO registers
SPI_enableChannels(mySpi);
SPI_enableFifoEnh(mySpi);
SPI_clearTxFifoInt(mySpi);
SPI_clearRxFifoInt(mySpi);
SPI_resetRxFifo(mySpi);
SPI_resetTxFifo(mySpi);
SPI_setRxFifoIntLevel(mySpi, SPI_FifoLevel_4_Words);
}
user113574:
检查一下硬件先