Problem with int DSPI

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Problem with int DSPI

Jump to solution
1,312 Views
Teckna
Contributor V

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

 

0 Kudos
Reply
1 Solution
829 Views
PetrM
Senior Contributor I

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

View solution in original post

0 Kudos
Reply
3 Replies
829 Views
Nana
Contributor II

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 ?

0 Kudos
Reply
830 Views
PetrM
Senior Contributor I

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

0 Kudos
Reply
829 Views
Teckna
Contributor V

Many thanks, it's ok!

 

Teckna

0 Kudos
Reply