Problem with int DSPI

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

Problem with int DSPI

跳至解决方案
1,176 次查看
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 解答
693 次查看
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 回复数
693 次查看
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 项奖励
回复
694 次查看
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 项奖励
回复
693 次查看
Teckna
Contributor V

Many thanks, it's ok!

 

Teckna

0 项奖励
回复