在AVR的M48里加入以下语句: /*------------------------------------------ 在*.XCL文件尾部加入以下3句(M48为iom48.xcl) // Output -Ointel-extended,(CODE)=.hex//输出hex文件 -Ointel-extended,(XDATA)=.eep//输出eep文件 -------------------------------------------*/
在STM32里加入以下语句: /*------------------------------------------ 在*.XCL文件尾部加入 // Output -Ointel-extended,(CODE)=.hex//输出hex文件 -------------------------------------------*/
哈哈~~~在其他ARM7俺估计是一样的~~~
|
|
用户1364594 2008-1-8 13:17
老大 有时间给看看这个 用5402的两个串口做spi,bsp0是主,1是从。往DXR10里写完数据后,DRR11怎么也收不到数据。写DXR之后,DXR不往XSR里转移,SPCR2里XRDY位始终为0,请帮忙看看,搞了很长时间了,刚开始学54问题有点弱,见笑了~
头文件:
//filename:boot_5402.h
#include <stdio.h>
#include <string.h>
#include "C5402DEF.h"
void init_5402(void)
{ TI_REG start;
Disable();
SREG->IMR = 0x0000;
SREG->IFR = 0xffff;
SREG->PMST = (0x01 << PMST_IPTR) | (1 << PMST_MP_MC) | (1 << PMST_OVLY) | (1 << PMST_DROM);
SREG->SWWSR = 0x2000;
SREG->SWCR = 0x0000;
do {
SREG->CLKMD = 0;
__nop();
}
while(SREG->CLKMD & (1 << CLKMD_PLLSTATUS));//检测是否div模式
SREG->CLKMD = (4 << CLKMD_PLLMUL) | (30 << CLKMD_PLLCOUNT) | (1 << CLKMD_PLLONOFF) | (1 << CLKMD_PLLNDIV) | (1 << CLKMD_PLLSTATUS);//100M
for (start=0;start<10000;start++);
}
void init_MCBSP(void)
{
McBSP0->SPSA = SPCR1;
McBSP0->SPSD &= (0 << SPCR1_RRST);//禁止串口接收
McBSP1->SPSA = SPCR1;
McBSP1->SPSD &= (0<< SPCR1_RRST);//禁止串口接收
_delay_loop_(1);//延时等待 1us
McBSP0->SPSA = SPCR2;
McBSP0->SPSD &= (0 << SPCR2_XRST);//禁止串口发送
McBSP1->SPSA = SPCR2;
McBSP1->SPSD &=(0 << SPCR2_XRST);//禁止串口发送
_delay_loop_(1);//延时等待
McBSP0->SPSA = SPCR1;
McBSP0->SPSD = (0x03 << SPCR1_CLKSTP);//CLKSTP=11b,CLKXP=0,时钟闲时低电平,上升沿前半个周期发数,上升沿写数
McBSP1->SPSA = SPCR1;
McBSP1->SPSD = (0x03 << SPCR1_CLKSTP);//CLKSTP=11b,CLKXP=0,时钟闲时低电平,上升沿?
_delay_loop_(1);//延时等待
McBSP0->SPSA = SPCR1;
McBSP0->SPSD = (00 << SPCR1_RJUST)|(0x03 << SPCR1_CLKSTP);//接收数据右对齐高位填零
McBSP1->SPSA = SPCR1;
McBSP1->SPSD = (00 << SPCR1_RJUST)|(0x03 << SPCR1_CLKSTP);//接收数据右对齐高位填零
_delay_loop_(1);//延时等待 1us
McBSP0->SPSA = PCR;
McBSP0->SPSD = (1 << PCR_FSXM) //设置主FSX引脚为输出,
| (1 << PCR_FSXP) //FSX引脚平时输出低电平
| (1 << PCR_CLKXM) //设置主CLKX引脚为输出
| (0 << PCR_CLKXP) //CLKXP下降沿发
| (1 << PCR_CLKRP);//CLKRP上升沿写
McBSP1->SPSA = PCR;
McBSP1->SPSD = (0 << PCR_FSXM) //设置从FSX引脚为输入
| (1 << PCR_FSXP) //FSX引脚平时输出低电平
| (1 << PCR_CLKXM) //设置从CLKX引脚为输入
| (0 << PCR_CLKXP) //CLKXP下降沿发
| (1 << PCR_CLKRP);//CLKRP上升沿写
_delay_loop_(1);//延时等待
McBSP0->SPSA = SRGR1;
McBSP0->SPSD = (0x31 << SRGR1_CLKGDV);//速率50分频,串行时钟周期是dsp时钟周期的50倍,既500ns,高低电平宽250ns;
McBSP1->SPSA = SRGR1;
McBSP1->SPSD = (0x01 << SRGR1_CLKGDV);
_delay_loop_(1);//延时等待
McBSP0->SPSA = SRGR2;
McBSP0->SPSD = (1 << SRGR2_CLKSM);//时钟发生器采用dsp时钟
McBSP1->SPSA = SRGR2;
McBSP1->SPSD = (1 << SRGR2_CLKSM);//时钟发生器采用dsp时钟
_delay_loop_(1);//延时等待
McBSP0->SPSA = SRGR2;
McBSP0->SPSD = (0 << SRGR2_FSGM)|(1 << SRGR2_CLKSM);//DXR向XSR复制数据时产生帧同步信号
McBSP1->SPSA = SRGR2;
McBSP1->SPSD = (0 << SRGR2_FSGM)|(1 << SRGR2_CLKSM);
_delay_loop_(1);//延时等待
McBSP0->SPSA = RCR2;
McBSP0->SPSD = (0 << RCR2_RPHASE);//接收单项帧
McBSP1->SPSA = RCR2;
McBSP1->SPSD = (0 << RCR2_RPHASE);//接收单项帧
_delay_loop_(1);//延时等待
McBSP0->SPSA = RCR1;
McBSP0->SPSD = (0000001 << RCR1_RFRLEN1);//接收每帧一个数
McBSP1->SPSA = RCR1;
McBSP1->SPSD = (0000001 << RCR1_RFRLEN1);//接收每帧一个数
_delay_loop_(1);//延时等待
McBSP0->SPSA = RCR1;
McBSP0->SPSD = (10 << RCR1_RWDLEN1)|(1 << RCR1_RFRLEN1);//每个数16bit
McBSP1->SPSA = RCR1;
McBSP1->SPSD = (10 << RCR1_RWDLEN1)|(1 << RCR1_RFRLEN1);//每个数16bit
_delay_loop_(1);//延时等待
McBSP0->SPSA = RCR2;
McBSP0->SPSD = (1 << RCR2_RDATDLY);//主口接收延时1bit数据
McBSP1->SPSA = RCR2;
McBSP1->SPSD = (0 << RCR2_RDATDLY);//从口接收无延时
_delay_loop_(1);//延时等待
McBSP0->SPSA = XCR2;
McBSP0->SPSD = (0 << XCR2_RPHASE);//发送单项帧
McBSP1->SPSA = XCR2;
McBSP1->SPSD = (0 << XCR2_RPHASE);//发送单项帧
_delay_loop_(1);//延时等待
McBSP0->SPSA = XCR1;
McBSP0->SPSD = (1 << XCR1_RFRLEN1);//发送每帧一个数
McBSP1->SPSA = XCR1;
McBSP1->SPSD = (1 << XCR1_RFRLEN1);//发送每帧一个数
_delay_loop_(1);//延时等待
McBSP0->SPSA = XCR1;
McBSP0->SPSD = (10 << XCR1_RWDLEN1)|(1 << XCR1_RFRLEN1);//每个数16bit
McBSP1->SPSA = XCR1;
McBSP1->SPSD = (10 << XCR1_RWDLEN1)|(1 << XCR1_RFRLEN1);//每个数16bit
_delay_loop_(1);//延时等待
McBSP0->SPSA = XCR2;
McBSP0->SPSD = (1 << XCR2_RDATDLY);//主口发送延时1bit数据
McBSP1->SPSA = XCR2;
McBSP1->SPSD = (1 << XCR2_RDATDLY);//从口发送无延时
_delay_loop_(1);//延时等待
McBSP0->SPSA = SPCR1;
McBSP0->SPSD |= (1 << SPCR1_RRST);//开串口接收
McBSP1->SPSA = SPCR1;
McBSP1->SPSD |= (1 << SPCR1_RRST);//开串口接收
_delay_loop_(1);//延时等待 1us
McBSP0->SPSA = SPCR2;
McBSP0->SPSD |= (1 << SPCR2_GRST) | (1 << SPCR2_XRST) | (1 << SPCR2_FRST);//开时钟发送,开串口时钟,开帧发送
McBSP1->SPSA = SPCR2;
McBSP1->SPSD |= (1 << SPCR2_GRST) | (1 << SPCR2_XRST) | (1 << SPCR2_FRST);//开时钟
_delay_loop_(1);//延时等待
}
主程序:
#include "C5402DEF.h"
#include "DSP_SPI.h"
#include <stdio.h>
#include <math.h>
extern void init_5402();
extern void init_MCBSP();
main ()
{
TI_REG sin="0";
//int i="0";
init_5402();
init_MCBSP();
while(1)
{
//for (i=0;i<200;i++)
//{
sin=sin+0;
McBSP0->DXR1 = 0x0056;//主口写一个字
//McBSP1->SPSA = SPCR1;
//while((McBSP1->SPSD & (1 << SPCR1_RRDY))) {};//等待从口DDR接受完成
sin=McBSP1->DRR1;//从口保存数据
//if (i==200) i="0";
//}
}
}