导航: 老古网老古论坛XMOS公共讨论区XMOS开源项目区单片机程序设计嵌入式系统广告区域
→[转帖]如何重置使用/ CS信号的XS1 SPI接口?[liufengzhong]

 *第50938篇: [转帖]如何重置使用/ CS信号的XS1 SPI接口?

  
楼 主:liufengzhong 2014年9月2日23:39
 [转帖]如何重置使用/ CS信号的XS1 SPI接口?
您好所有XCore成员

我面临着一个严重的问题,从XMOS的SPI 1.4.0从组件。它似乎并不当主线程开始采取适当的考虑/ SPICS信号。

主循环开始以下列顺序:

    // Wait until CS is asserted
    nSPICS when pinseq(0):>  void;
    // Wait until SPICLK is in idle state
    SPICLK when pinseq(1):>  void;

端口反序列化使用的是32位,在while()循环缓冲端口的数据,但它永远不会再检查SPICS信号。但SPI要求通信必须重置(输入的数据将被丢弃,该位计数器必须重新启动为0)时/ SPICS再次变高。

如果我设置/ SPICS信号为高电平时,XS1口只是停止服用时钟考虑并停止反序列化。所以,如果我重置SPI主(的XS1是在我的应用程序的奴隶),无需重新设置XS1,而这是接收数据,该数据被移位(例如,如果我重新设置了主,而XS1已经收到5位,我将得到的XS1下一数据之后的下一个时间,而不是32 27个时钟,因为在端口的位计数器保留的最后一个值,而当/ SPICS被设置为1,须重置)

有没有一种方法来强制解串器的一个端口被重置为0时/ SPICS信号变为高电平(数据解串器是不完整的,当然,但至少解串器正确复位)?

我已看的XS1库文件,但是我无法找到任何东西重设缓冲端口

感谢由您的帮助

伯努瓦


回答:

您可以使用clearbuf(空端口P)丢弃在缓冲区中的任何数据;

这将重置串行器,你将同步了!

它的原型在xs1.h - 值得拥有的,通过这个文件的扫描。各种在里面有用的内部函数的高级用法!

/**
 * Clears the buffer used by a port. Any data sampled by the port which has not
 * been input by the processor is discarded. Any data output by the processor which
 * has not been driven by the port is discarded. If the port is in the process
 * of serialising output, it is interrupted immediately.
 * If a pending output would have caused a change in direction of the port then
 * that change of direction does not take place. If the port is driving a value
 * on its pins when clearbuf() is called then it continues to drive
 * the value until an output statement changes the value driven.
 * \param p The port whose buffer is to be cleared.
 */
void clearbuf(void port p);


回复:

谢谢您的回答


不过,我仍然不知道clearbuf()重置位计数器。该文件(或文件头),只是说,它清除缓冲区的内容并停止反序列化过程。

由于这是一件绝对可怕的测试(SPI主控我用的是DSP,其上的SPI在硬件处理,所以无法中断一个字传输一旦开始),我一直在寻找的东西“保证作品“° - )

我想我会需要花费一些时间来实现测试SPI主机与另一个XS1,关于这一点我将中断传输,看看如何在clearbuf()被称为奴隶的反应。
顺便说一句,我在第一篇文章说,在调用这个函数中缺少的SPI 1.4.0组件。一旦在主线程中循环,代码永远不会再检查非华语线路的状态(它不清除缓冲区,如果传输被中止,这不符合SPI规范)

回复2:

如预期的clearbuf()函数不工作的时候...

下面是代码段我加入重置的移位寄存器,当CS变为高:

         // Scan nSPICS while we wait until the data being received
        // If the nSPICS line is released, we clear the buffers
        nSPICS:>  CSState;
        if (CSState==1)
        {
            clearbuf (SPI_SDI);
            clearbuf (SPI_SDO);

            // Immediately reload the output buffer with dummy data
            SPI_SDO  <:0xFFFFFFFF;

            // Wait until CS line goes down again
            nSPICS when pinseq(0):>  void;

            // Prepare next word to transmit (the shift register contains the dummy word for now)
            // Load only new output data if no valid data is already in the variable
            // A call to getNextMIDIByteToTransmit() has been done just before the check of CS line
            // so the variable may already contain something valid
            if (OutputData==0xFFFFFFFF)
                OutputData=bitrev(getNextMIDIByteToTransmit(0));
        }


当CS线变高,我清除缓冲区,等待CS线停机了。但是我所看到的,当启用此部分是移位寄存器重置在任何时刻,所有的串行数据进出都是乱码。我的代码的其余部分是由XMOS(1.4版)提供了SPI的组成部分,而这个工作,只要我不检查CS线(如果我评论的部分前面已经给出)。但是,我需要检查CS线,否则SPI组件不符合以SPI规范(正式,在CS的上升沿将复位并非由XMOS的源代码处理缓冲区)

如果您有什么想法......我快疯了这个问题。

提前感谢


>>>>>>对该主题发表你的看法

本主题贴数1,分页: [第1页]


[上一篇主题]:[转帖]什么是“violates parallel usage rul

[下一篇主题]:[转帖]xcore是否支持多种I2S datelines与普通BCLK /&nb