RS232通信实验
1 通信的基本感念
2 F28335的SCI介绍
3 SCI配置步骤
4 硬件设计
5 软件设计
#include "uart.h"void UARTa_Init(Uint32 baud)
{unsigned char scihbaud=0;unsigned char scilbaud=0;Uint16 scibaud=0;scibaud=37500000/(8*baud)-1;scihbaud=scibaud>>8;scilbaud=scibaud&0xff;EALLOW;SysCtrlRegs.PCLKCR0.bit.SCIAENCLK = 1; // SCI-AEDIS;InitSciaGpio();//Initalize the SCI FIFOSciaRegs.SCIFFTX.all=0xE040;SciaRegs.SCIFFRX.all=0x204f;SciaRegs.SCIFFCT.all=0x0;// Note: Clocks were turned on to the SCIA peripheral// in the InitSysCtrl() functionSciaRegs.SCICCR.all =0x0007; // 1 stop bit, No loopback// No parity,8 char bits,// async mode, idle-line protocolSciaRegs.SCICTL1.all =0x0003; // enable TX, RX, internal SCICLK,// Disable RX ERR, SLEEP, TXWAKESciaRegs.SCICTL2.all =0x0003;SciaRegs.SCICTL2.bit.TXINTENA =1;SciaRegs.SCICTL2.bit.RXBKINTENA =1;SciaRegs.SCIHBAUD =scihbaud; // 9600 baud @LSPCLK = 37.5MHz.SciaRegs.SCILBAUD =scilbaud;
// SciaRegs.SCICCR.bit.LOOPBKENA =1; // Enable loop backSciaRegs.SCICTL1.all =0x0023; // Relinquish SCI from Reset}// Transmit a character from the SCI'
void UARTa_SendByte(int a)
{while (SciaRegs.SCIFFTX.bit.TXFFST != 0);SciaRegs.SCITXBUF=a;
}void UARTa_SendString(char * msg)
{int i=0;while(msg[i] != '\0'){UARTa_SendByte(msg[i]);i++;}
}
#ifndef UART_H_
#define UART_H_#include "DSP2833x_Device.h" // DSP2833x 头文件
#include "DSP2833x_Examples.h" // DSP2833x 例子相关头文件void UARTa_Init(Uint32 baud);
void UARTa_SendByte(int a);
void UARTa_SendString(char * msg);#endif /* UART_H_ */
#include "DSP2833x_Device.h" // DSP2833x Headerfile Include File
#include "DSP2833x_Examples.h" // DSP2833x Examples Include File#include "leds.h"
#include "time.h"
#include "uart.h"/*******************************************************************************
* 函 数 名 : main
* 函数功能 : 主函数
* 输 入 : 无
* 输 出 : 无
*******************************************************************************/
void main()
{int i=0;char *msg;Uint16 ReceivedChar=0;InitSysCtrl();InitPieCtrl();IER = 0x0000;IFR = 0x0000;InitPieVectTable();LED_Init();TIM0_Init(150,200000);//200msUARTa_Init(4800);msg = "Hello World!\r\n";UARTa_SendString(msg);msg = "You will enter a character, and the DSP will echo it back!\r\n";UARTa_SendString(msg);while(1){msg = "\r\nEnter a character: ";UARTa_SendString(msg);// Wait for inc characterwhile(SciaRegs.SCIFFRX.bit.RXFFST !=1);// wait for XRDY =1 for empty state// Get characterReceivedChar = SciaRegs.SCIRXBUF.all;// Echo character backmsg = " You sent: ";UARTa_SendString(msg);UARTa_SendByte(ReceivedChar);DELAY_US(1000);}
}