|
基于Hercules 的工业“安全”控制系统 测试 RS485 发送
[复制链接]
基于Hercules 的工业“安全”控制系统 测试 RS485 发送数据到PC
硬件说明
Hercules 数字隔离RS485
TMS5700432 ====ISO15M
程序参考:example_sci_uart_9600.c
/* Include Files */
#include "sys_common.h"
#include "system.h"
/* USER CODE BEGIN (1) */
#include "sci.h"
#include "spi.h"
#define TSIZE1 10
uint8 TEXT1[TSIZE1]= {'R','S','4','8','5','-','O','K','\n','\r'};
#define TSIZE2 18
uint8 TEXT2[TSIZE2]= {'E','E','W','O','R','L','D','-','-','-','-','-','-','D','I','Y','\n','\r'};
#define TSIZE3 19
uint8 TEXT3[TSIZE3]= {'T','E','X','A','S',' ','I','N','S','T','R','U','M','E','N','T','S','\n','\r'};
void sciDisplayText(sciBASE_t *sci, uint8 *text, uint32 length);
void wait(uint32 time);
#define UART scilinREG
#define DIR_Rx gioSetBit(spiPORT3, SPI_PIN_SIMO, 0);
#define DIR_Tx gioSetBit(spiPORT3, SPI_PIN_SIMO, 1);
void delay(uint32 para)
{
uint32 i;
for(i = 0; i < para; i++)
{
asm("NOP");
}
}
/****************************************************************
* ISO15M TMS570_LIN(SCI)
* TXD LINTX
* RXD LINRX
* DIR SPI3SIMO
*/
void main(void)
{
/* USER CODE BEGIN (3) */
sciInit(); /* initialize sci/sci-lin */
/* even parity , 2 stop bits */
spiInit();
//不需要设置方向
//gioSetDirection(spiPORT3, SPI_PIN_SIMO);
DIR_Tx;
DIR_Rx;
DIR_Tx;
while(1) /* continious desplay */
{
sciDisplayText(UART,&TEXT1[0],TSIZE1); /* send text code 1 */
sciDisplayText(UART,&TEXT2[0],TSIZE2); /* send text code 2 */
sciDisplayText(UART,&TEXT3[0],TSIZE3); /* send text code 3 */
delay(0x00400000);
};
}
/* USER CODE BEGIN (4) */
void sciDisplayText(sciBASE_t *sci, uint8 *text,uint32 length)
{
while(length--)
{
while ((UART->FLR & 0x4) == 4); /* wait until busy */
sciSendByte(UART,*text++); /* send out text */
};
}
|
|