首页 | 新闻 | 新品 | 文库 | 方案 | 视频 | 下载 | 商城 | 开发板 | 数据中心 | 座谈新版 | 培训 | 工具 | 博客 | 论坛 | 百科 | GEC | 活动 | 主题月 | 电子展
返回列表 回复 发帖

SCI串口调试问题

SCI串口调试问题

我用MC9S08AW60在有俩个SCI模块,
在使用单线『loop』模式下,收发数据都正常。
在双线模式,俩个模块接到一起,
调试可以进入中断,但发现买次往SCI1D SCI2D写数据后,SCI1D SCI2D没有变化。
在codewarrior观察
void SendDataA(byte SerialData)
{
EN485A = 1;
while (!SCI1S1_TDRE);
SCI1D = SerialData;
EN485A = 0;
}
但却可以进入中断
__interrupt void isrVsci2rx(void)
{
unsigned char Temp;
static byte i=0;

Temp = SCI2S1; // Acknowledge Receiver Full Flag
SCI2S1_RDRF =1;
bb = SCI2D; // Read the Data Buffer

i++; // Add a value of one to the data received

}
请问是什么原因,谢谢。

isrVsci2rx读出的数据不确定~~
i believe i can
以前用飞利浦的51ATMEL51进行出口通信都没有出现过这种问题
i believe i can
把整个project打包贴出来看看吧。
海纳百川  有容乃大
void MCU_init(void)
{
/* ### MC9S08AW60_64 "Cpu" init code ... */
/* PE initialization code after reset */
/* Common initialization of the write once registers */
/* SOPT: COPE=0,COPT=1,STOPE=0 */
SOPT = 0x53;
/* SPMSC1: LVDF=0,LVDACK=0,LVDIE=0,LVDRE=1,LVDSE=1,LVDE=1,BGBE=0 */
SPMSC1 = 0x1C;
/* SPMSC2: LVWF=0,LVWACK=0,LVDV=0,LVWV=0,PPDF=0,PPDACK=0,PPDC=0 */
SPMSC2 = 0x00;
/* SMCLK: MPE=0,MCSEL=0 */
SMCLK &= (unsigned char)~0x17;
/* System clock initialization */
/* ICGC1: HGO=0,RANGE=1,REFS=0,CLKS1=0,CLKS0=0,OSCSTEN=1,LOCD=0 */
ICGC1 = 0x44;
/* ICGFLT: FILT11=0,FILT10=0,FILT9=0,FILT8=0,FILT7=1,FILT6=1,FILT5=0,FILT4=0,FILT3=0,FILT2=0,FILT1=0,FILT0=0 */
ICGFLT = 0xC0; /* Initialization of the filter value */
/* ICGC2: LOLRE=0,MFD2=0,MFD1=0,MFD0=0,LOCRE=0,RFD2=0,RFD1=0,RFD0=0 */
ICGC2 = 0x00;
ICGTRM = *(unsigned char*far)0xFFBE; /* Initialize ICGTRM register from a non volatile memory */
/* Common initialization of the CPU registers */
/* PTASE: PTASE7=1,PTASE6=1,PTASE5=1,PTASE4=1,PTASE3=1,PTASE2=1,PTASE1=1,PTASE0=1 */
PTASE = 0xFF;
/* PTBSE: PTBSE7=1,PTBSE6=1,PTBSE5=1,PTBSE4=1,PTBSE3=1,PTBSE2=1,PTBSE1=1,PTBSE0=1 */
PTBSE = 0xFF;
/* PTCSE: PTCSE6=1,PTCSE5=1,PTCSE4=1,PTCSE3=1,PTCSE2=1,PTCSE1=1,PTCSE0=1 */
PTCSE |= (unsigned char)0x7F;
/* PTDSE: PTDSE7=1,PTDSE6=1,PTDSE5=1,PTDSE4=1,PTDSE3=1,PTDSE2=1,PTDSE1=1,PTDSE0=1 */
PTDSE = 0xFF;
/* PTESE: PTESE7=1,PTESE6=1,PTESE5=1,PTESE4=1,PTESE3=1,PTESE2=1,PTESE1=1,PTESE0=1 */
PTESE = 0xFF;
/* PTFSE: PTFSE7=1,PTFSE6=1,PTFSE5=1,PTFSE4=1,PTFSE3=1,PTFSE2=1,PTFSE1=1,PTFSE0=1 */
PTFSE = 0xFF;
/* PTGSE: PTGSE6=1,PTGSE5=1,PTGSE4=1,PTGSE3=1,PTGSE2=1,PTGSE1=1,PTGSE0=1 */
PTGSE |= (unsigned char)0x7F;
/* PTADS: PTADS7=0,PTADS6=0,PTADS5=0,PTADS4=0,PTADS3=0,PTADS2=0,PTADS1=0,PTADS0=0 */
PTADS = 0x00;
/* PTBDS: PTBDS7=0,PTBDS6=0,PTBDS5=0,PTBDS4=0,PTBDS3=0,PTBDS2=0,PTBDS1=0,PTBDS0=0 */
PTBDS = 0x00;
/* PTCDS: PTCDS6=0,PTCDS5=0,PTCDS4=0,PTCDS3=0,PTCDS2=0,PTCDS1=0,PTCDS0=0 */
PTCDS = 0x00;
/* PTDDS: PTDDS7=0,PTDDS6=0,PTDDS5=0,PTDDS4=0,PTDDS3=0,PTDDS2=0,PTDDS1=0,PTDDS0=0 */
PTDDS = 0x00;
/* PTEDS: PTEDS7=0,PTEDS6=0,PTEDS5=0,PTEDS4=0,PTEDS3=0,PTEDS2=0,PTEDS1=0,PTEDS0=0 */
PTEDS = 0x00;
/* PTFDS: PTFDS7=0,PTFDS6=0,PTFDS5=0,PTFDS4=0,PTFDS3=0,PTFDS2=0,PTFDS1=0,PTFDS0=0 */
PTFDS = 0x00;
/* PTGDS: PTGDS6=0,PTGDS5=0,PTGDS4=0,PTGDS3=0,PTGDS2=0,PTGDS1=0,PTGDS0=0 */
PTGDS = 0x00;
/* ### Init_SCI init code */
/* SCI1C2: TIE=0,TCIE=0,RIE=0,ILIE=0,TE=0,RE=0,RWU=0,SBK=0 */
SCI1C2 = 0x00; /* Disable the SCI1 module */
(void)(SCI1S1 == 0); /* Dummy read of the SCI1S1 registr to clear flags */
(void)(SCI1D == 0); /* Dummy read of the SCI1D registr to clear flags */
/* SCI1BD: SBR12=0,SBR11=0,SBR10=0,SBR9=0,SBR8=0,SBR7=0,SBR6=0,SBR5=0,SBR4=1,SBR3=1,SBR2=0,SBR1=1,SBR0=0 */
SCI1BD = 0x1A;
/* SCI1C1: LOOPS=0,SCISWAI=0,RSRC=0,M=0,WAKE=0,ILT=0,PE=0,PT=0 */
SCI1C1 = 0x00;
/* SCI1C2: TIE=0,TCIE=0,RIE=1,ILIE=0,TE=1,RE=1,RWU=0,SBK=0 */
SCI1C2 = 0x2C;
/* SCI1C3: R8=0,T8=0,TXDIR=0,TXINV=0,ORIE=0,NEIE=0,FEIE=0,PEIE=0 */
SCI1C3 = 0x00;
/* SCI1S2: BRK13=0,RAF=0 */
SCI1S2 = 0x00;
/* ### Init_SCI init code */
/* SCI2C2: TIE=0,TCIE=0,RIE=0,ILIE=0,TE=0,RE=0,RWU=0,SBK=0 */
SCI2C2 = 0x00; /* Disable the SCI2 module */
(void)(SCI2S1 == 0); /* Dummy read of the SCI2S1 registr to clear flags */
(void)(SCI2D == 0); /* Dummy read of the SCI2D registr to clear flags */
/* SCI2BD: SBR12=0,SBR11=0,SBR10=0,SBR9=0,SBR8=0,SBR7=0,SBR6=0,SBR5=0,SBR4=1,SBR3=1,SBR2=0,SBR1=1,SBR0=0 */
SCI2BD = 0x1A;
/* SCI2C1: LOOPS=0,SCISWAI=0,RSRC=0,M=0,WAKE=0,ILT=0,PE=0,PT=0 */
SCI2C1 = 0x80;
/* SCI2C2: TIE=0,TCIE=0,RIE=1,ILIE=0,TE=1,RE=1,RWU=0,SBK=0 */
SCI2C2 = 0x2C;
/* SCI2C3: R8=0,T8=0,TXDIR=0,TXINV=0,ORIE=0,NEIE=0,FEIE=0,PEIE=0 */
SCI2C3 = 0x00;
/* SCI2S2: BRK13=0,RAF=0 */
SCI2S2 = 0x00;

/* ### */
asm CLI; /* Enable interrupts */
} /*MCU_init*/

