前面说到28027的spi模块进行16位数据的传输的时候可以完全按照要求,但是在8位数据传送的时候却遇到了问题一直不能正确的进行校验,后同房过检查发现一方面是点自己的语法错误 sdata = stata <<8; rdata 能正确的接收到(sdata<<8)数据,此时sdata的数值不再是sdata而是(sdata<<8)导致(rdata&0x00ff)一直不等于sdata,今天很高兴找出这个错误,低级错误.以下是我的程序
#include"DSP28x_Project.h"
void gpiosetup(void);
void spisetup(void);
/////////////////////////
void main(void)
{
uint16_t count;
uint16_t rdata=0;
uint16_t sdata=0x0000;
InitSysCtrl();
DINT;//关中断
IER = 0x0000;
IFR = 0x0000;
//初始化PIE
InitPieCtrl();
//初始化PIE中断向量
InitPieVectTable();
///////////////////
gpiosetup();
spisetup();
while(1)
{
sdata = count;
SpiaRegs.SPITXBUF=(sdata<<8);
while(SpiaRegs.SPIFFRX.bit.RXFFST!=1){}
//while(SpiaRegs.SPISTS.bit.INT_FLAG ==0){}
rdata = SpiaRegs.SPIRXBUF;
rdata &= 0x00ff;
if(rdata!=sdata) GpioDataRegs.GPACLEAR.bit.GPIO3 = 1 ;
else GpioDataRegs.GPASET.bit.GPIO3 = 1 ;
if(count%2) GpioDataRegs.GPACLEAR.bit.GPIO2 = 1 ;
else GpioDataRegs.GPASET.bit.GPIO2 = 1 ;
DELAY_US(500000);
if(++count>250)count=0;
}
}
void gpiosetup(void)
{
EALLOW;//去保护
///功能选择
//GPIO通用引脚
GpioCtrlRegs.GPAMUX1.bit.GPIO2 = 0;
GpioCtrlRegs.GPAMUX1.bit.GPIO3 = 0;
//SPI模式引脚
GpioCtrlRegs.GPAMUX2.bit.GPIO16 = 1;
GpioCtrlRegs.GPAMUX2.bit.GPIO17 = 1;
GpioCtrlRegs.GPAMUX2.bit.GPIO18 = 1;
GpioCtrlRegs.GPAMUX2.bit.GPIO19 = 1;
///////输出
GpioCtrlRegs.GPADIR.bit.GPIO2 = 1;
GpioCtrlRegs.GPADIR.bit.GPIO3 = 1;
//SPI输入
GpioCtrlRegs.GPADIR.bit.GPIO16 = 0;
GpioCtrlRegs.GPADIR.bit.GPIO17 = 0;
GpioCtrlRegs.GPADIR.bit.GPIO18 = 0;
GpioCtrlRegs.GPADIR.bit.GPIO19 = 0;
//输入校验周期QUALPRD2=0默认为0
//输入校验次数为异步输入
GpioCtrlRegs.GPAQSEL2.bit.GPIO16=3;
GpioCtrlRegs.GPAQSEL2.bit.GPIO17=3;
GpioCtrlRegs.GPAQSEL2.bit.GPIO18=3;
GpioCtrlRegs.GPAQSEL2.bit.GPIO19=3;
//上拉电阻使能
GpioCtrlRegs.GPAPUD.bit.GPIO2 =1;
GpioCtrlRegs.GPAPUD.bit.GPIO3 =1;
GpioCtrlRegs.GPAPUD.bit.GPIO16 =1;
GpioCtrlRegs.GPAPUD.bit.GPIO17 =1;
GpioCtrlRegs.GPAPUD.bit.GPIO18 =1;
GpioCtrlRegs.GPAPUD.bit.GPIO19 =1;
EDIS;//写保护
}
void spisetup(void)
{
//Sip时钟已开启60M/4
//软件复位spi
SpiaRegs.SPICCR.bit.SPISWRESET = 0;
//spi不工作时候spiclk保持高电平
SpiaRegs.SPICCR.bit.CLKPOLARITY = 0;
//允许spi内部自测功能
SpiaRegs.SPICCR.bit.SPILBK = 1;
//8位数据模式
SpiaRegs.SPICCR.bit.SPICHAR = 7;
//相位极性是上降沿所存数据下降沿发送数据
SpiaRegs.SPICTL.bit.CLK_PHASE = 0;
//主机模式
SpiaRegs.SPICTL.bit.MASTER_SLAVE = 1;
//允许发送功能
SpiaRegs.SPICTL.bit.TALK = 1;
//60M/4/(1+99)=150K
SpiaRegs.SPIBRR = 99;
//使能FIFO发送操作
SpiaRegs.SPIFFTX.bit.TXFIFO= 0;
SpiaRegs.SPIFFTX.bit.SPIFFENA = 1;
SpiaRegs.SPIFFTX.bit.TXFFIL = 0;
SpiaRegs.SPIFFTX.bit.TXFFIENA= 0;
SpiaRegs.SPIFFTX.bit.TXFFINTCLR = 1;
//使能FIFO接收操作
SpiaRegs.SPIFFRX.bit.RXFIFORESET= 0;
SpiaRegs.SPIFFRX.bit.RXFFIENA = 0;
SpiaRegs.SPIFFRX.bit.RXFFIL = 4;
SpiaRegs.SPIFFRX.bit.RXFFINTCLR = 1;
//0延时
SpiaRegs.SPIFFCT.all = 0;
//
SpiaRegs.SPIPRI.bit.FREE = 1;
//退出复位进入工作状态
SpiaRegs.SPIFFTX.bit.TXFIFO = 1;
SpiaRegs.SPIFFRX.bit.RXFIFORESET = 1;/**/
SpiaRegs.SPISTS.all = 0x00;
SpiaRegs.SPICCR.bit.SPISWRESET = 1;
//重新开始FIFO的接收或者发送操作
SpiaRegs.SPIFFTX.bit.SPIRST= 1;//
}
http://hi.baidu.com/nizhenyu/item/8b261336cdc02c83f4e4ad38
Young Hu:
很感谢您的分享!对其他人也会有帮助的