21ic电子技术开发论坛 单片机与嵌入式系统 德州仪器MCU c5502uart串口调用csl函数数据错位问题
发新帖我要提问
返回列表
打印

c5502uart串口调用csl函数数据错位问题

[复制链接]
726|9
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
加cpp|  楼主 | 2016-10-19 10:32 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 加cpp 于 2016-10-20 17:43 编辑

若已知需要输出的数据char pbuf[5]={0xaa,0xbb,0xcc,0xdd,0xee}

而串口结果输出的是0xbb,0xcc,0xdd,0xee,0xee发生了移位

使用的是CSLBool returnFlag;

returnFlag=UART_write(&pbuf[0],plen,0);

***************************************附上原程序********************************************

#include <stdio.h>
#include <csl.h>
#include <csl_pll.h>
#include <csl_chip.h>
#include <csl_irq.h>
#include <csl_gpt.h>
#include <csl_uart.h>
#include <csl_uarthal.h>

void delay(unsigned int N);
/* Reference start of interrupt vector table */
/* This symbol is defined in file, vectors.s55 */
extern void VECSTART(void);

Uint16 i = 0;
Uint16 j = 0;
Uint16 DestData,DestData1,DestData2;
Uint16 DataCount=0;
Uint16 LLL;
Uint16 plen=5;

Uint16 z;

char pbuf[5]={0x11,0x22,0x33,0x44,0x55};
char t_data;
CSLBool returnFlag;
/* 通过定义宏来控制两个外围存储器映射的寄存器,从而实现对GPIO口的控制 */
#define GPIODIR (*(volatile ioport Uint16*)(0x3400))
#define GPIODATA (*(volatile ioport Uint16*)(0x3401))
/*UART的中断程序*/


interrupt void UartIsr(void)
{
// Transimit seriz of serial debugger on pc is:
// 1112131415161718191A1B1C1D1E1F2021222324
UART_FSET(URLCR, DLAB, 0);

// wait for RX empty
// while(!UART_FGET(URLSR,DR));
// DestData = UART_RGET(URRBR);
// DestData1=DestData;
// returnFlag=UART_write(&pbuf[0],length,0);
// DestData2=UART_RGET(URTHR);
/* for(z=0;z<20;z++)
{
UART_FSET(URLCR, DLAB, 0);
LLL=z;
UART_RSET(URTHR,LLL);
DestData2=UART_RGET(URTHR);
}
*/

}
void Uart_Config(void)
{
/* Set BSR to disable SP2MODE */
CHIP_FSET(XBSR, SP2MODE,0) ;

/* Disable all UART events */
UART_FSET(URLCR,DLAB,0);
UART_RSET(URIER, UART_RINT);

/* Reset and disable FIFOs */
UART_RSET(URFCR, 0x7);
UART_RSET(URFCR, 0);

/* Set DLL and DLM to values appropriate for the required baudrate */
UART_FSET(URLCR, DLAB, 1); // DLAB = 1
//UART_RSET(URDLL, 0x45); // 9600bps
UART_RSET(URDLL, 0xE8); // 9600bps
UART_RSET(URDLM, 0x01);
UART_FSET(URLCR, DLAB, 0); // DLAB = 0

/* Setup word size, stop bits, parity */
UART_RSET(URLCR, 0x03); // 8 data bits, odd parity, one stop bit

/* Disable loopback control */
UART_RSET(URMCR, 0);

/* UART out of reset */
UART_FSET(URPECR,URST,1);

/* Temporarily disable all maskable interrupts */
//IRQ_globalDisable();

/* Clear interrupt enable bit */
IRQ_disable(IRQ_EVT_RINT2);

/* Clear any pending Timer interrupts */
IRQ_clear(IRQ_EVT_RINT2);

/* Place interrupt service routine address at */
/* associated vector location */
IRQ_plug(IRQ_EVT_RINT2, &UartIsr);

/* Enable Timer interrupt */
IRQ_enable(IRQ_EVT_RINT2);

/* Enable all maskable interrupts */
//IRQ_globalEnable(); // IRQ_globalDisable();
}
void main(void)
{
/* Initialize CSL library - This is REQUIRED !!! */
CSL_init();

/* PLL configuration structure used to set up PLL interface */
// 主频为300Mhz
PLL_setFreq(1, 0x3, 0, 1, 3, 3, 0);


IRQ_setVecs((Uint32)(&VECSTART));
Uart_Config();
/* Enable all maskable interrupts */
IRQ_globalEnable();

returnFlag=UART_write(&pbuf[0],plen,0);

DestData2=UART_RGET(URTHR);

for(;;)
{

for(i=0; i<16; i++)
{
delay(300);

}

}
}
void delay(unsigned int N)
{
unsigned int i,j;
for(i=0;i<N;i++)
for(j=0;j<N;j++)
asm(" nop");

}

uart.jpg (140.6 KB )

uart.jpg

相关帖子

沙发
zhangmangui| | 2016-10-19 22:20 | 只看该作者
详细看看UART_write 函数的参数吧

使用特权

评论回复
板凳
touser| | 2016-10-19 22:27 | 只看该作者
计算是应该从0开始的。

使用特权

评论回复
地板
touser| | 2016-10-19 22:31 | 只看该作者
fifo写满了?

使用特权

评论回复
5
加cpp|  楼主 | 2016-10-20 17:42 | 只看该作者
zhangmangui 发表于 2016-10-19 22:20
详细看看UART_write 函数的参数吧

看过了,很简略,就是拉黄的这一块

使用特权

评论回复
6
加cpp|  楼主 | 2016-10-20 17:44 | 只看该作者
zhangmangui 发表于 2016-10-19 22:20
详细看看UART_write 函数的参数吧

参数就是上面添加了的图片

使用特权

评论回复
7
加cpp|  楼主 | 2016-10-20 17:45 | 只看该作者
touser 发表于 2016-10-19 22:27
计算是应该从0开始的。

5是指数组大小吧,是从0开始发的,上面添加了csl的函数库请帮忙审阅下

使用特权

评论回复
8
加cpp|  楼主 | 2016-10-20 17:46 | 只看该作者

我没有用fifo,直接用char8位传输

使用特权

评论回复
9
232321122| | 2016-10-22 23:08 | 只看该作者
这个怎么会错位?

使用特权

评论回复
10
232321122| | 2016-10-22 23:10 | 只看该作者
难道函数的传递过程有问题?

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

4

主题

12

帖子

0

粉丝
关闭 热门推荐
快速回复 在线客服 返回列表 返回顶部