EFM32片内外设--LEUart抖动误差

继续使用上次的Demo,我们来申明一个LEUart的问题。

硬件准备: TG STK, LEUart0, Tx:PD4, Rx:PD5.  TG STK的20pin扩展口上已经有这两个IO口,分别是12Pin(PD4),14Pin(PD5)。

软件准备:我们简化一下上次的例程,仅仅让LEUart发送0x01.

#include <stdint.h>
#include <stdbool.h>
#include "efm32.h"
#include "efm32_chip.h"
#include "efm32_cmu.h"
#include "efm32_leuart.h"
#include "efm32_gpio.h"

void LEUart_Init(void)
{
    CMU_ClockEnable(cmuClock_HFPER, true);
    CMU_ClockEnable(cmuClock_GPIO, true);
    CMU_ClockEnable(cmuClock_CORELE, true);
   
    CMU_ClockSelectSet(cmuClock_LFB, cmuSelect_LFXO);
    CMU_ClockEnable(cmuClock_LEUART0, true);
   
    /* Defining the LEUART1 initialization data */
    LEUART_Init_TypeDef leuart1Init =
    {
        .enable   = leuartEnable,         /* Activate data reception on LEUn_TX pin. */
        .refFreq  = CMU_ClockFreqGet(cmuClock_LEUART0),/* Inherit the clock frequenzy from the LEUART clock source */
        .baudrate = 9600,                 /* Baudrate = 9600 bps */
        .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(LEUART0);
   
    /* Route LEUART1 TX pin to DMA location 0 */
    LEUART0->ROUTE = LEUART_ROUTE_TXPEN | LEUART_ROUTE_RXPEN | LEUART_ROUTE_LOCATION_LOC0;
   
    LEUART_Init(LEUART0, &Leuart_Init);
   
    /* Enable GPIO for LEUART0.  */
    GPIO_PinModeSet(gpioPortD, 4, gpioModePushPull, 1);
    GPIO_PinModeSet(gpioPortD, 5, gpioModeInputPull, 1);
}

/**************************************************************************//**
 * @brief  Main function
 *****************************************************************************/
int main(void)
{
    /* Chip errata */
    CHIP_Init();
    LEUart_Init();
   
    while(1)
    {
        unsigned long ulDelay = 100000;
        while(ulDelay--);
        LEUART_Tx(LEUART0, 0x01);
    }
}

然后用示波器观察LEUart的输出波形,会发现0,1的宽度是不一样的。例如此例程中LEUart使用外部32kHz的晶振作为时钟源,波特率设置为9600,会发现低电平约为92uS,高电平约为122uS。如下图所示:

这是为什么呢?

原来答案还在于时钟源上面。在Reference manual中会有如下的解释:

Jitter in Transmitted Data:

Internally the LEUART module uses only the positive edges of the 32.768 kHz clock (LFBCLK) for transmission and reception. Transmitted data will thus have jitter equal to the difference between the optimal data set-up location and the closest positive edge on the 32.768 kHz clock. The jitter in on the location data is set up by the transmitter will thus be no more than half a clock period according to the optimal set-up location. The jitter in the period of a single baud output by the transmitter will never be more than one clock period.

简要的概括就是由于时钟源是32768Hz,因此在输出的时候,会有一个时钟周期的误差,即1秒/32768 = 30uS的误差。因此也就能解释上面的波形了,高低电平相差将近30uS。

但是就是因为是这样,因此在操作LEUart的时候,就需要特别注意与LEUart做通讯的设备,最好也是采用晶振作为时钟源。否则容易造成误码率。目前用此例程,在PC端做测试,暂时未发现明显的误码。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值