Hi Carlos,

The time pattern in my case is:
- CS goes low (active)
- several bytes go afterwards with 20 ms (!, milliseconds) delay between
them
- CS goes hi
- 20 mks (1000 times less than interbyte delay) 
- and pattern repeats

And it is normal case, but after SPI becomes mad and can't transmit single
byte at first, later completely rejecting to send data.

1) Actual code of byte exchange is
static unsigned char spi_raw_rw_byte( int channel, unsigned long spidat1 )

{
        unsigned long status = 0;
        unsigned char result = 0;
        unsigned int spint = 0;  
        unsigned int spiflg = 0;
        unsigned long i = 0;
        int done = 0;

        //printk("SPIDAT1 = %x\n", (unsigned int)spidat1);
        SPI_DBG( "%s (%d): Commiting %x to SPIDAT1\n", __func__, __LINE__,
(unsigned int)spidat1 );
        SPIDAT1 = spidat1;
        msleep(1);
        
        do
        {
                if(++i > 500000)
                        break;  // BUG IS HERE!!! Sometimes code breaks
here, thus indicating unsuccessful data transmission/

                status = SPIBUF;
                spint  = SPIINT;
                spiflg = SPIFLG;
                SPI_DBG( "%X \n", (unsigned int)status );
                
                if(status & (1<<29))
                        continue;
                else
                        done = 1;
        }
        while(done != 1);

        if(done == 0)
                printk("Not done: %d, SPIDAT1 = %x, SPIBUF =%x, SPIINT =%x,
SPIFLG =%x\n", 
                                (unsigned int)i, 
                                (unsigned int)spidat1, 
                                (unsigned int)status, 
                                (unsigned int)spint,
                                (unsigned int)spiflg);

        //SPI_DBG( "done\n" );

        result = (unsigned char)(status & 0xFF);
        //SPI_DBG( "%s (%d): Read back %x\n", __func__, __LINE__, (unsigned
int)result );

        return result;
}

2) Which is used by block write subroutine
channel = spi_device_number(filp);
spidat1 = setup_transaction(channel);

for( i=0 ; i<count ; i++ )
{
        spiByte = pInternalBuffer[i];

        spidat1 &= 0xFFFF0000; // clear data part of register
        spidat1 |=spiByte;     // write data to low part of spidat1 register

        spi_raw_rw_byte(channel, spidat1 );
}

end_transaction(channel);

3) Before proceeding with data exchange I setup channel
unsigned int setup_transaction(int channel)
{
        unsigned long spiByteCommand = 0;

        if( channel )
        {
                SPI_DBG( "%s (%d): USing data format 1 and CS1\n", __func__,
__LINE__ );

                spiByteCommand |= (1<<16) | (1<<24);
        }
        Else
        {
                SPI_DBG( "%s (%d): USing data format 0 and CS 0\n",
__func__,               __LINE__ );
                spiByteCommand |= (2<<16) | (0<<24);
        }

        //// CS delays
        SPIDELAY |= (0xF << 24); // maximum setup time
        SPIDELAY |= (0xF << 16); // maximum hold time

        //SPIDELAY |= (0x5 << 24); // maximum setup time
        //SPIDELAY |= (0x5 << 16); // maximum hold time

        //// CS HOLD setup
        spiByteCommand |= (1 << 28);

        return spiByteCommand;
}

4) After transmission ended, I clean the channel.
unsigned int end_transaction(int channel)
{
        // clear CS & CSHOLD
        SPIDAT1 = (3<<16) | (0 << 28);
        return 0;
}


Important Note: As you can see in spi_raw_rw_byte() code, I read SPIFLG
after SPIBUF. But SPIFLG has overrun flag set contrary to data sheet which
indicates that this flag is cleared by previous SPIBUF read.

5) Is it possible to look at your code? May be I configuring SPI controller
in wrong way.


Regards,
Kirill

-----Original Message-----
From: Carlos Ojea [mailto:[EMAIL PROTECTED] 
Sent: Monday, November 27, 2006 11:42 AM
To: Kirill Sukhonosenko
Cc: [email protected]
Subject: Re: SPI issue

Few weeks ago I did a test transmitting only 100 bytes via SPI but I
didn't see the 'several secods' delay though.
How many bytes do you transmit before you can see the delay?

Regards,
Carlos



_______________________________________________
Davinci-linux-open-source mailing list
[email protected]
http://linux.davincidsp.com/mailman/listinfo/davinci-linux-open-source

Reply via email to