LPC1788 Uboot SPI driver

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

LPC1788 Uboot SPI driver

406 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by sekil on Tue Oct 23 15:55:03 MST 2012
Please help me write correctly function spi_xfer:

this my code:

int spi_xfer(struct spi_slave *slave, unsigned int bitlen,
const void *dout, void *din, unsigned long flags)
{
unsigned intlen;
u8 tmp;
intret, i;
const uchar *txp = dout;
uchar *rxp = din;

if (bitlen == 0)
/* Finish any previously submitted transfers */
goto out;

if (bitlen % 8) {
/* Errors always terminate an ongoing transfer */
flags |= SPI_XFER_END;
printf("Error lens\n");
goto out;
}

len = bitlen >> 3;
LPC_SSP1->ICR = SSP_ICR_BITMASK;

if (flags & SPI_XFER_BEGIN) spi_cs_activate(slave);
//printf ("Activete CS ok\n");
if (dout)
{//printf ("try send dout\n");
for (i=0; i<len; i++)
{
LPC_SSP1->DR = SSP_DR_BITMASK(txp);
//printf("sends - %x\n",txp);
}
}
if (din)
{
while (LPC_SSP1->SR & SSP_SR_RNE)
{
            tmp = (SSP_DR_BITMASK(LPC_SSP1->DR));
        }
for (i=0; i<len; i++)
{
LPC_SSP1->DR = 0xff;
}
while ( (LPC_SSP1->SR & (SSP_SR_BSY|SSP_SR_RNE)) != SSP_SR_RNE );
tmp = LPC_SSP1->DR; //without this i always get 0xff in first read byte :(((
//printf ("read test = %x\n",tmp);
for (i=0;i<len;i++)
        {
if (LPC_SSP1->SR & SSP_SR_RNE) *rxp++ =    (SSP_DR_BITMASK(LPC_SSP1->DR))& 0xff;
       }
}
if (flags & SPI_XFER_END) spi_cs_deactivate(slave);
return 0;

out:
if (flags & SPI_XFER_END) spi_cs_deactivate(slave);
return 0;
}

This function work, but not normal - i get time out if i write/erase data to at45db321d SPI flash.
P.S. I'm not professional programmer - but I'm learning :)
P.S.S Sory for my English
Labels (1)
0 Kudos
1 Reply

299 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by sekil on Wed Oct 24 13:25:24 MST 2012
Thanks for the help

understand himself

Now i have SPI driver in my Uboot LPC1788

P.S. Bu GA GA :)



0 Kudos