新手小白,刚刚开始学习DSP,将自己的过程记录下来。(自用记录,防止遗忘!)
一、实验现象
1. 通过对TI例程进行调试,初步实现F280049开发板与PC机串口之间的通信。目前可实现在串口助手中发送一串字符,PC机可进行数据接收,但回显显示结果存在丢失数据的现象。
如下图:
二、解决方案
1. 针对F280049开发板与PC机之间的SCI串口通信时,发送一串字符,PC机可进行数据接收,但回显显示结果存在丢失数据的问题,已解决。
经分析,主要是由于程序未使用FIFO寄存器的方式,无法对PC机发送数据进行缓存处理,只能一位一位的实时处理,当数据从移位寄存器到接收缓冲器时,产生一次中断,此时后面发送的数据对前面未处理的数据进行了覆盖,最终只留下了最后一位数据,导致了数据发送过程中丢失现象。
对此提出了两种解决方式。1). 仍不使用FIFO寄存器对数据进行处理,改变发送数据的方式,一次发送一个字节,同时观察SCIRXBUF与SCITXBUF寄存器,多次发送,避免数据丢失的现象产生。2). 更改程序使用FIFO寄存器将数据缓存至FIFO中,直到满足设置的FIFO深度,从而产生一次中断,对数据进行连续处理。
使用FIFO寄存器目前可实现如下效果:
三、程序代码
废话不说,上代码!
#include "driverlib.h"
#include "device.h"
#ifdef _FLASH
// These are defined by the linker (see device linker command file)
extern uint16_t RamfuncsLoadStart;
extern uint16_t RamfuncsLoadSize;
extern uint16_t RamfuncsRunStart;
#endif
//
// Defines
//
// Define AUTOBAUD to use the autobaud lock feature
//#define AUTOBAUD
//
// Globals
//
uint16_t counter = 0;
unsigned char *msg;
//
// Function Prototypes
//
__interrupt void sciaTxISR(void);
__interrupt void sciaRxISR(void);
//
// Main
//
void main(void)
{
//
// Configure PLL, disable WD, enable peripheral clocks.
//
Device_init();
//
// Disable pin locks and enable internal pullups.
//
Device_initGPIO();
//
// GPIO28 is the SCI Rx pin.
//
GPIO_setMasterCore(DEVICE_GPIO_PIN_SCIRXDA, GPIO_CORE_CPU1); //选择指定GPIO28引脚,主核心为CPU1
GPIO_setPinConfig(DEVICE_GPIO_CFG_SCIRXDA); //GPIO28配置为SCI的 RX接收引脚
GPIO_setDirectionMode(DEVICE_GPIO_PIN_SCIRXDA, GPIO_DIR_MODE_IN); //GPIO28引脚 设置为输入
GPIO_setPadConfig(DEVICE_GPIO_PIN_SCIRXDA, GPIO_PIN_TYPE_STD); //GPIO28引脚引脚类型 为浮动输入
GPIO_setQualificationMode(DEVICE_GPIO_PIN_SCIRXDA, GPIO_QUAL_ASYNC); //GPIO28参数条件模式 为关闭同步
//
// GPIO29 is the SCI Tx pin.
//
GPIO_setMasterCore(DEVICE_GPIO_PIN_SCITXDA, GPIO_CORE_CPU1); //选择指定GPIO29引脚,主核心为CPU1
GPIO_setPinConfig(DEVICE_GPIO_CFG_SCITXDA); //GPIO29配置为SCI的 TX发送引脚
GPIO_setDirectionMode(DEVICE_GPIO_PIN_SCITXDA, GPIO_DIR_MODE_OUT); //GPIO29引脚 设置为输出
GPIO_setPadConfig(DEVICE_GPIO_PIN_SCITXDA, GPIO_PIN_TYPE_STD); //GPIO29引脚引脚类型 为推挽输出
GPIO_setQualificationMode(DEVICE_GPIO_PIN_SCITXDA, GPIO_QUAL_ASYNC); //GPIO29参数条件模式 为关闭同步
//
// Disable global interrupts.
//
DINT; //禁用全局中断
//
// Initialize interrupt controller and vector table.
//
Interrupt_initModule(); //初始化PIE并清除PIE寄存器
Interrupt_initVectorTable(); //用指向shell中断的指针初始化PIE向量表ISR服务程序
IER = 0x0000; //中断使能寄存器 置0
IFR = 0x0000; //中断标志寄存器 置0
//
// Map the ISR to the wake interrupt.
//
Interrupt_register(INT_SCIA_TX, sciaTxISR);//将中断函数与中断向量表映射
Interrupt_register(INT_SCIA_RX, sciaRxISR);
//
// Initialize SCIA and its FIFO.
//
SCI_performSoftwareReset(SCIA_BASE);//软件重置初始化SCIA
//
// Configure SCIA for echoback.
//
SCI_setConfig(SCIA_BASE, 25000000, 9600, (SCI_CONFIG_WLEN_8 |
SCI_CONFIG_STOP_ONE |
SCI_CONFIG_PAR_NONE));//初始化
SCI_resetChannels(SCIA_BASE);//通道重置
SCI_clearInterruptStatus(SCIA_BASE, SCI_INT_TXFF | SCI_INT_RXFF);//清除接收、发送中断寄存器标志位
SCI_enableFIFO(SCIA_BASE);//使能FIFO
SCI_enableModule(SCIA_BASE);//使能接收、发送、重启SCI
SCI_performSoftwareReset(SCIA_BASE);//软件重置SCIA
//
// Set the transmit FIFO level to 0 and the receive FIFO level to 2.
// Enable the TXFF and RXFF interrupts.
//
SCI_setFIFOInterruptLevel(SCIA_BASE, SCI_FIFO_TX0, SCI_FIFO_RX3);//FIFO深度设置
SCI_enableInterrupt(SCIA_BASE, SCI_INT_TXFF | SCI_INT_RXFF);//使能接收、发送中断寄存器标志位
//
// Send starting message.
//
msg = "\r\n\n\nHello World!\0";
SCI_writeCharArray(SCIA_BASE, (uint16_t*)msg, 17);
msg = "\r\nYou will enter a character, and the DSP will echo it back!\0";
SCI_writeCharArray(SCIA_BASE, (uint16_t*)msg, 61);
//
// Clear the SCI interrupts before enabling them.
//
SCI_clearInterruptStatus(SCIA_BASE, SCI_INT_TXFF | SCI_INT_RXFF);//清除接收、发送中断寄存器标志位
//
// Enable the interrupts in the PIE: Group 9 interrupts 1 & 2.
//
Interrupt_enable(INT_SCIA_RX);//使能外设中断RX、TX
Interrupt_enable(INT_SCIA_TX);
Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP9);//9号中断向量组的9.1、9.2号
//
// Enable global interrupts.
//
EINT;
for(;;)
{
}
}
//
// sciaTxISR - Disable the TXFF interrupt and print message asking
// for two characters.
__interrupt void
sciaTxISR(void)
{
//
// Disable the TXRDY interrupt.
//
SCI_disableInterrupt(SCIA_BASE, SCI_INT_TXFF);
msg = "\r\nEnter two characters: \0";
SCI_writeCharArray(SCIA_BASE, (uint16_t*)msg, 25);
//
// Acknowledge the PIE interrupt.
//
Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP9);
}
//
// sciaRxISR - Read two characters from the RXBUF and echo them back.
//
__interrupt void
sciaRxISR(void)
{
uint16_t receivedChar1, receivedChar2, receivedChar3;//receivedChar4;
//
// Enable the TXFF interrupt again.
//
SCI_enableInterrupt(SCIA_BASE, SCI_INT_TXFF);
//
// Read two characters from the FIFO. //读取三次sci
//
receivedChar1 = SCI_readCharBlockingFIFO(SCIA_BASE);
receivedChar2 = SCI_readCharBlockingFIFO(SCIA_BASE);
receivedChar3 = SCI_readCharBlockingFIFO(SCIA_BASE);
//
// Echo back the two characters.
//
msg = " You sent: \0";
SCI_writeCharArray(SCIA_BASE, (uint16_t*)msg, 13);
SCI_writeCharBlockingFIFO(SCIA_BASE, receivedChar1); //发送三次读取到的数据
SCI_writeCharBlockingFIFO(SCIA_BASE, receivedChar2);
SCI_writeCharBlockingFIFO(SCIA_BASE, receivedChar3);
//
// Clear the SCI RXFF interrupt and acknowledge the PIE interrupt.
//
SCI_clearInterruptStatus(SCIA_BASE, SCI_INT_RXFF);
Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP9);
counter++;
}
//
// End of File
//