不知道为何一直检测不到时钟信号,当只有主机运行的时候也检测不到时钟信号,发送端用示波器检测有波形输出,但是时钟信号就没波形输出。请各位大神指点一下
我的主模式下程序:
#include"stm8s105s6.h"
#define uchar unsigned char
#define uint unsigned int
_Bool LED @PD_ODR:0;
_Bool LED2 @PD_ODR:1;
_Bool MOSI @PC_ODR:6;
_Bool MISO @PC_IDR:7;
_Bool SPI_CLK @PC_ODR:5;
_Bool SPI_NSS @PE_IDR:5;
uchar a1,t,b,n,j=0,m=0;
uchar rec_over=0;
uchar UART2_Rx[3]={0,0,0};//接收缓存
uchar SPI_Rx[3]={0,0,0};
void CLK_Init(void);
void GPIO_Init(void);
void UART2_Init(void);
void UART2_SendChar(uint ch);
void delay(uint s);
void SPI(void);
void SPI_SendChar(uint ch);
void CLK_Init(void)
{
CLK_CKDIVR = 0x00; //16M晶振
}
void GPIO_Init(void)
{
PD_DDR=0x03;
PD_CR1=0x03;
PD_CR2=0x00;
PC_DDR=0x20;
PC_CR1=0x20;
PC_CR2=0x00;
PE_DDR=0x00;//NSS设为上拉输入
PE_CR1=0x20;
PE_CR2=0x00;
}
void UART2_Init(void)
{
UART2_CR1=0x00;
UART2_CR2=0x00;
UART2_CR3=0x00;
UART2_BRR2=0x02;
UART2_BRR1=0x68;
UART2_CR2=0x2c;
}
void SPI_SendChar(uint ch)
{
while((SPI_SR & 0x80)==0x00);
SPI_DR=ch;
}
void delay(uint s)
{
uchar i;
for(s;s>0;s--)
for(i=0;i<100;i++);
}
void SPI(void)
{
SPI_CR1=0x14;
SPI_CR2=0x73;
SPI_ICR=0x80;
SPI_SR=0x02;
SPI_CR1=0x54;
// SPI_DR=0x04;
// SPI_DR=a;
// delay(1);
// while((SPI_SR|0x80)==0x80);
}
void main()
{
GPIO_Init();
CLK_Init();
UART2_Init();
LED2=1;
//SPI_CLK=1;
_asm("rim");
while(1)
{
if(m==1)
{
//SPI_CLK=1;
SPI();
LED2=0;
}
}
}
@far@interrupt void UART2_Recv_IRQHandler(void)
{
UART2_Rx[j]=UART2_DR;// UART2_SendChar(UART2_Rx[j]);
j=j+1;
if(j==3)
{
rec_over=1; //接收完一串数据标志
if(UART2_Rx[0]==0x66)
if(UART2_Rx[1]==0x66)
if(UART2_Rx[2]==0x01)
{
m=1;
}
/*if(UART2_Rx[0]==0x66)
if(UART2_Rx[1]==0x66)
if(UART2_Rx[2]==0x02)
{
m=2;
}*/
j=0;
}
return;
}
@far @interrupt void SPIQHandler(void)
{
while((SPI_SR&0x02)==0x02)
SPI_DR=0x01;
// SPI_CLK=1;
while((SPI_SR & 0x80)==0x00);
LED=1;
// SPI_CLK=0;
}
|