Hi everyone,
I'm facing a problem with the interrupt DSPI driver on Kinetis K60, using MQX 3.7 and Codewarrior 10.1.
I'm interfacing a SPI dataflash AT45DB161D. If I use the polled DSPI driver everything works fine, the problem rises only in interrupt mode.
My code is the following:
/* assert CS, send command*/ data[ 0 ] = 0x9F; if( 1 != fwrite( data, 1, 1, com )) { fflush( com ); return FALSE; } /* wait for response */ if(4 != fread( data, 1, 4, com )) { fflush (com); return FALSE; } /* deassert CS */ if (MQX_OK != fflush (com)) { return FALSE; } return TRUE;
With an oscilloscope, I can see 5 clock packets on the SCK line, the 0x9F command byte on the SOUT line at the first clock packet and the 4 data bytes on the SIN line at the other 4 clock packets: the hardware works ok. The problem is that the fread function returns always 0 byte read.
How can I fix this? Must the interrupt DSPI driver be changed due to a bug or my code has to be modified?
Many thanks
Teckna
已解决! 转到解答。
Hello,
the interrupt SPI driver usage is different to the polled one. Functions read/write do not wait for the transmission end, they return immediately after accessing the internal buffer. So you should do this:
/* assert CS, send command*/ data[ 0 ] = 0x9F; if( 1 != fwrite( data, 1, 1, com )) { fflush( com ); return FALSE; } /* wait for response */ result = 0; do { result += fread( data + result, 1, 4 - result, com )) } while (result < 4); /* deassert CS */ if (MQX_OK != fflush (com)) { return FALSE; } return TRUE;
Regards,
PetrM
Hello I have a question how fast work the driver for SPI integrated in MQX with this memory ?
I'm trying to access same memory at 25Mhz SCK baud and I'm wonder if it's fast enough to do the reading and manage the data! Even if my sys clock is 48Mhz ?!?
You use DMA transfer ? What settings you use for DSPI accesing the memory ?
Hello,
the interrupt SPI driver usage is different to the polled one. Functions read/write do not wait for the transmission end, they return immediately after accessing the internal buffer. So you should do this:
/* assert CS, send command*/ data[ 0 ] = 0x9F; if( 1 != fwrite( data, 1, 1, com )) { fflush( com ); return FALSE; } /* wait for response */ result = 0; do { result += fread( data + result, 1, 4 - result, com )) } while (result < 4); /* deassert CS */ if (MQX_OK != fflush (com)) { return FALSE; } return TRUE;
Regards,
PetrM