异步串口实验,出现了两个问题:
(1)在FIFO轮循模式下,用串口调试助手发送一个字符串:1234567
8910111 ,DSP接收到数据后在1602液晶上显示,但是结果为:1234567
0110111 红 {MOD}标记的两位传输错误,又尝试把字符串换成:you are great!,结果显示:前面两位是乱码,后面都是正确的。想问下这是什么原因?是波特率设置的问题?晶振是11.05926MHZ,波特率为9600Bps ,换成其他的波特率,比如4800,14400,还是不行。
(2) 把FIFO模式关闭,只在串口中断下进行数据的收发,同样是有串口调试助手发送字符串,DSP接受后在LCD上显示,代码是和轮循模式一样的,出现的结果就是:DSP只发,没收。这又是什么原因啊?
说明(1)(2) 分别是单独调试的,调试一个,另外的就注释掉
下面是在例程基础上稍作改动的原代码:
/*********************************************************************
** Module Name: UART **
** Author: CTH **
** Version: 1.0 **
** CreateDate: 2008-8-10 **
** Description: **
** Remark: **
** Revision History: 2008-8-10 **
** Web:
http://www.study-kit.com **
**********************************************************************/
#include <csl.h>
#include <csl_pll.h>
#include <csl_emif.h>
#include <csl_chip.h>
#include <stdio.h>
/***LCD寄存器******/
#define LCD_REG (*((unsigned int *)0x200003))
#define LCD_DATA (*((unsigned int *)0x200006))
#define comm 0
#define dat 1
/*异步通信接口芯片 内部寄存器*/
#define UART_BASE_ADDR 0x200008 // UART寄存器地址
#define RHR *((int *)(UART_BASE_ADDR+0))
#define THR *((int *)(UART_BASE_ADDR+0))
#define IER *((int *)(UART_BASE_ADDR+1))
#define ISR *((int *)(UART_BASE_ADDR+2))
#define FCR *((int *)(UART_BASE_ADDR+2))
#define LCR *((int *)(UART_BASE_ADDR+3))
#define MCR *((int *)(UART_BASE_ADDR+4))
#define LSR *((int *)(UART_BASE_ADDR+5))
#define MSR *((int *)(UART_BASE_ADDR+6))
#define SCR *((int *)(UART_BASE_ADDR+7))
#define DLL *((int *)(UART_BASE_ADDR+0))
#define DLM *((int *)(UART_BASE_ADDR+1))
/*定义UART分频系数,在11.05926M时,波特率为9600BPS*/
#define DLL_DATA 0x48
#define DLM_DATA 0x00
/*变量的定义、初始化*/
CSLBool b;
Uint16 eventId0;
int old_intm;
interrupt void int0(void); //外部中断0
unsigned char str1[]={"study-kit.com "};
unsigned char str2[]={"TEL:010-82623343"};
extern void VECSTART(void);
/****函数声明****/
void LCD1602_initial( );
void Delay(unsigned int nDelay);
void delaynum(unsigned int d_time);
void wr_lcd(unsigned char dat_comm, unsigned int content);
void lcd_display(void);
void clrram();
/*锁相环的设置*/
PLL_Config myConfig = {
0, //IAI: the PLL locks using the same process that was underway
//before the idle mode was entered
1, //IOB: If the PLL indicates a break in the phase lock,
//it switches to its bypass mode and restarts the PLL phase-locking
//sequence
12, //PLL multiply value; multiply 12 times
0 //Divide by 2 PLL divide value; it can be either PLL divide value
//(when PLL is enabled), or Bypass-mode divide value
//(PLL in bypass mode, if PLL multiply value is set to 1)
};
/*SDRAM的EMIF设置*/
EMIF_Config emiffig = {
0x221, //EGCR : the MEMFREQ = 00,the clock for the memory is equal to cpu frequence
// the WPE = 0 ,forbiden the writing posting when we debug the EMIF
// the MEMCEN = 1,the memory clock is reflected on the CLKMEM pin
// the NOHOLD = 1,HOLD requests are not recognized by the EMIF
0xFFFF, //EMI_RST: any write to this register resets the EMIF state machine
0x1fff, //CE3_1: CE0 space control register 1
0x00ff, //CE3_2: CE0 space control register 2
0x00ff, //CE3_3: CE0 space control register 3
0x1fff, //CE1_1: CE0 space control register 1
// Asynchronous, 16Bit
0x00ff, //CE1_2: CE0 space control register 2
0x00ff, //CE1_3: CE0 space control register 3
0x1FFF, //CE2_1: CE0 space control register 1
// Asynchronous, 16Bit
0xFFFF, //CE2_2: CE0 space control register 2
0x00FF, //CE2_3: CE0 space control register 3
0x1fff, //CE3_1: CE0 space control register 1
0x00ff, //CE3_2: CE0 space control register 2
0x00ff, //CE3_3: CE0 space control register 3
0x2911, //SDC1: SDRAM control register 1
// TRC = 8
// SDSIZE = 0;SDWID = 0
// RFEN = 1
// TRCD = 2
// TRP = 2
0x0410, //SDPER : SDRAM period register
// 7ns *4096
0x07FF, //SDINIT: SDRAM initialization register
// any write to this register to init the all CE spaces,
// do it after hardware reset or power up the C55x device
0x0131 //SDC2: SDRAM control register 2
// SDACC = 0;
// TMRD = 01;
// TRAS = 0101;
// TACTV2ACTV = 0001;
};
/*中断配置*/
void INTconfig()
{
/* Temporarily disable all maskable interrupts */
IRQ_setVecs((Uint32)(&VECSTART));
/* Temporarily disable all maskable interrupts */
old_intm = IRQ_globalDisable();
/* Get Event Id associated with External INT1(8019), for use with */
eventId0 = IRQ_EVT_INT0;
/* Clear any pending INT0 interrupts */
IRQ_clear(eventId0);
/* Place interrupt service routine address at */
/* associated vector location */
IRQ_plug(eventId0,&int0);
/* Enable INT0(8019) interrupt */
IRQ_enable(eventId0);
/* Enable all maskable interrupts */
IRQ_globalEnable();
}
void delay(unsigned int d_time)
{
while(d_time--);
}
main()
{
unsigned int temp,data,i,k;
/*初始化CSL库*/
CSL_init();
/*EMIF为全EMIF接口*/
CHIP_RSET(XBSR,0x0a01);
/*设置系统的运行速度为144MHz*/
PLL_config(&myConfig);
/*初始化DSP的EMIF*/
EMIF_config(&emiffig);
INTconfig();
/*UART初始化*/
LCR = 0x80; //设置波提率 通信线路控制寄存器
temp=LCR; //通信线路控制寄存器
DLL = DLL_DATA; //写除数低8位
DLM = DLM_DATA; //写除数高8位
temp=DLL_DATA;
LCR = 0x00; //设置通信的数据格式,D7=0
LCR = 0x03; //8位数据,一个停止位
FCR = 0xc1; //FIFO控制寄存器,在FIFO模式
MCR = 0x08; //调制解调控制寄存器,OUT2=1,中断信号可通过系统总线送给8520中断控制寄存器
IER = 0x00; //中断使能寄存器禁止,4种中断都禁止
while(1)
{
/*发送字符串*/
/*for(k=0;k<16;k++)
{
THR=str1[k];
delay(200);
}
for(k=0;k<16;k++)
{
THR=str2[k];
delay(200);
}
delay(5000); */
temp=LSR; //通信线路状态寄存器
data=ISR; //中断识别寄存器,判别中断的类型
THR =0x55; //发送保持寄存器,要发送的数据是U,对应16进制ASCII
if(temp&0x01)
{
lcd_display( ); // 液晶显示接受到字符
temp=0;
}
delay(5000);
}
}
void Delay(unsigned int nDelay)
{
int ii,jj,kk=0;
for ( ii=0;ii<nDelay;ii++ )
{
for ( jj=0;jj<1024;jj++ )
{
kk++;
}
}
}
//External INT0(EXINT)中断处理函数
interrupt void int0()
{
unsigned int temp,data,i;
temp=LSR;
//data=ISR;
if(temp&0x01)//LSR的最低位不为0,表示数据已经准备好接收
{
lcd_display( ); // 液晶显示接受到字符
temp=0;
}
if(detect&0x20)// 发送缓冲寄存器为空,进行写操作
{
THR=0x55;
printf("write data:%x",THR);
}
temp=0;
}
/*************************************************
液晶模块
*************************************************/
/***忙检测****/
void Delay(unsigned int nDelay)
{
int ii,jj,kk=0;
for ( ii=0;ii<nDelay;ii++ )
{
for ( jj=0;jj<1024;jj++ )
{
kk++;
}
}
}
/*时序延时*/
void delaynum(unsigned int d_time)
{
while(d_time--);
}
void LCD1602_initial( )
{
wr_lcd(comm,0x01);
wr_lcd(comm,0x30);
wr_lcd(comm,0x0c);
wr_lcd(comm,0x06);
}
void wr_lcd(unsigned char dat_comm, unsigned int content)
{
Delay(40);
if(dat_comm) // wtite data
{
LCD_REG=0x01; // rs=1,en=0
LCD_DATA=content;
LCD_REG=0x03; //en=1,rs=1
delaynum(80);
LCD_REG=0x00; //en=0 ,rs=0
}
else //write command
{
LCD_REG=0x00;
LCD_DATA=content;
LCD_REG=0x02;
delaynum(80);
LCD_REG=0x00;
}
Delay(100);
}
/*液晶显示*/
void lcd_display( )
{
int n;
clrram();
wr_lcd(comm,0x80);
for(n=0;n<14;n++)
{
wr_lcd(dat,RHR);
delay(200);
}
}
/*清屏*/
void clrram()
{
wr_lcd(comm,0x01);
}
/******************************************************************************
* End of UART.c
******************************************************************************/
此帖出自
小平头技术问答
不太明白版主说的“发的就不对”是什么意思?显示部分程序有问题,怎讲?从哪里可以看出来?希望版主能够说的详细点,谢谢!
“发的不对”就是说你发送的内容本来就是错的。“显示部分程序有问题”是说显示时数据对应的显示字符搞错了。到底是什么地方不对,一项项的去检查、排除,顺着“发送——接收——显示”这个顺序查找。
好吧,谢谢回复!
一周热门 更多>