MQX 4.2 SPI CLK doesn't work while reading

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

MQX 4.2 SPI CLK doesn't work while reading

1,184 次查看
SergeMaslenniko
Contributor II

Hello Everyone,

I try to send a command via SPI from MCU (K60) with MQX 4.2 to a slave device and receive a response from it.

the command size is 6 bytes (cmdSize)

the response size is 10 bytes (dataSize)

for this operation I've written the code:

int Result = fwrite(cmd, 1, cmdSize, m_SpiHndl);

   

    if (Result != cmdSize)

   return false;

    Result = fread(data, 1, dataSize, m_SpiHndl);

   fflush(m_SpiHndl);

The problem is that Master MCU CLK works only for fwrite and doesn't work for fread.

It looks like:

2016-04-16_spi.jpg

But in the SPI registers (SPI2_TCR) it's set that 16 bytes were transferred (6 for cmd and 10 for receiving data):

2016-04-16_spi_regs.png

What can I do in order to solve this problem?

Thanks in advance.

Yours faithfully,

Serge

0 项奖励
回复
2 回复数

867 次查看
danielchen
NXP TechSupport
NXP TechSupport

Hi Serge:

These lines also exist in MQX spi demo code

  C:\Freescale\Freescale_MQX_4_2\mqx\examples\spi\spi_memory.c.  In function memory_read_status,

.....

    /* Write instruction */

    result = fwrite (buffer, 1, 1, spifd);

    if (result != 1)

    {

      /* Stop transfer */

        printf ("ERROR (tx)\n");

        return state;

    }

    /* Read memory status */

    result = fread (&state, 1, 1, spifd);

    /* Deactivate CS */

    fflush (spifd);

.....

Can you run this demo well?

Regards

Daniel

0 项奖励
回复

867 次查看
SergeMaslenniko
Contributor II

Hi Daniel,

Thanks for reply.

Recently I've found that it works without my oscilloscope connected.

But the strange thing is:

1. when I call fwrite it's possible to see CLK with oscilloscope

2. when I call fread it's possible to see CLK with oscilloscope

3. when I call fwrite and then fread it is not possible to see CLK with oscilloscope, but without oscilloscope connected it's working well

Perhaps this situation is fault of my oscilloscope (pico 72205A)?

Regards

Serge

0 项奖励
回复