mke06128vqh4 中的 uart0 朋友们,我有一块用 MKE06Z128VQH4 微控制器设计的板,我在其中使用了多个输出和输入。我使用的是一个 KBI 输入、3 个定时器和一个计数器,所以没有问题 - 我已经进行了配置,它们都能正常工作。 我目前正在研究 UART0 串行端口,我将 USB-TTL 串行适配器连接到 PC,以接收或发送数据。我无法使用 SDK 库发送或接收信息。我使用 MCUXpresso 的配置如图所示: mk1.JPG 针脚: Iotelctronic_0-1764071007390.png 时钟,我有一个 12MHZ 的外部晶体: Iotelctronic_1-1764071084330.png 由于 FLL 出错,我无法设置 FEE 选项,然后我使用 FBELP 进行配置。 在 UART0 中,我使用中断接收和发送轮询进行配置。 Iotelctronic_2-1764071328099.png Iotelctronic_3-1764071349888.png 安装的 sdk 是 Iotelctronic_4-1764071419903.png 我有示例软件包: Iotelctronic_5-1764071510120.png 有了这些例子,我仍然无法让 UART0 正常工作。我需要一些指导 - 几天来我一直在尝试让 UART0 正常工作。 Re: uart0 in mke06128vqh4 你好@Iotelctronic
感谢您的提问。
请首先测试 UART 演示。UART 演示在您那边能正常工作吗?
确保硬件连接正确。连接正确的 TX 和 RX 引脚。
测量 TX/RX 信号。
BR
爱丽丝
Re: uart0 in mke06128vqh4 你好@Iotelctronic
请在不做任何修改的情况下使用演示版。
我已经在我这边进行了测试,没有发现任何问题
BR
爱丽丝 Re: uart0 in mke06128vqh4 嗨,艾丽丝! 我使用轮询对演示进行了测试,但它不起作用。 codigo main.c:
#include "pin_mux.h"
#include "board.h"
#include "fsl_uart.h"
/*******************************************************************************
* Definitions
******************************************************************************/
/* UART instance and clock */
#define DEMO_UART UART1
#define DEMO_UART_CLK_FREQ CLOCK_GetFreq(kCLOCK_BusClk)
/*******************************************************************************
* Prototypes
******************************************************************************/
/*******************************************************************************
* Variables
******************************************************************************/
uint8_t txbuff[] = "Uart polling example\r\nBoard will send back received characters\r\n";
uint8_t rxbuff[20] = {0};
/*******************************************************************************
* Code
******************************************************************************/
/*!
* @brief Main function
*/
int main(void)
{
uint8_t ch;
uart_config_t config;
BOARD_InitBootPins();
BOARD_InitBootClocks();
config.baudRate_Bps = 115200U;
config.parityMode = kUART_ParityDisabled;
config.stopBitCount = kUART_OneStopBit;
//config.txFifoWatermark = 0;
//config.rxFifoWatermark = 1;
config.enableTx = false;
config.enableRx = false;
// UART_GetDefaultConfig(&config);
// config.baudRate_Bps = BOARD_DEBUG_UART_BAUDRATE;
// config.enableTx = true;
//config.enableRx = true;
UART_Init(DEMO_UART, &config, DEMO_UART_CLK_FREQ);
UART_WriteBlocking(DEMO_UART, txbuff, sizeof(txbuff) - 1);
while (1)
{
UART_ReadBlocking(DEMO_UART, &ch, 1);
UART_WriteBlocking(DEMO_UART, &ch, 1);
}
} Re: uart0 in mke06128vqh4 你好@Iotelctronic
1) 关于时钟,请检查 12 MHz 晶振是否正常工作,并验证配置。
2) KE06 不支持 DMA。
谢谢!
BR
爱丽丝 Re: uart0 in mke06128vqh4 你好,我找到问题所在了。我使用的 SDK 示例和其他使用寄存器的项目对我不起作用;它们总是发送错误的数据和字符。我使用的是外置 12 MHz 晶振,使用该晶振似乎无法产生精确的 115200 波特率。不过,我将配置改为 8 MHz,而没有拆焊 12 MHz 晶体,结果运行正常。我最大的问题是:如果我将配置修改为 8 MHz,但不更改 12 MHz 晶体,为什么它还能工作?我展示的代码是我在 .freq 中做的修改= 8000000U.有什么解释吗?我还想问一下,MKE06Z128VQH4 微控制器是否有与 UART 一起使用的 DMA? /***********************************************************************************************************************
* This file was generated by the MCUXpresso Config Tools. Any manual edits made to this file
* will be overwritten if the respective MCUXpresso Config Tools is used to update this file.
**********************************************************************************************************************/
/*
* How to setup clock using clock driver functions:
*
* 1. call CLOCK_SetSimSafeDivs() to set the system clock dividers in SIM to safe value.
*
* 2. If external oscillator is used Call CLOCK_SetXtal0Freq() to set XTAL0 frequency based on board settings and
* call CLOCK_InitOsc0() to init the OSC.
*
* 3. Call CLOCK_BootToXxxMode()/CLOCK_SetXxxMode() to set ICS run at the target mode.
*
* 4. If ICSIRCLK is needed, call CLOCK_SetInternalRefClkConfig() to enable the clock.
*
* 5. call CLOCK_SetSimConfig() to configure the divider in sim.
*/
/* clang-format off */
/* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
!!GlobalInfo
product: Clocks v7.0
processor: MKE06Z128xxx4
package_id: MKE06Z128VLK4
mcu_data: ksdk2_0
processor_version: 9.0.0
* BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/
/* clang-format on */
#include "clock_config.h"
/*******************************************************************************
* Definitions
******************************************************************************/
/*******************************************************************************
* Variables
******************************************************************************/
/* System clock frequency. */
extern uint32_t SystemCoreClock;
/*******************************************************************************
************************ BOARD_InitBootClocks function ************************
******************************************************************************/
void BOARD_InitBootClocks(void)
{
BOARD_BootClockRUN();
}
/*******************************************************************************
********************** Configuration BOARD_BootClockRUN ***********************
******************************************************************************/
/* clang-format off */
/* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
!!Configuration
name: BOARD_BootClockRUN
called_from_default_init: true
outputs:
- {id: Bus_clock.outFreq, value: 20 MHz}
- {id: Core_clock.outFreq, value: 40 MHz}
- {id: Flash_clock.outFreq, value: 20 MHz}
- {id: ICSFF_clock.outFreq, value: 31.25 kHz}
- {id: ICSIR_clock.outFreq, value: 37.5 kHz}
- {id: LPO_clock.outFreq, value: 1 kHz}
- {id: OSCER_clock.outFreq, value: 8 MHz}
- {id: Plat_clock.outFreq, value: 40 MHz}
- {id: System_clock.outFreq, value: 40 MHz}
- {id: Timer_clock.outFreq, value: 20 MHz}
settings:
- {id: ICSMode, value: FEE}
- {id: ICS.BDIV.scale, value: '1', locked: true}
- {id: ICS.IREFS.sel, value: ICS.RDIV}
- {id: ICS.RDIV.scale, value: '256'}
- {id: ICS_C1_IRCLKEN_CFG, value: Enabled}
- {id: OSC_CR_OSCEN_CFG, value: Enabled}
- {id: OSC_CR_OSC_MODE_CFG, value: ModeOscLowPower}
- {id: OSC_CR_RANGE_CFG, value: High}
- {id: OSC_CR_RANGE_RDIV_CFG, value: High}
- {id: SIM.DIV2.scale, value: '2'}
- {id: SIM.DIV3.scale, value: '2', locked: true}
sources:
- {id: OSC.OSC.outFreq, value: 8 MHz, enabled: true}
* BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/
/* clang-format on */
/*******************************************************************************
* Variables for BOARD_BootClockRUN configuration
******************************************************************************/
const ics_config_t icsConfig_BOARD_BootClockRUN =
{
.icsMode = kICS_ModeFEE, /* FEE - FLL Engaged External */
.irClkEnableMode = kICS_IrclkEnable, /* ICSIRCLK enabled, ICSIRCLK disabled in STOP mode */
.bDiv = 0x0U, /* Bus clock divider: divided by 1 */
.rDiv = 0x3U, /* FLL external reference clock divider: divided by 256 */
};
const sim_clock_config_t simConfig_BOARD_BootClockRUN =
{
.outDiv1 = 0x0U, /* DIV1 clock divider: divided by 1 */
.outDiv2 = 0x1U, /* DIV2 clock divider: divided by 2 */
.outDiv3 = 0x1U, /* DIV3 clock divider: divided by 2 */
.busClkPrescaler = 0x0U, /* bus clock optional prescaler */
};
const osc_config_t oscConfig_BOARD_BootClockRUN =
{
.freq = 8000000U, /* Oscillator frequency: 12000000Hz */
.workMode = kOSC_ModeOscLowPower, /* Oscillator low power */
.enableMode = kOSC_Enable, /* Enable external reference clock, disable external reference clock in STOP mode */
};
/*******************************************************************************
* Code for BOARD_BootClockRUN configuration
******************************************************************************/
void BOARD_BootClockRUN(void)
{
/* Set the system clock dividers in SIM to safe value. */
CLOCK_SetSimSafeDivs();
/* Initializes OSC0 according to board configuration. */
CLOCK_InitOsc0(&oscConfig_BOARD_BootClockRUN);
CLOCK_SetXtal0Freq(oscConfig_BOARD_BootClockRUN.freq);
/* Set ICS to FEE mode. */
CLOCK_BootToFeeMode(icsConfig_BOARD_BootClockRUN.bDiv,
icsConfig_BOARD_BootClockRUN.rDiv);
/* Configure the Internal Reference clock (ICSIRCLK). */
CLOCK_SetInternalRefClkConfig(icsConfig_BOARD_BootClockRUN.irClkEnableMode);
/* Set the clock configuration in SIM module. */
CLOCK_SetSimConfig(&simConfig_BOARD_BootClockRUN);
/* Set SystemCoreClock variable. */
SystemCoreClock = BOARD_BOOTCLOCKRUN_CORE_CLOCK;
} Re: uart0 in mke06128vqh4 谢谢,时钟的问题在于晶体焊接的频率是 8MHZ,而不是 12MHZ
記事全体を表示