Other Parts Discussed in Thread: SYSCONFIG
我根据SysConfig设置了8位数据位,1位停止位无校验位,波特率位2500000,但我发现实际波特率并不符合,在我多次调整后发现实际波特率只有我设置的一半,之后我直接将波特率寄存器设置为0x0001,发现最大波特率只有规格书上最大波特率6.25M的一半3.12M左右
//board.c
void PinMux_init()
{
// GPIO33 -> EN485 Pinmux
GPIO_setPinConfig(GPIO_33_GPIO33);
//
// SCIA -> SCI_A Pinmux
//
GPIO_setMasterCore(SCI_A_SCIRX_GPIO, GPIO_CORE_CPU1);
GPIO_setPinConfig(SCI_A_SCIRX_PIN_CONFIG);
GPIO_setPadConfig(SCI_A_SCIRX_GPIO, GPIO_PIN_TYPE_STD);
GPIO_setQualificationMode(SCI_A_SCIRX_GPIO, GPIO_QUAL_ASYNC);
GPIO_setMasterCore(SCI_A_SCITX_GPIO, GPIO_CORE_CPU1);
GPIO_setPinConfig(SCI_A_SCITX_PIN_CONFIG);
GPIO_setPadConfig(SCI_A_SCITX_GPIO, GPIO_PIN_TYPE_STD);
GPIO_setQualificationMode(SCI_A_SCITX_GPIO, GPIO_QUAL_ASYNC);
}
void SCI_A_init(){
SCI_clearInterruptStatus(SCI_A_BASE, SCI_INT_RXFF | SCI_INT_TXFF | SCI_INT_FE | SCI_INT_OE | SCI_INT_PE | SCI_INT_RXERR | SCI_INT_RXRDY_BRKDT | SCI_INT_TXRDY);
SCI_clearOverflowStatus(SCI_A_BASE);
SCI_resetTxFIFO(SCI_A_BASE);
SCI_resetRxFIFO(SCI_A_BASE);
SCI_resetChannels(SCI_A_BASE);
SCI_setConfig(SCI_A_BASE, 100000000, SCI_A_BAUDRATE, (SCI_CONFIG_WLEN_8|SCI_CONFIG_STOP_ONE|SCI_CONFIG_PAR_NONE));
SCI_disableLoopback(SCI_A_BASE);
SCI_performSoftwareReset(SCI_A_BASE);
SCI_enableInterrupt(SCI_A_BASE, SCI_INT_RXFF);
SCI_setFIFOInterruptLevel(SCI_A_BASE, SCI_FIFO_TX0, SCI_FIFO_RX1);
SCI_enableFIFO(SCI_A_BASE);
SCI_enableModule(SCI_A_BASE);
}
//device.c
void Device_init(void)
{
//
// Disable the watchdog
//
SysCtl_disableWatchdog();
#ifdef CMDTOOL
CMD_init();
#endif
#ifdef _FLASH
#ifndef CMDTOOL
// Copy time critical code and flash setup code to RAM. This includes the
// following functions: InitFlash();
// The RamfuncsLoadStart, RamfuncsLoadSize, and RamfuncsRunStart symbols
// are created by the linker. Refer to the device .cmd file.
memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (size_t)&RamfuncsLoadSize);
#endif
// Call Flash Initialization to setup flash waitstates. This function must
// reside in RAM.
Flash_initModule(FLASH0CTRL_BASE, FLASH0ECC_BASE, DEVICE_FLASH_WAITSTATES);
#endif
// Set up PLL control and clock dividers
SysCtl_setClock(DEVICE_SETCLOCK_CFG);
// Make sure the LSPCLK divider is set to the default (divide by 4)
SysCtl_setLowSpeedClock(SYSCTL_LSPCLK_PRESCALE_1);
ASSERT(SysCtl_getClock(DEVICE_OSCSRC_FREQ) == DEVICE_SYSCLK_FREQ);
ASSERT(SysCtl_getLowSpeedClock(DEVICE_OSCSRC_FREQ) == DEVICE_LSPCLK_FREQ);
#ifndef _FLASH
SysCtl_deviceCal();
#endif
// Turn on all peripherals
Device_enableAllPeripherals();
//Disable DC DC in Analog block
ASysCtl_disableDCDC();
//Configure GPIO in Push Pull,Output Mode
GPIO_setPadConfig(22U, GPIO_PIN_TYPE_STD);
GPIO_setPadConfig(23U, GPIO_PIN_TYPE_STD);
GPIO_setDirectionMode(22U, GPIO_DIR_MODE_OUT);
GPIO_setDirectionMode(23U, GPIO_DIR_MODE_OUT);
// Configure GPIO22 and GPIO23 as digital pins
GPIO_setAnalogMode(22U, GPIO_ANALOG_DISABLED);
GPIO_setAnalogMode(23U, GPIO_ANALOG_DISABLED);
}
//sci.c
void
SCI_setConfig(uint32_t base, uint32_t lspclkHz, uint32_t baud, uint32_t config)
{
uint32_t divider;
//
// Check the arguments.
// Is the required baud rate greater than the maximum rate supported?
ASSERT(SCI_isBaseValid(base));
ASSERT(baud != 0U);
ASSERT((baud * 16U) <= lspclkHz);
SCI_disableModule(base);
divider = ((lspclkHz / (baud * 8U)) - 1U);
// Set the baud rate.
HWREGH(base + SCI_O_HBAUD) = (divider & 0xFF00U) >> 8U;
HWREGH(base + SCI_O_LBAUD) = divider & 0x00FFU;
// Set parity, data length, and number of stop bits.
HWREGH(base + SCI_O_CCR) = ((HWREGH(base + SCI_O_CCR) &
~(SCI_CONFIG_PAR_MASK |
SCI_CONFIG_STOP_MASK |
SCI_CONFIG_WLEN_MASK)) | config);
SCI_enableModule(base);
}