void MCU_init(void); /* Device initialization function declaration */

void main(void) {
unsigned char Temp;

MCU_init(); /* call Device Initialization */

/* include your code here */

//////////

EN485A = 1;
while (!SCI1S1_TDRE);
Temp = SCI1S1;
SCI1S1_TDRE=1;

SCI1D = 0x55;
EN485A = 0;

////

EN485B = 1;
while (!SCI2S1_TDRE);
Temp = SCI2S1;
SCI2S1_TDRE=1;

SCI2D = 0x55;
EN485B = 0;

///////
// task();
for(;;) {
/* __RESET_WATCHDOG(); by default, COP is disabled with device init. When enabling, also reset the watchdog. */
} /* loop forever */
/* please make sure that you never leave main */
}
i believe i can
SCI2C1 = 0x80; 时为单线模式,可以写SCI1D、SCI2D成功;
但当SCI2C1 = 0x00;双线模式时, 写SCI1D、SCI2D不成功,无法写进去,好郁闷~`
i believe i can
这是接收处理
__interrupt void isrVsci1rx(void)
{
unsigned char Temp;
static byte i;

Temp = SCI1S1; // Acknowledge Receiver Full Flag
SCI1S1_RDRF =1;

if(SCI1S1_FE)
{
Temp =SCI1D;
return;
}

i = SCI1D; // Read the Data Buffer

i++; // Add a value of one to the data received


}
__interrupt void isrVsci2rx(void)
{
unsigned char Temp;
static byte i;

Temp = SCI2S1; // Acknowledge Receiver Full Flag
SCI2S1_RDRF =1;

if(SCI2S1_FE)
{
Temp =SCI1D;
return;
}

i = SCI2D; // Read the Data Buffer

i++; // Add a value of one to the data received
}
i believe i can
声明:我用的是485max487e,两片,把把它的A/B交叉接到一起。
485硬件接线:发送接收使能0接收1发送正常;
A/B接线无误;
VCCGND无误;
软件:配置单线模式调试正常,可发可收;
双线模式:发送无法写SI1D,但有错误中断(未使能,确进入错误中断);
可能原因:最有可能出现在软件配置上
我是按以下初始化写的
SCI模块初始化流程——
1、写SCIxBDH:SCIxBDL设置波特率
2、SCIxC1:配置1线/2线,9/8位数据选择,唤醒,奇偶检验。
3、配置SCIxC2:配置中断,使能Rx和Tx;使能Rx接收唤醒(RWU),SBK发送break字节;RWU,Rx wakeup,and SBK在初始化是很少用。
4、SCIxC3:使能接收错误中断源;在1线模式下控制引脚传输方向;
SCI1C1 = 0x00;双线模式
/* SCI1C2: TIE=0,TCIE=0,RIE=1,ILIE=0,TE=1,RE=1,RWU=0,SBK=0 */
SCI1C2 = 0x2C; 发送接收使能,接收中断使能
/* SCI1C3: R8=0,T8=0,TXDIR=0,TXINV=0,ORIE=0,NEIE=0,FEIE=0,PEIE=0 */
SCI1C3 = 0x00; 未用
应当没有问题吧。可还是出现上面情况。

i believe i can
返回列表