中级会员
积分 303
威望 228
贡献 57
兑换币 36
注册时间 2009-3-8
在线时间 9 小时
1 贡献
我的程序如下:
#include <hidef.h> /* common defines and macros */
#include <mc9s12xdp512.h> /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12xdp512"
#define uchar unsigned char
#define uint unsigned int
uchar putchar_SPI0(uchar cx)
{
uchar te;
PTM_PTM3=0;
te=SPI0SR;
while(!(SPI0SR_SPTEF));//检查寄存器是否为空
SPI0DR=cx;
while(!(SPI1SR_SPIF));//确认数据传输完毕
//clear the SPIF flag
PTM_PTM3=1;
}
uchar getchar_SPI0()
{
PTM_PTM3=0;
//uchar te;
//while(!(SPI0SR_SPTEF));
while(!(SPI0SR_SPIF));
//te=SPI0DR;
return(SPI0DR);
PTM_PTM3=1;
}
void MCU_int()
{
CLKSEL=0x00;
PLLCTL_PLLON=1;
SYNR=2;
REFDV=1;
_asm(nop);
_asm(nop);
while(!(CRGFLG_LOCK==1)); //when pll is steady ,then use it;
CLKSEL_PLLSEL =1; //engage PLL to system;
PTJ_PTJ0 = 0;
DDRJ_DDRJ0 = 0;
PPSJ_PPSJ0 = 1; //PTJ上升沿中断
PIEJ_PIEJ0 = 1; //中断使能
PIFJ_PIFJ0 = 0;
DDRK=0xff;
PORTK=0xff;
}
void SpiInit()
{
DDRM|=0x38; //SCK0=1,MOSI=1,SS0=1
MODRR_MODRR4=1; //使用PM口
PTM_PTM3=1;
SPI0CR1=0x52;
SPI0CR2=0x10;
SPI0BR=0x04;
}
void main(void) {
uchar m;
/* put your own code here */
EnableInterrupts;
MCU_int();
SpiInit();
for(;;)
{
putchar_SPI0(0X05);
getchar_SPI0;
m=SPI1DR;
PORTK=0xee;
} /* wait forever */
/* please make sure that you never leave this function */
}
为什么总在while(!(SPI1SR_SPIF));处出现死循环,而且数据无法写入SPI0DR;SPI0DR总为0;急盼各位高手的解答
换了几个SPI口结果都一样。。。
我来回答