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:
But in the SPI registers (SPI2_TCR) it's set that 16 bytes were transferred (6 for cmd and 10 for receiving data):
What can I do in order to solve this problem?
Thanks in advance.
Yours faithfully,
Serge
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
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