概述
虽然心里一认为LEUart如果使用二分之一的Core clock的话,是可以支持高波特率的。但是一直没有做过测试。呵呵。心里也没底哈。
利用原先的那个demo,将LEUart的时钟源配置为二分之一的core clock,重新测试了一边。证明LEUart是可以工作于高波特率的。
但是注意的是,LEUart的分频系数整数部分为7位,因此最大分频系数为128,如果波特率如果太小的话,反而实现不了了哦。呵呵。否则将core clock预分频。呵呵。
硬件准备: TG STK, LEUart0, Tx:PD4, Rx:PD5. TG STK的20pin扩展口上已经有这两个IO口,分别是12Pin(PD4,Tx),14Pin(PD5,Rx)。
代码:
#include <stdint.h>
#include <stdbool.h>
#include "efm32.h"
#include "em_chip.h"
#include "em_cmu.h"
#include "em_leuart.h"
#include "em_gpio.h"
unsigned char ucString[] = {
"Hello world,This is a test for LEUart from Gecko.rn"
};
#define LINK_UART_TX_PORT gpioPortD
#define LINK_UART_TX_BIT 4
#define LINK_UART_TX_MODE gpioModePushPull
#define LINK_UART_RX_PORT gpioPortD
#define LINK_UART_RX_BIT 5
#define LINK_UART_RX_MODE gpioModeInputPull
#define LINK_CMU_UART cmuClock_LEUART0
#define LINK_UART LEUART0
#define LINK_UART_ROUTE_EN LEUART_ROUTE_TXPEN | LEUART_ROUTE_RXPEN
#define LINK_UART_ROUTE_LOCATION LEUART_ROUTE_LOCATION_LOC0
#define LINK_REF_FREQUENCY CMU_ClockFreqGet(LINK_CMU_UART)
#define LINK_UART_IRQ LEUART0_IRQn
#define LEUART_STATUS LEUART0->STATUS
#define UARTTXC 0x08
void LEUart_Init(void)
{
CMU_ClockEnable(cmuClock_HFPER, true);
CMU_ClockEnable(cmuClock_GPIO, true);
CMU_ClockEnable(cmuClock_CORELE, true);
CMU_ClockSelectSet(cmuClock_LFB, cmuSelect_CORELEDIV2);
CMU_ClockEnable(cmuClock_LEUART0, true);
/* Defining the LEUART1 initialization data */
LEUART_Init_TypeDef leuart1Init =
{
.enable = leuartEnable, /* Activate data reception on LEUn_TX pin. */
.refFreq = LINK_REF_FREQUENCY, /* Inherit the clock frequenzy from the LEUART clock source */
.baudrate = 230400, /* Baudrate */
.databits = leuartDatabits8, /* Each LEUART frame containes 8 databits */
.parity = leuartNoParity, /* No parity bits in use */
.stopbits = leuartStopbits1, /* Setting the number of stop bits in a frame to 2 bitperiods */
};
LEUART_Init_TypeDef Leuart_Init = leuart1Init;
/* Reseting and initializing LEUART1 */
LEUART_Reset(LINK_UART);
/* Route LEUART1 TX pin to DMA location 0 */
LINK_UART->ROUTE = LINK_UART_ROUTE_EN | LINK_UART_ROUTE_LOCATION;
LEUART_Init(LINK_UART, &Leuart_Init);
//LEUART_IntEnable(LINK_UART, LEUART_IEN_RXDATAV);
//NVIC_SetPriority(LINK_UART_IRQ,7);
/* Enable LEUART1 interrupt vector */
//NVIC_EnableIRQ(LINK_UART_IRQ);
/* Enable GPIO for LEUART0. */
GPIO_PinModeSet(LINK_UART_TX_PORT, LINK_UART_TX_BIT, LINK_UART_TX_MODE, 1);
GPIO_PinModeSet(LINK_UART_RX_PORT, LINK_UART_RX_BIT, LINK_UART_RX_MODE, 1);
}
/**************************************************************************//**
* @brief Main function
*****************************************************************************/
int main(void)
{
/* Chip errata */
CHIP_Init();
/* Turning on HFXO to increase frequency accuracy. */
/* Waiting until oscillator is stable */
CMU->OSCENCMD = CMU_OSCENCMD_HFXOEN;
while (!(CMU->STATUS && CMU_STATUS_HFXORDY)) ;
/* Switching the CPU clock source to HFXO */
CMU->CMD = CMU_CMD_HFCLKSEL_HFXO;
LEUart_Init();
while(1)
{
unsigned long ulDelay = 1000000;
while(ulDelay--);
for(unsigned char i = 0; i < 53; i++)
{
LEUART_Tx(LINK_UART, ucString[i]);
}
}
}
最后
以上就是顺心店员为你收集整理的EFM32片内外设--LEUart高波特率测试的全部内容,希望文章能够帮你解决EFM32片内外设--LEUart高波特率测试所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复