Problem with int DSPI

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Problem with int DSPI

ソリューションへジャンプ
1,168件の閲覧回数
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 件の賞賛
返信
1 解決策
685件の閲覧回数
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 件の賞賛
返信
3 返答(返信)
685件の閲覧回数
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 件の賞賛
返信
686件の閲覧回数
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 件の賞賛
返信
685件の閲覧回数
Teckna
Contributor V

Many thanks, it's ok!

 

Teckna

0 件の賞賛
返信