本帖最后由 jijicaode 于 2013-3-27 14:15 编辑
DSP和PLC串行通讯问题,搞不定毕不了业了。。。求助 我用的是DM642,用并串互转芯片TL16C752B进行串口电路的拓展,用RS232串口和三菱的FX-1N进行通信。我做了无数的实验,DSP能跟电脑通信,FX-1N能跟电脑通信,但是DSP和FX-1N就不能进行通信。另外FX-1N跟电脑通讯的时候,用串口调试工具看一定要设置BREAK位,,就是左下角一栏中的BREAK要勾上,FX-1N才能正确的和电脑进行通信。BREAK的意思我也查过:(通常,直到有数据传输时,接收和传输信号会保持在mark电压。如果一个信号掉到space电压并且持续了很长时间,一般来说是1/4到1/2秒,那么就说有一个break条件存在了。BREAK经常被用来重置一条数据线或者用来改变像调制解调器这样的设备的通讯模式。)下面贴上我的FX-1N和电脑串行通信的程序。 最重要的是贴上我的DSP与PC通信的程序。/********************************************************************/
/* Copyright 2004 by SEED Incorporated. */
/* All rights reserved. Property of SEED Incorporated. */
/* Restricted rights to use, duplicate or disclose this code are */
/* granted through contract. */
/* */
/********************************************************************/
#include <csl.h>
#include <csl_emifa.h>
#include <csl_irq.h>
#include <csl_chip.h>
#include "seeddm642.h"
#include "seeddm642_uart.h"
/*SEEDDM642的emifa的设置结构*/
EMIFA_Config Seeddm642ConfigA ={
0x00052078,/*gblctl EMIFA(B)global control register value */
/*将CLK6、4、1使能;将MRMODE置1;使能EK2EN,EK2RATE*/
0xffffffd3,/*cectl0 CE0 space control register value*/
/*将CE0空间设为SDRAM*/
0x73a28e01,/*cectl1 CE1 space control register value*/
/*Read hold: 1 clock;
MTYPE : 0000,选择8位的异步接口
Read strobe :001110;14个clock宽度
TA:2 clock; Read setup 2 clock;
Write hold :2 clock; Write strobe: 14 clock
Write setup :7 clock
-- ---------------
\ 14c /1c
\----------------/ */
0x22a28a22, /*cectl2 CE2 space control register value*/
0x22a28a42, /*cectl3 CE3 space control register value*/
0x57115000, /*sdctl SDRAM control register value*/
0x0000081b, /*sdtim SDRAM timing register value*/
0x001faf4d, /*sdext SDRAM extension register value*/
0x00000002, /*cesec0 CE0 space secondary control register value*/
0x00000002, /*cesec1 CE1 space secondary control register value*/
0x00000002, /*cesec2 CE2 space secondary control register value*/
0x00000073 /*cesec3 CE3 space secondary control register value*/
};
SEEDDM642_UART_Config UartConfig ={
0x00,/*寄存器IER*/
0x57,/*寄存器FCR*/
0x1F,/*寄存器LCR*/
0x00,/*寄存器MCR*/
};
extern far void vectors();
Uint8 IOreadback;
Uint16 buffer;
SEEDDM642_UART_Handle SEEDuartHandleA;
SEEDDM642_UART_Handle SEEDuartHandleB;
/*此程序可将四个采集口的数据经过Video Port0送出*/
void main()
{
/*-------------------------------------------------------*/
/* perform all initializations */
/*-------------------------------------------------------*/
/*Initialise CSL,初始化CSL库*/
CSL_init();
/*----------------------------------------------------------*/
/*EMIFA的初始化,将CE0设为SDRAM空间,CE1设为异步空间
注,DM642支持的是EMIFA,而非EMIF*/
EMIFA_config(&Seeddm642ConfigA);
/*----------------------------------------------------------*/
/*中断向量表的初始化*/
//Point to the IRQ vector table
IRQ_setVecs(vectors);
/*----------------------------------------------------------*/
/*测试SEEDDM642的数字输入与输出*/
/*输出测试值*/
SEEDDM642_rset(SEEDDM642_IOOUT, 0x55);
/*延时1ms时间*/
SEEDDM642_waitusec(1);
/*读回测试值*/
IOreadback = SEEDDM642_rget(SEEDDM642_IOOUT);
/*延时1ms时间*/
SEEDDM642_waitusec(1);
/*输出测试值*/
SEEDDM642_rset(SEEDDM642_IOOUT, 0xaa);
/*延时1ms时间*/
SEEDDM642_waitusec(1);
/*读回测试值*/
IOreadback = SEEDDM642_rget(SEEDDM642_IOOUT);
/*延时1ms时间*/
SEEDDM642_waitusec(1);
/*输出测试值*/
SEEDDM642_rset(SEEDDM642_IOOUT, 0x33);
/*延时1ms时间*/
SEEDDM642_waitusec(1);
/*读回测试值*/
IOreadback = SEEDDM642_rget(SEEDDM642_IOOUT);
/*延时1ms时间*/
SEEDDM642_waitusec(1);
/*----------------------------------------------------------*/
/*测试串口A*/
/* Open UART */
SEEDuartHandleA = SEEDDM642_UART_open(SEEDDM642_UARTA,
SEEDDM642_UART_BAUD57600,
&UartConfig);
/*Open UARTB*/
SEEDuartHandleB = SEEDDM642_UART_open(SEEDDM642_UARTB,
SEEDDM642_UART_BAUD57600,
&UartConfig);
/* Loop through 256 bytes */
for (;;)
{
buffer = SEEDDM642_UART_getChar(SEEDuartHandleA);
// buffer = 0x55;
SEEDDM642_UART_putChar(SEEDuartHandleA, (buffer & 0xff));
}
/* for (;;)
{
buffer = SEEDDM642_UART_getChar(SEEDuartHandleB);
// buffer = 0x55;
SEEDDM642_UART_putChar(SEEDuartHandleB, (buffer & 0xff));
}*/
}
需要修改UART的设置吗?怎么改?我修改了一些都连接不起来。望高手指教!!!不然毕不了业了!哎哎
|