标题: MC68HC908EY16 的ESCI 和SPI 可以同时通信吗? [打印本页]
作者: feifeiyue 时间: 2006-8-31 16:07 标题: MC68HC908EY16 的ESCI 和SPI 可以同时通信吗?
我现在用MC68HC908EY16 来控制MC33689, 这两者之间要实现LIN数据的发送和接受。请问MC33689的LIN 通信和里面的SPI寄存器有什么关系?因为我无论怎么配置这个寄存器在MC33689的LIN输出口上都没有数据。我是通过MC68HC908EY16的SPI发送数据来初始化MC33689的。
作者: strongchen 时间: 2006-8-31 16:20
MC68HC908EY16 的ESCI 和SPI 可以同时通信。
作者: feifeiyue 时间: 2006-8-31 16:26
MC33689的LIN 通信和 SPI 有什么关系呢?为什么我的程序无论怎么设置MC33689的寄存器都不可以在MC33689的LIN管脚得到数据阿?
作者: feifeiyue 时间: 2006-8-31 16:29
请问版主帮我看看程序错在哪里?
#include /* for EnableInterrupts macro */
#include /* include peripheral declarations */
#include
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=0x19;
/*Internal data bus clock source used as clock source for SCI*/
/*
* 0b00001001
* ||||||||__ Disables SS pullup resistor
* |||||||___ Oscillator disabled during stop mode
* ||||||____ disbles 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
*/
DDRB_DDRB6=1; // OUTPUT
PTB_PTB6=0; // CS=0
do {
ICGCR = 0x13;
} while (ICGCR != 0x13); /* Enable the external oscillator */
return;
}
void Master_SPI_Init(void)
{
SPCR=0x38;
/*
* 0b00111000
* ||||||||__ SPI Transmit Interrupt Disabled
* |||||||___ SPI Disabled
* ||||||____ SPI Wired-OR Mode Disabled
* |||||_____ Clock Phase Bit to 0
* ||||______ Clock Polarity is goup
* |||_______ SPI Master Enabled
* ||________ DMA Select Bit (no effect on this version of SPI)
* |_________ SPI Receiver Interrupt disabled
*/
SPSCR=0x03;
/*
* 0b000000101
* ||||||||__ baud rate (BD) divisor is 64
* |||||||___ baud rate (BD) divisor is 64
* ||||||____ not allow the MODF flag to be set
* |||||_____ Transmit data register not empty
* ||||______ SS pin at appropriate logic level
* |||_______ No overflow
* ||________ MODF and OVRF cannot generate CPU interrupt requests
* |_________ Receive data register not full
*/
SPCR_SPE=1; // Enable SPI
}
void Master_SPI_Send(unsigned char temp)
{
while(!SPSCR_SPTE && ! PTB_PTB6);
PTB_PTB6=0;
SPDR=temp;
}
void MC33689_Init(void)
{
unsigned char status;
status=0x23;
while(!SPSCR_SPTE && ! PTB_PTB6);
PTB_PTB6=0; // CS=0
SPDR=status;
/*¼Ä´æÆ÷Ãû£ºSPI
¼Ä´æÆ÷λ£ºD7 D6 D5 D4 D3 D2 D1 D0
붨Ò壺 L2 L1 LIN_UP HS3 HS2 HS1 MODE2 MODE1
¸³Öµ£º 0 0 1 0 0 0 1 1
˵Ã÷£ºÊ¹ÓøüĴæÆ÷ÔÚÕý³£¹¤×÷״̬Ϲ¤×÷,slew rate is more
than 10kbps normal state */
}
//´®¿Ú³õʼ»¯º¯Êý
//²¨ÌØÂÊ:12500 Æðʼλ£º1 Êý¾Ý³¤¶È£º8 ֹͣλ£º1 ÎÞÆæżУÑé
void SCI_Init()
{
SCC1_ENSCI =1; //SCIʹÄÜ
SCC2_TE=1; //·¢ËÍʹÄÜ
SCC1_LOOPS=1;
SCC1_TXINV=0; // not Inversion
SCC1_M=1; // 9 bits
// SCC2_SCRIE=1; //½ÓÊÕÖжÏʹÄÜ
SCC2_RE=1; //½ÓÊÕʹÄÜ
SCC3=0; // disenable all the interrupt
SCS1_SCTE=0; // clear ESCI Transmitter Empty
//BaudRate = fbus/(64*BPD*BD*(PD+PDFA))
/*SCBR_SCP = 0; //BPD=1 (Option 1 3 4 13)
SCBR_SCR = 0x1; //BD=1 (Option 1,2,4,8,16,32,64,128)
SCPSC_PSSB = 0; //PDFA=8/32 (Option 0/32 1/32...31/32)
SCPSC_PS = 0x4; //PD=3 (Option 2 3 4 5 6 7 8) */
// for Debug fbus = 9.6 MHz
SCBR_SCP = 0x3; //BPD=13 (Option 1 3 4 13)
SCBR_SCR = 0; //BD=4
SCPSC_PSSB = 0; //PDFA=0 (Option 0/32 1/32...31/32)
SCPSC_PS = 0; //PD=5 (Option 2 3 4 5 6 7 8)
}
void SCI_Transmit(unsigned char data)
{
SCDR=data; //°ÑÊý¾Ý·ÅÈë·¢ËÍ»º³åÇø
while(!SCS1_SCTE); //µÈ´ý·¢ËÍ»º³åÇø¿Õ
}
void SCI_Receive(unsigned char data2)
{
data2=SCDR; //¶ÁÈ¡½ÓÊÕ»º³åÇø
while(!SCS1_SCRF); //Çå0
}
void delay(unsigned char tt)
{
unsigned char a,b;
for(a=0;a
for(b=0;b<0x3f;b++);
}
void main(void)
{
// EnableInterrupts; /* enable interrupts */
/* include your code here */
unsigned char data,data2;
data=0x55;
data2=0x23;
EY16_Init();
SCI_Init();
Master_SPI_Init();
MC33689_Init();
//SCI_Receive(data2);
while(1)
{
SCI_Transmit(data);
delay(6);
Master_SPI_Send(data2);
// delay(1);
}
// for(;;) {
// __RESET_WATCHDOG(); /* feeds the dog */
// } /* loop forever */
/* please make sure that you never leave this function */
}
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) |
Powered by Discuz! 7.0.0 |