主题中讨论的其他器件:C2000WARE、 MOTORWARE
您好!
我设计了一个电机控制板(MCB)、它需要使用转差协议以115.2 kbaud 的速率与 LCD 板进行通信。 通常、LCD 会向 MCB 发送数据请求、或发送命令来更改此参数或该参数(速度、扭矩限制等)、然后发送要更改的值。 这会导致 MCB 必须接收和解释的消息长度发生变化。 因此、接收到的数据将逐字节检查、字符表示消息的开始和结束。 对于在作出和发送答复之前,必须由 MCB 接收的内容,有若干条件。
正在接收和评估数据。 它通常满足上述条件、通常情况下更是如此、并且一个应答被逐字节地放置在一起、因此由 SCIb 进行传输。 我可以通过调试器(通过在适当的位置放置断点)查看所有这种情况。 我可以使用示波器从物理角度查看接收到的消息。
但是、任何要作为应答传输的消息都不会从微控制器发出。 我可以查看 Tx 应该退出的引脚、没有任何内容。 奇怪的是、终端程序(Docklight、Putty、TeraTerm)在 Rx 或 Tx 线路上都没有执行任何操作。
遇到这种情况后、我运行了该程序的一些旧版本、并可以使用终端查看 Rx 和 Tx 上的活动。 但是、这些较旧版本在答复中没有正确的消息格式。 我对消息格式做了一些小的更改、并且突然遇到了一些错误、迫使我在 Properties 对话框中更改编译器和链接器标志(以及对编译器本身的引用)。 我将此属性指定为安装新版本的 CCS、并随附新的编译器版本。 我无法解释他们最初的工作原因、但现在我对该计划的所有版本都在同一条船上、如上所述。
我想不出有什么问题。 但这以前是有效的。 我对此非常满意。
无论如何、下面是我设置该内容的方法(此代码出现在主程序的开头附近):
//Uint16 i_index;
//
// Step 1. Initialize System Control registers, PLL, WatchDog, Clocks to
// default state: This function is found in the F2806x_SysCtrl.c file.
//
InitSysCtrl();
//
// Step 2. Select GPIO for the device or for the specific application:
// This function is found in the F2806x_Gpio.c file.
//
//InitSciGpio(); // @@@ This will change significantly when added to InstaSpin code.
InitScibGpio();
//
// Step 3. Initialize PIE vector table:
// The PIE vector table is initialized with pointers to shell Interrupt
// Service Routines (ISR). The shell routines are found in
// F2806x_DefaultIsr.c. Insert user specific ISR code in the appropriate
// shell ISR routine in the DSP28_DefaultIsr.c file.
//
// Disable and clear all CPU interrupts
//
DINT;
//IER = 0x0000;
//IFR = 0x0000;
//
// Initialize Pie Control Registers To Default State:
// This function is found in the F2806x_PieCtrl.c file.
//
InitPieCtrl(); // Not needed right now. May resurrect.
//
// Initialize the PIE Vector Table To a Known State:
// This function is found in F2806x_PieVect.c.
// This function populates the PIE vector table with pointers
// to the shell ISR functions found in F2806x_DefaultIsr.c.
//
InitPieVectTable();
//
// Enable CPU and PIE interrupts
// This function is found in the F2806x_PieCtrl.c file.
//
EnableInterrupts();
InitArrays(); // Set all array contents to zero.
//
// Step 4. Initialize all the Device Peripherals to a known state:
// This function is found in F2806x_InitPeripherals.c
//
//InitPeripherals(); skip this for now...
// Note: Autobaud lock is not required.
//
// Step 5. User specific functions, Reassign vectors (optional),
// Enable Interrupts:
//
LoopCount = 0;
scib_fifo_init(); // Initialize the SCI FIFO
scib_loop_init(); // Initialize SCI for digital loop back
实际上、中断并不是用来提供一个标志、让我知道何时接收到数据。
下面是 SCIb 的设置(在 InitScibGpio 中):
// InitScibGpio -
//
void
InitScibGpio()
{
EALLOW;
//
// Enable internal pull-up for the selected pins
// Pull-ups can be enabled or disabled disabled by the user.
// This will enable the pullups for the specified pins.
//
GpioCtrlRegs.GPAPUD.bit.GPIO23 = 0; // Enable pull-up for GPIO23 (SCIRXDB)
GpioCtrlRegs.GPAPUD.bit.GPIO22 = 0; // Enable pull-up for GPIO22 (SCITXDB)
//
// Set qualification for selected pins to asynch only
// Inputs are synchronized to SYSCLKOUT by default.
// This will select asynch (no qualification) for the selected pins.
//
GpioCtrlRegs.GPAQSEL2.bit.GPIO23 = 3; // Asynch input GPIO23 (SCIRXDB)
//
// Configure SCI-B pins using GPIO regs
// This specifies which of the possible GPIO pins will be SCI functional
// pins.
//
// Configure GPIO23 for SCIRXDB operation
//
GpioCtrlRegs.GPAMUX2.bit.GPIO23 = 3;
//
// Configure GPIO22 for SCITXDB operation
//
GpioCtrlRegs.GPAMUX2.bit.GPIO22 = 2;
EDIS;
}
下面是 SCIb 的初始化:
void
scib_loop_init()
// *************************************************************************************************
// * Procedure Name: scib_loop_init
// * Purpose: Initialize Serial Comm Interface B.
// * Test 1,SCIB DLB, 8-bit word, baud rate 0x0017 (115.2k), No loopback,
// * default, 1 STOP bit, no parity
// * Tx (GPIO22) is pin 98 on TMS320
// * Rx (GPIO23) is pin 2 on TMS320
// * Date created: 10/01/2021
// * By: DDR
// *************************************************************************************************
{
//
// Note: Clocks were turned on to the SCIB peripheral
// in the InitSysCtrl() function
//
// 1 stop bit, No loopback, No parity,8 char bits, async mode,
// idle-line protocol
ScibRegs.SCICCR.all =0x0007;
//
// enable TX, RX, internal SCICLK, Disable RX ERR, SLEEP, TXWAKE
ScibRegs.SCICTL1.all =0x0003; // Enable SCITXD & SCIRXD. Disable every other feature, for now...
ScibRegs.SCICTL2.all =0x0003; // Enable RXRDY/BRKDT & Enable TXRDY interrupts.
ScibRegs.SCICTL2.bit.TXINTENA = 0; // Disable Transmit Interrupt, for now..
ScibRegs.SCICTL2.bit.RXBKINTENA = 0; //Disable Receiver-buffer break
ScibRegs.SCIHBAUD =0x0000;
ScibRegs.SCILBAUD =0x0017; // Set BAUD at 115.2k (was 0x0017, but not catching the STOP bit)
ScibRegs.SCICCR.bit.LOOPBKENA = 0; // Disable loop back
ScibRegs.SCICTL1.all =0x0023; // Relinquish SCI from Reset
} // End scib_loop_init
下面是 FIFO 初始化:
void
scib_fifo_init()
// *************************************************************************************************
// * Procedure Name: scib_fifo_init
// * Purpose: Initialize FIFOs. See comments below for further explanation.
// * Date created: 10/01/2021
// * By: DDR
// *************************************************************************************************
{
ScibRegs.SCIFFTX.all=0xE040; // Enable Tx FIFO with Enhancements. Empty FIFO. Clear Interrupt Flag.
ScibRegs.SCIFFRX.all=0x2044; // Enable Rx FIFO. Clear FIFO Interrupt.
// Rx Interrupt generated when # bytes >= 1.
ScibRegs.SCIFFCT.all=0x0; // AutoBAUD disabled. BAUD set manually at 115.2k in "scib_loop_init", above. Delay = 0.
} // End scib_fifo_init
希望您可以在上面提供的代码中找到一些内容。 如果您愿意、我可以向您发送整个项目。
谢谢、
Dave
