RT1052 LPSPI时钟配置

时钟配置

时钟树

LPSPI时钟树

图1 RT052时钟树

使用官方提供的MCUXpresso Config Tools v6工具可以很方便的配置和选择
由上图可知LPSPI由4个时钟源可以选择

分别是:PLL2 PFD2 clock outputPLL2 main clock outputPLL3 PFD0 clock outputPLL3 PFD1 clock output

时钟源

查看rt1052的数据手册
在这里插入图片描述

图2 RT052时钟源数据手册

根据数据手册可知使用库函数CLOCK_SetMux(kCLOCK_LpspiMux, 2);选择的就是PLL2 main clock output 的时钟源

分频系数

在这里插入图片描述

图3 RT052时分频系数数据手册

分频系数很好理解,使用库函数的时候会在设置的值+1, CLOCK_SetDiv(kCLOCK_LpspiDiv, 4);是5分频

注意事项

1、最大时钟

LPSPI最大支持时钟如下图所示:
在这里插入图片描述

图4 源时钟支持最大频率

但是我使用MCUXpresso Config Tools v6工具发现只能配置到120MHz,超过这个波特率有概率会在spi发送函数中卡死
在这里插入图片描述

2、真实的SPI_CLK

The LPSPI functional clock is asynchronous to the bus clock and if it remains enabled in
low power modes then LPSPI can perform SPI bus transfers and low power wakeups in
both master and slave modes. The LPSPI divides the functional clock by a prescaler and
the resulting frequency must be at least two times faster than the SPI external clock
(LPSPI_SCK) frequency.

摘自数据手册,通过库函数代码发现库函数会计算出一个最佳波特率,其值会是设置的波特率的一半,比如正点原子的例程设置的96M但是最后分频下来真实的波特率是48MHz

uint32_t LPSPI_MasterSetBaudRate(LPSPI_Type *base,
                                 uint32_t baudRate_Bps,
                                 uint32_t srcClock_Hz,
                                 uint32_t *tcrPrescaleValue)
{
    ......
    uint32_t prescaler, bestPrescaler;
    uint32_t scaler, bestScaler;
    uint32_t realBaudrate, bestBaudrate;
    uint32_t diff, min_diff;
    uint32_t desiredBaudrate = baudRate_Bps;
            /* calculate the baud rate difference based on the conditional statement
            * that states that the calculated baud rate must not exceed the desired baud rate
            */
            if (desiredBaudrate >= realBaudrate)
            {
                diff = desiredBaudrate - realBaudrate;
                if (min_diff > diff)
                {
                    /* a better match found */
                    min_diff = diff;
                    bestPrescaler = prescaler;
                    bestScaler = scaler;
                    bestBaudrate = realBaudrate;//计算最佳波特率切返回
                }
            }
        }
    }
    ......
    /* return the actual calculated baud rate */
    return bestBaudrate;
}
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

柒妖71

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值