Board logo

标题: 如何使用MC68HC908EY16的ESCI模块发送数据?看看程序错在哪里? [打印本页]

作者: feifeiyue    时间: 2006-8-21 20:38     标题: 如何使用MC68HC908EY16的ESCI模块发送数据?看看程序错在哪里?

  我现在有自己编写的程序,可是就是不可以进行SCI通信,各位前辈请指教指教,是配置错了还是程序别的问题。


#include <hidef.h> /* for EnableInterrupts macro */
#include <MC68HC908EY16.h> /* include peripheral declarations */


void EY16_Init(void)


{
  CONFIG1=0x39;


 /* 
                         *  0b00111001
                         *    ||||||||__ COP Module Disabled
                         *    |||||||___ STOP is illegal
                         *    ||||||____ STOP Mode Recovery in 4096 Cycles
                         *    |||||_____ LVI Operates in 5 V
                         *    ||||______ LVI Power Disabled
                         *    |||_______ LVI Resets Disabled
                         *    ||________ LVI Disabled during STOP
                         *    |_________ COP large Timeout
                         */


  CONFIG2=0x0D;
 /*Internal data bus clock source used as clock source for SCI*/
/* 
                  *  0b00001101
                  *    ||||||||__ Disables SS pullup resistor
                  *    |||||||___ Oscillator disabled during stop mode
                  *    ||||||____ Enables extra divide by 128 prescaler in timebase module
                  *    |||||_____ Allows PTC4/OSC1 to be an external clock connection
                  *    ||||______ ICG set for fast external crystal operation
                  *    |||_______ PTC3/OSC2 functions as an I/O port pin
                  *    ||________ Internal data bus clock used as clock source for ESCI
                  *    |_________ R
                  */


}



//串口初始化函数
//波特率:4800      起始位:1 数据长度:8 停止位:1  无奇偶校验
void SCI_Init()


{
 SCC1_ENSCI =1;   //SCI使能
 SCC2_TE=1;       //发送使能
 
// SCC2_SCRIE=1;   //接收中断使能
 SCC2_RE=1;         //接收使能


 SCC3=0;           // disenable  all the interrupt
 
  //BaudRate = fbus/(64*BPD*BD*(PD+PDFA))
  SCBR_SCP    = 0;    //BPD=1 (Option 1 3 4 13)
  SCBR_SCR    = 0;    //BD=1  (Option 1,2,4,8,16,32,64,128)


  SCPSC_PSSB  = 0x8;  //PDFA=8/32 (Option 0/32 1/32...31/32)
  SCPSC_PS    = 0x2;  //PD=3      (Option   2 3 4 5 6 7 8)
 
  // for Debug  fbus = 1.2 MHz
  /*SCBR_SCP    = 0;    //BPD=1 (Option 1 3 4 13)
  SCBR_SCR    = 1;    //BD=4
  SCPSC_PSSB  = 0;    //PDFA=0 (Option  0/32 1/32...31/32)
  SCPSC_PS    = 1;    //PD=2 (Option    2 3 4 5 6 7 8) */
}


void SCI_Transmit(unsigned char data)
{
 while(!SCS1_SCTE);   //等待发送缓冲区空
 SCDR=data;       //把数据放入发送缓冲区
}



void SCI_Receive(unsigned char data2)
{
 while(!SCS1_SCRF);  //清0
  data2=SCDR;     //读取接收缓冲区
}



void main(void) {
//  EnableInterrupts; /* enable interrupts */
  /* include your code here */
 
unsigned char data,data2;
data=0x55;
data2=0x55;


EY16_Init();
SCI_Init();
SCI_Receive(data2);
SCI_Transmit(data);


}


 


 


 


 




 


作者: strongchen    时间: 2006-8-22 10:07

你现在的现象是什么?口线上有没有信号出来?
作者: feifeiyue    时间: 2006-8-22 19:20

现在我改变波特率,在示波器上有时可以观察到传输的数据,有时候不可以。如果接收数据怎么写程序?
并且我还想请教您我使用MC33689实现LIN通信,我对MC33689的配置不是很明白
请您指教一些。




欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) Powered by Discuz! 7.0.0