1471 views|0 replies
- Last login
- 2023-10-7
- Online Time
- 253 hours
- Prestige
- 1125 points
- Points
- 830 points
|
SCI配置 SCI_Configure.c
/* Includes ------------------------------------------------------------------*/
#include
#include
#include "C2000_it.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
#define CBR_110 11E1
#define CBR_300 3E2
#define CBR_600 6E2
#define CBR_1200 12E2
#define CBR_2400 24E2
#define CBR_4800 48E2
#define CBR_9600 96E2
#define CBR_14400 144E2
#define CBR_19200 192E2
#define CBR_38400 384E2
#define CBR_56000 56E3
#define CBR_57600 576E2
#define CBR_115200 1152E2
#define CBR_128000 128E3
#define CBR_256000 256E3
#define CPU_FREQ 60E6
#define LSPCLK_FREQ (CPU_FREQ/4)
#define SCI_BAUD(baud) (LSPCLK_FREQ/(baud*8))-1
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/****************************************************************************
* Function Name : SCI_Configure
* Description : SCI 引脚和参数配置
* Input : None
* Output : None
* Return : None
******************************************************************************/
void SCI_Configure(void)
{
EALLOW;
// GPIO28/SCI_RX,配置成上拉输入,输入限定脉冲周期为3*2=6个时钟周期
GpioCtrlRegs.GPADIR.bit.GPIO28 = 0; // 配置为输入
GpioCtrlRegs.GPAPUD.bit.GPIO28 = 0; // 使能上拉
GpioCtrlRegs.GPAMUX2.bit.GPIO28 = 1; // 配置 GPIO28 为SCI_RX
GpioCtrlRegs.GPAQSEL2.bit.GPIO28 = 3; // 限定输入脉冲为6
// GPIO29/SCI_TX,配置为无上拉输出
GpioCtrlRegs.GPADIR.bit.GPIO29 = 1; // 配置为输出
GpioCtrlRegs.GPAPUD.bit.GPIO29 = 1; // 禁止上拉
GpioCtrlRegs.GPAMUX2.bit.GPIO29 = 1; // 配置 GPIO29 为SCI_TX
SciaRegs.SCICTL1.bit.SWRESET = 0; // 复位SCI寄存器
SciaRegs.SCICTL1.bit.SWRESET = 1; // 完成复位
// 配置SCI 8位数据位,1个停止位,无校验,波特率 115200
SciaRegs.SCICCR.bit.STOPBITS = 0; // 0:1个停止位 1:两个停止位
SciaRegs.SCICCR.bit.PARITY = 0; // 0:奇校验 1:偶校验
SciaRegs.SCICCR.bit.PARITYENA = 0; // 0: Disable parity check 1: Enable parity check SciaRegs.SCICCR.bit.SCICHAR = 7; // 7: 8 data bits SciaRegs.SCIHBAUD = 0; SciaRegs.SCILBAUD = SCI_BAUD(CBR_115200); SciaRegs.SCICTL1.bit.RXENA = 1; // 0: Disable reception 1: Enable reception SciaRegs.SCICTL1.bit.TXENA = 1; // 0: Disable transmission 1: Enable transmission SciaRegs.SCICTL2.bit.RXBKINTENA = 0; // 0: Disable receive interrupt 1: Enable receive interrupt SciaRegs.SCICTL2.bit.TXINTENA = 0; // 0: Disable send interrupt 1: Enable send interrupt EDIS; } /******************************************************************************** * Function Name : SCI_SendByte * Description : SCI sends a byte * Input : unsigned char TxByte: byte to be sent * Output : None * Return : None **********************************************************************/ void SCI_SendByte(unsigned char TxByte) { while(SciaRegs.SCICTL2.bit.TXRDY != 1); SciaRegs.SCITXBUF = TxByte; [size=4 ]} /****************************************************************************** * Function Name : SCI_PrintfStringTest * Description : SCI sends a string test * Input : None * Output : None * Return: None **********************************************************************/ void SCI_PrintfStringTest(void) { unsigned char retry = 0; char buff[] = "\nwww.ccnu.edu.cn"; for(retry =0; retry!=sizeof(buff); ++retry){ SCI_SendByte(buff[retry]); } } None
******************************************************************************/
void SCI_SendByte(unsigned char TxByte)
{
while(SciaRegs.SCICTL2.bit.TXRDY != 1);
SciaRegs.SCITXBUF = TxByte;
}
/****************************************************************************
* Function Name : SCI_PrintfStringTest
* Description : SCI 发送一个字符串测试
* Input : None
* Output : None
* Return : None
******************************************************************************/
void SCI_PrintfStringTest(void)
{
unsigned char retry = 0;
char buff[] = "\nwww.ccnu.edu.cn";
for(retry=0; retry!=sizeof(buff); ++retry){
SCI_SendByte(buff[retry]);
}
}
None
******************************************************************************/
void SCI_SendByte(unsigned char TxByte)
{
while(SciaRegs.SCICTL2.bit.TXRDY != 1);
SciaRegs.SCITXBUF = TxByte;
}
/****************************************************************************
* Function Name : SCI_PrintfStringTest
* Description : SCI 发送一个字符串测试
* Input : None
* Output : None
* Return : None
******************************************************************************/
void SCI_PrintfStringTest(void)
{
unsigned char retry = 0;
char buff[] = "\nwww.ccnu.edu.cn";
for(retry=0; retry!=sizeof(buff); ++retry){
SCI_SendByte(buff[retry]);
}
}
|
|