dsp28035的sci echo back怎么和电脑通讯
1个回答
展开全部
是可以的,下面是配置:
void linSciInit() { // 这里把 LIN 当 SCI 用。
//Allow write to protected registers
EALLOW;
LinaRegs.SCIGCR0.bit.RESET = 0; // Into reset
LinaRegs.SCIGCR0.bit.RESET = 1; // Out of reset
LinaRegs.SCIGCR1.bit.SWnRST = 0; // Into software reset
//SCI Configurations
LinaRegs.SCIGCR1.bit.COMMMODE = 0; // Idle-Line Mode
LinaRegs.SCIGCR1.bit.TIMINGMODE = 1; // Asynchronous Timing
LinaRegs.SCIGCR1.bit.PARITYENA = 0; // No Parity Check
LinaRegs.SCIGCR1.bit.PARITY = 0; // Odd Parity
LinaRegs.SCIGCR1.bit.STOP = 0; // One Stop Bit
LinaRegs.SCIGCR1.bit.CLK_MASTER = 1; // Enable SCI Clock
LinaRegs.SCIGCR1.bit.LINMODE = 0; // SCI Mode
LinaRegs.SCIGCR1.bit.SLEEP = 0; // Ensure Out of Sleep
LinaRegs.SCIGCR1.bit.MBUFMODE = 0; /吵亩/ none Buffer Mode
LinaRegs.SCIGCR1.bit.LOOPBACK = 0; // External Loopback
LinaRegs.SCIGCR1.bit.CONT = 1; // Continue on Suspend in Emulation Mode
LinaRegs.SCIGCR1.bit.RXENA = 1; // Enable RX
LinaRegs.SCIGCR1.bit.TXENA = 1; // Enable TX
//Ensure IODFT is disabled
LinaRegs.IODFTCTRL.bit.IODFTENA = 0x0;
//Set transmission length )
LinaRegs.SCIFORMAT.bit.CHAR = 7; // Eight bits
LinaRegs.SCIFORMAT.bit.LENGTH = 0; // 1 byte
//Set baudrate
LinaRegs.BRSR.bit.SCI_LIN_PSL = 194; // Baud = 9600hz
LinaRegs.BRSR.bit.M = 0; // 官方说的是这个值为 5,但实升运森测 0 比 5 要稳定。
// Enable interrupts
LinaRegs.SCISETINT.bit.SETRXINT = 1; // Enable RX interrupt
// LinaRegs.SCISETINT.bit.SETTXINT = 1; // Enable TX interrupt,要发送的时候再打开。
//Set interrupt priority
LinaRegs.SCICLEARINTLVL.all = 0xFFFFFFFF; // Set Int level of all interrupts to LVL 0
LinaRegs.SCIGCR1.bit.SWnRST = 1; // bring out of software reset
// Disable write to protected registers
EDIS;
}
注意,这里配置为 9600,测试时最大只能到 19200,再高就悄和会不稳定,原因未知。
配套 ISR:
interrupt void linaLevel0ISR(void) {
//Read-clear the interrupt vector
// Uint16 i;
LinL0IntVect = LinaRegs.SCIINTVECT0.all;
//RXINT
if (LinL0IntVect == 11) { //RXVect
com_rx = LinaRegs.SCIRD & 0xff; // Read data
if (cRxCounter < 28) {
cRxBuffer[cRxCounter++] = com_rx;
}
} else if (LinL0IntVect == 12) { //TXVect
if (txindex < tx_sum) //发1个
LinaRegs.SCITD = cTxBuffer[txindex++];
else { //发完了。
EALLOW;
//timer_local
LinaRegs.SCICLEARINT.all = 0x000100; // disable TX interrupt
LinaRegs.SCISETINT.bit.SETRXINT = 1; // enable RX interrupt
EDIS;
}
} else { //Other Interrupt
//There should not be other interrupts
linSciInit();
}
//Acknowledge the PIE to be able to receive more interrupts
PieCtrlRegs.PIEACK.all = PIEACK_GROUP9;
}
void linSciInit() { // 这里把 LIN 当 SCI 用。
//Allow write to protected registers
EALLOW;
LinaRegs.SCIGCR0.bit.RESET = 0; // Into reset
LinaRegs.SCIGCR0.bit.RESET = 1; // Out of reset
LinaRegs.SCIGCR1.bit.SWnRST = 0; // Into software reset
//SCI Configurations
LinaRegs.SCIGCR1.bit.COMMMODE = 0; // Idle-Line Mode
LinaRegs.SCIGCR1.bit.TIMINGMODE = 1; // Asynchronous Timing
LinaRegs.SCIGCR1.bit.PARITYENA = 0; // No Parity Check
LinaRegs.SCIGCR1.bit.PARITY = 0; // Odd Parity
LinaRegs.SCIGCR1.bit.STOP = 0; // One Stop Bit
LinaRegs.SCIGCR1.bit.CLK_MASTER = 1; // Enable SCI Clock
LinaRegs.SCIGCR1.bit.LINMODE = 0; // SCI Mode
LinaRegs.SCIGCR1.bit.SLEEP = 0; // Ensure Out of Sleep
LinaRegs.SCIGCR1.bit.MBUFMODE = 0; /吵亩/ none Buffer Mode
LinaRegs.SCIGCR1.bit.LOOPBACK = 0; // External Loopback
LinaRegs.SCIGCR1.bit.CONT = 1; // Continue on Suspend in Emulation Mode
LinaRegs.SCIGCR1.bit.RXENA = 1; // Enable RX
LinaRegs.SCIGCR1.bit.TXENA = 1; // Enable TX
//Ensure IODFT is disabled
LinaRegs.IODFTCTRL.bit.IODFTENA = 0x0;
//Set transmission length )
LinaRegs.SCIFORMAT.bit.CHAR = 7; // Eight bits
LinaRegs.SCIFORMAT.bit.LENGTH = 0; // 1 byte
//Set baudrate
LinaRegs.BRSR.bit.SCI_LIN_PSL = 194; // Baud = 9600hz
LinaRegs.BRSR.bit.M = 0; // 官方说的是这个值为 5,但实升运森测 0 比 5 要稳定。
// Enable interrupts
LinaRegs.SCISETINT.bit.SETRXINT = 1; // Enable RX interrupt
// LinaRegs.SCISETINT.bit.SETTXINT = 1; // Enable TX interrupt,要发送的时候再打开。
//Set interrupt priority
LinaRegs.SCICLEARINTLVL.all = 0xFFFFFFFF; // Set Int level of all interrupts to LVL 0
LinaRegs.SCIGCR1.bit.SWnRST = 1; // bring out of software reset
// Disable write to protected registers
EDIS;
}
注意,这里配置为 9600,测试时最大只能到 19200,再高就悄和会不稳定,原因未知。
配套 ISR:
interrupt void linaLevel0ISR(void) {
//Read-clear the interrupt vector
// Uint16 i;
LinL0IntVect = LinaRegs.SCIINTVECT0.all;
//RXINT
if (LinL0IntVect == 11) { //RXVect
com_rx = LinaRegs.SCIRD & 0xff; // Read data
if (cRxCounter < 28) {
cRxBuffer[cRxCounter++] = com_rx;
}
} else if (LinL0IntVect == 12) { //TXVect
if (txindex < tx_sum) //发1个
LinaRegs.SCITD = cTxBuffer[txindex++];
else { //发完了。
EALLOW;
//timer_local
LinaRegs.SCICLEARINT.all = 0x000100; // disable TX interrupt
LinaRegs.SCISETINT.bit.SETRXINT = 1; // enable RX interrupt
EDIS;
}
} else { //Other Interrupt
//There should not be other interrupts
linSciInit();
}
//Acknowledge the PIE to be able to receive more interrupts
PieCtrlRegs.PIEACK.all = PIEACK_GROUP9;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询