This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
谢谢你的解答,,我还有一个问题是:如果我的LSPCLK=25Mhz,,BRR=0的话,那么,波特率=25
Mhz/16 =1.5M 左右,,如果LSPCLK等于SYSCLKOUT的话,,波特率也就更大了,,,那么sci串口就真的会以这么大的波特率来发送和接受数据么??我听说串口一般都不会用的这么大,,也就几百Kbit,,主要是和RS323 和RS485 一起用,,速率不能太大,,这是由于RS232和RS485 的限制 还是SCI串口本身的限制呢,,??手册上给的波特率的计算公式只是个理想的么,,实际的波特率没有那么大,,也就几百个K么 ??
thanks!!
谢谢你的解答,,我还有一个问题是:如果我的LSPCLK=25Mhz,,BRR=0的话,那么,波特率=25
Mhz/16 =1.5M 左右,,如果LSPCLK等于SYSCLKOUT的话,,波特率也就更大了,,,那么sci串口就真的会以这么大的波特率来发送和接受数据么??我听说串口一般都不会用的这么大,,也就几百Kbit,,主要是和RS323 和RS485 一起用,,速率不能太大,,这是由于RS232和RS485 的限制 还是SCI串口本身的限制呢,,??手册上给的波特率的计算公式只是个理想的么,,实际的波特率没有那么大,,也就几百个K么 ??
thanks!!
一般串口通信经常使用的波特率是 4800 ~ 115200 bps,可以根据自己的需求进行选择,当然 RS232 和 RS485 等不同的串口通信协议会有各自在通信速率和通信距离方面的限制。
对于 C2000 而言,手册上所给出的波特率计算公式是理想的,实际应用的过程中如果通信速率不是特别快的话一般不会有问题,但是如果设置的通信速率过快可能会因为系统时钟误差等方面的原因导致通信速率产生误差,从而引起串口通信无法正常链接。
建议您先实现 9600 bps,通信成功之后再根据自己的需要适当调整波特率。
嗯 好的 这是我的代码:
#include "DSP280x_Device.h" // DSP280x Headerfile Include File
#include "DSP280x_Examples.h" // DSP280x Examples Include File
// Prototype statements for functions found within this file.
interrupt void sciaRxFifoIsr(void);
void scia_fifo_init(void);
void scia_xmit(int a);
//int SciaRx_Ready(void);
// Global variables
Uint16 ReceivedChar[20]; // Received data for SCI-A
Uint16 loop;
void main(void)
{
Uint16 i;
Uint16 SendChar;
// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the DSP280x_SysCtrl.c file.
InitSysCtrl();
// Step 2. Initalize GPIO:
// This example function is found in the DSP280x_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
// InitGpio();
// Setup only the GP I/O only for SCI-A and SCI-B functionality
// This function is found in DSP280x_Sci.c
InitSciGpio();
// Step 3. Clear all interrupts and initialize PIE vector table:
// Disable CPU interrupts
DINT;
// Initialize PIE control registers to their default state.
// The default state is all PIE interrupts disabled and flags
// are cleared.
// This function is found in the DSP280x_PieCtrl.c file.
InitPieCtrl();
// Disable CPU interrupts and clear all CPU interrupt flags:
IER = 0x0000;
IFR = 0x0000;
// Initialize the PIE vector table with pointers to the shell Interrupt
// Service Routines (ISR).
// This will populate the entire table, even if the interrupt
// is not used in this example. This is useful for debug purposes.
// The shell ISR routines are found in DSP280x_DefaultIsr.c.
// This function is found in DSP280x_PieVect.c.
InitPieVectTable();
// Interrupts that are used in this example are re-mapped to
// ISR functions found within this file.
EALLOW; // This is needed to write to EALLOW protected registers
PieVectTable.SCIRXINTA = &sciaRxFifoIsr;
EDIS; // This is needed to disable write to EALLOW protected registers
// Step 4. Initialize all the Device Peripherals:
// This function is found in DSP280x_InitPeripherals.c
// InitPeripherals(); // Not required for this example
// Enable interrupts required for this example
IER |= M_INT9;
PieCtrlRegs.PIECTRL.bit.ENPIE = 1; // Enable the PIE block
PieCtrlRegs.PIEIER9.bit.INTx1=1; // PIE Group 9, INT1 RXINT
//IER = 0x100; // Enable CPU INT
//EINT;
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM
// Step 5. User specific code, enable interrupts:
scia_fifo_init(); // Init SCI-A
SendChar=0;
loop=0;
// Init send data.
for(i=0;i<20;i++)
{
scia_xmit(SendChar);
//Move to the next character and repeat the test
SendChar++;
// Limit the character to 8-bits
SendChar &= 0x00FF;
}
// Step 6. IDLE loop. Just sit and loop forever (optional):
for(;;);
}
interrupt void sciaRxFifoIsr(void)
{
ReceivedChar[loop] =SciaRegs.SCIRXBUF.all; // Read data
loop++;
SciaRegs.SCIFFRX.bit.RXFFOVRCLR=1; // Clear Overflow flag
SciaRegs.SCIFFRX.bit.RXFFINTCLR=1; // Clear Interrupt flag
PieCtrlRegs.PIEACK.all|=0x100; // Issue PIE ack
}
void scia_fifo_init()
{
SciaRegs.SCICCR.all =0x0007; // 1 stop bit, No loopback
// No parity,8 char bits,
// async mode, idle-line protocol
SciaRegs.SCICTL1.all =0x0003; // enable TX, RX, internal SCICLK,
// Disable RX ERR, SLEEP, TXWAKE
SciaRegs.SCICTL2.bit.TXINTENA =1;
SciaRegs.SCICTL2.bit.RXBKINTENA =1;
SciaRegs.SCIHBAUD = 0x0001; //9600=BAUD
SciaRegs.SCILBAUD = 0x0044;
// SciaRegs.SCICCR.bit.LOOPBKENA =1; // Enable loop back\
SciaRegs.SCIFFTX.all=0xC000;// 0xC028;
SciaRegs.SCIFFRX.all=0x0022;//0x0028;
SciaRegs.SCIFFCT.all=0x00;
SciaRegs.SCICTL1.all =0x0023; // Relinquish SCI from Reset
SciaRegs.SCIFFTX.bit.TXFIFOXRESET=1;
SciaRegs.SCIFFRX.bit.RXFIFORESET=1;
}
// Transmit a character from the SCI'
void scia_xmit(int a)
{
SciaRegs.SCITXBUF=a;
}
谢谢!!
应该是 SCI 模块设置的问题,请将
SciaRegs.SCIFFTX.all=0xC000;// 0xC028;
SciaRegs.SCIFFRX.all=0x0022;//0x0028;
改为:
SciaRegs.SCIFFTX.all |= 0xC000;
SciaRegs.SCIFFRX.all |=0x0028;
在硬件上如此连接没有问题,主要是两个都是3.3V的系统吗,如果是,那问题已经出在软件的初始化,比如波特率是否统一,是否都设奇偶校验位,停止位是统一为1位或者2位,等等,还可以用示波器实时观察RX,及TX上的波形来分析