本帖最后由 加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");
} |