This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

5502uart串口使用乱码

Other Parts Discussed in Thread: MAX3232

使用的是5502pgf300mhz的芯片,用max3232芯片与rs232进行连接,目前测试程序是看串口发送数据给dsp再接收回串口

现在有两个问题,请各位大神指教:

1.根据设备管理器com4,波特率9600,数据8位,无校验,1位停止配置进行操作,先运行程序再开串口调试助手,出现乱码错误,请问问题出在哪儿的。如图:

2.上面问题解决的基础上,需要对其进行改动,不是从pc上发送和接收,只需要将dsp运算的结果通过串口传输出来,是不是利用csl的uart_write()宏来设置?

附上程序:

#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;
Uint16 DataCount=0;
/* 通过定义宏来控制两个外围存储器映射的寄存器,从而实现对GPIO口的控制 */
#define GPIODIR (*(volatile ioport Uint16*)(0x3400))
#define GPIODATA (*(volatile ioport Uint16*)(0x3401))

//Uint16 length = 4;
//char pbuf[4] = {0x74, 0x65, 0x73, 0x74};
//CSLBool returnFlag;

/*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;
UART_FSET(URLCR, DLAB, 0);
UART_RSET(URTHR,DestData1);
}
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, no 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, 0xf, 0, 1, 3, 3, 0);


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

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

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");

}