打印
[STM32F1]

I2S MCLK输出开关对输出的影响

[复制链接]
825|21
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
huangchui|  楼主 | 2021-4-7 21:51 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
正常工作的样机,原来采用8M晶体,I2S2输出给DAC,32k采样率,DMA方式,MCLK采用I2S2_MCK(PC6)正常运行,频率误差跟官方资料一致2.3%,为了提高精度,断开I2S2_MCK,将MCU的MCO(PA8)与DAC的MCLK_IN连接,这个时候出现一个问题,如果MCU的I2S2_MCK设置为输出时(SPI_I2SPR的MCKOE位),也就是MCO给DAC提供主时钟同时I2S2_MCK也输出(悬空不用),样机能正常工作,但是误差精度还是2.3%。

使用特权

评论回复
沙发
chuxh| | 2021-4-7 21:53 | 只看该作者

还有什么现象?能再详细描述下吗?

使用特权

评论回复
板凳
huangchui|  楼主 | 2021-4-7 21:57 | 只看该作者
如果将MCU的I2S2_MCK设置为关闭不用时,LRCK、BCK输出正常,但是DAC会输出一个不受音量控制的单频声音,此单频声音不是正常的数据,DAC的操作状态正常,但MCU传数据不正常。

使用特权

评论回复
地板
supernan| | 2021-4-7 22:00 | 只看该作者
从官方资料看,MCKOE只会打开或者关闭MCU的I2S2_MCK输出与否

使用特权

评论回复
5
huangchui|  楼主 | 2021-4-7 22:09 | 只看该作者
但从结果看,似乎不是,不知道是哪个地方出问题了

使用特权

评论回复
6
heweibig| | 2021-4-7 22:12 | 只看该作者
看手册里关于MCK有这样的描述,你确认下的配置。

使用特权

评论回复
7
wyjie| | 2021-4-7 22:14 | 只看该作者

Procedure
1. Select the I2SDIV[7:0] bits in the SPI_I2SPR register to define the serial clock baud
rate to reach the proper audio sample frequency. The ODD bit in the SPI_I2SPR
register also has to be defined.
2. Select the CKPOL bit to define the steady level for the communication clock. Set the
MCKOE bit in the SPI_I2SPR register if the master clock MCK needs to be provided to
the external DAC/ADC audio component 。

使用特权

评论回复
8
huangchui|  楼主 | 2021-4-7 22:18 | 只看该作者
从手册里看在I2S做主发送数据,MCLK输出与否根据需求,可以设置为关闭如手册上面的表和下面的描述:
I2S master mode
The I2S can be configured in master mode for transmission and reception. This means that
the serial clock is generated on the CK pin as well as the Word Select signal WS. Master
clock (MCK) may be output or not, thanks to the MCKOE bit in the SPI_I2SPR register.

软件里面,这部分是在初始化里做的:
static void I2SOUT_Init(uint32_t AudioFreq)
{
  /* Initialize the hAudioOutI2s Instance parameter */
  hAudioOutI2s.Instance         = I2SOUT;

/* Disable I2S block */
  __HAL_I2S_DISABLE(&hAudioOutI2s);
  
  /* Perform MSP initialization at first function call */
  if(HAL_I2S_GetState(&hAudioOutI2s) == HAL_I2S_STATE_RESET)
  {
    I2SOUT_MspInit();
  }
  
  /* I2SOUT peripheral configuration */
  hAudioOutI2s.Init.AudioFreq   = AudioFreq;
  hAudioOutI2s.Init.CPOL        = I2S_CPOL_LOW;
  hAudioOutI2s.Init.DataFormat  = I2S_DATAFORMAT_16B;
  hAudioOutI2s.Init.MCLKOutput  = I2S_MCLKOUTPUT_DISABLE;  //////////就这个语句,enable是完全正常,disable就不行
//        hAudioOutI2s.Init.MCLKOutput  = I2S_MCLKOUTPUT_ENABLE;
  hAudioOutI2s.Init.Mode        = I2S_MODE_MASTER_TX;
  hAudioOutI2s.Init.Standard    = I2S_STANDARD;
  
  /* Initialize the I2S peripheral with the structure above */
  HAL_I2S_Init(&hAudioOutI2s);

}

ODD DIV配置例程代码里对有没有MCKOE使能已经做了:
   /* Compute the Real divider depending on the MCLK output state, with a floating point */
    if(hi2s->Init.MCLKOutput == I2S_MCLKOUTPUT_ENABLE)
    {
      /* MCLK output is enabled */
      tmp = (uint32_t)(((((i2sclk / 256) * 10) / hi2s->Init.AudioFreq)) + 5);
    }
    else
    {
      /* MCLK output is disabled */
      tmp = (uint32_t)(((((i2sclk / (32 * packetlength)) *10 ) / hi2s->Init.AudioFreq)) + 5);
    }

    /* Remove the flatting point */
    tmp = tmp / 10;  

    /* Check the parity of the divider */
    i2sodd =(uint32_t)(tmp & (uint32_t)1);

    /* Compute the i2sdiv prescaler */
    i2sdiv =(uint32_t)((tmp - i2sodd) / 2);

    /* Get the Mask for the Odd bit (SPI_I2SPR[8]) register */
    i2sodd = (uint32_t) (i2sodd << 8);

从资料了和官方代码里看,均可以直接开关MCLK的

使用特权

评论回复
9
huangchui|  楼主 | 2021-4-7 22:24 | 只看该作者
看来还是BICK和LRCK计算结果跟需求不适配

使用特权

评论回复
10
jiajs| | 2021-4-7 22:26 | 只看该作者
这个操作不知道官方提供例子没。

使用特权

评论回复
11
wyjie| | 2021-4-7 22:28 | 只看该作者
是不是DAC和MCU都是配置成了主模式?

使用特权

评论回复
12
zwll| | 2021-4-7 22:30 | 只看该作者
高采样精度只有STM32F1在从模式才有用。

使用特权

评论回复
13
huangchui|  楼主 | 2021-4-7 22:31 | 只看该作者
通过对比,应该还是因为时钟频率和数据之间协调有点问题,不停修改下面的公式以调整频率:
/* MCLK output is disabled */
      tmp = (uint32_t)(((((i2sclk / (32 * packetlength)) *10 ) / hi2s->Init.AudioFreq)) + 5);
之后通信终于正常了

使用特权

评论回复
14
huangchui|  楼主 | 2021-4-7 22:33 | 只看该作者
但是另一个问题就是精度问题就妥协了

使用特权

评论回复
15
pengf| | 2021-4-7 22:36 | 只看该作者
似乎没有官方文档里写的无MCK输出时候那么小

使用特权

评论回复
16
huangchui|  楼主 | 2021-4-7 22:41 | 只看该作者
预料中的结果,多谢大家啦

使用特权

评论回复
17
wakayi| | 2021-5-6 14:53 | 只看该作者
误差精度有些高

使用特权

评论回复
18
wowu| | 2021-5-6 14:54 | 只看该作者
手册上哪里有写啊

使用特权

评论回复
19
xiaoqizi| | 2021-5-6 14:55 | 只看该作者
是不是开关的接触电阻产生了干扰

使用特权

评论回复
20
木木guainv| | 2021-5-6 14:57 | 只看该作者
这种影响有点大了

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

918

主题

12323

帖子

4

粉丝