Spi + lpc1343

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

Spi + lpc1343

892 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by bobi-one on Wed Apr 27 14:05:19 MST 2011
I am interfacing my touch screen controller via SPI but apparently I am not doing it the right way. I've managed to send words  and get the response but the way i have the response is bothering me. The touch controller is able to send 8 or 12bit responses.
Can someone suggest a way to catch the incomming data into one 16bit variable. (I think i need to catch 2 bytes )
Don't judge me, I am often confusing myself when using  pointers + arrays :)
0 Kudos
Reply
9 Replies

796 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by bobi-one on Fri Apr 29 11:24:49 MST 2011

Quote: larryvc
Are you asking if you can just have one receive() routine?  If so, pass a value to assign to LPC_SSP->DR. Like this:

void SSP_Receive( uint8_t *buf, uint32_t Length, uint8_t value)

LPC_SSP->DR = value;


Yes this is always an  option  :) , but I am trying  to understand  the problem in debt.
After transferring this code which was running fine on the lpcxpresso  on the Miniscule board the only working SPI peripheral was the sd card  and no touch  data (without modifying the  code  ) and  noticed, when touching with finger the MOSI track, touch data was pouring in . Thats why I  soldered  pull down resistor to it, till I find why the board is making this monkey business.(When lpc link is attached is working fine without the resistor)
And now I realized: never start writing long long code, if you don't know the basics ":D
0 Kudos
Reply

796 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by larryvc on Thu Apr 28 12:44:13 MST 2011

Quote: bobi-one
The second receive is used for my sd card ( it worked this way), Which of the two must i use and modify something other in my code/configuration in order to use  only one function properly.



Are you asking if you can just have one receive() routine?  If so, pass a value to assign to LPC_SSP->DR. Like this:

void SSP_Receive( uint8_t *buf, uint32_t Length, uint8_t value)

LPC_SSP->DR = value;
0 Kudos
Reply

796 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Thu Apr 28 09:46:42 MST 2011
Since SPI is shifting data from master (via MOSI) through slave back to master (via MISO) again, your marked line is just writing to SPI data register and therefore initiating this process.

Usually this is done with:
[INDENT] LPC_SSP->DR = 0xFF;
[/INDENT]but other values should work also.

MISO and MOSI don't need pull-ups.
0 Kudos
Reply

796 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by bobi-one on Thu Apr 28 06:15:14 MST 2011
void SSP_Receive( uint8_t *buf, uint32_t Length )
{
  uint32_t i;

  for ( i = 0; i < Length; i++ )
  {

[COLOR=Orange]LPC_SSP->DR = 0x00;[/COLOR] // MDC // Wait until the Busy bit is cleared */
while ( (LPC_SSP->SR & (SSPSR_BSY|SSPSR_RNE)) != SSPSR_RNE );
//while ( !(LPC_SSP->SR & SSPSR_RNE) );
*buf = LPC_SSP->DR;
buf++;

  }
  return;
}

void SSP_Receive2( uint8_t *buf, uint32_t Length )
{
  uint32_t i;

  for ( i = 0; i < Length; i++ )
  {

[COLOR=Red]LPC_SSP->DR = 0xFF;[/COLOR] // MDC // Wait until the Busy bit is cleared */
while ( (LPC_SSP->SR & (SSPSR_BSY|SSPSR_RNE)) != SSPSR_RNE );
//while ( !(LPC_SSP->SR & SSPSR_RNE) );
*buf = LPC_SSP->DR;
buf++;

  }
  return;
}


The second receive is used for my sd card ( it worked this way), Which of the two must i use and modify something other in my code/configuration in order to use  only one function properly. (and do i need some pull up / pull down resistor for MISO in the scenario when the lpc link is not connected?)
0 Kudos
Reply

796 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Thu Apr 28 01:08:45 MST 2011

Quote: bobi-one

    [COLOR=Red]*x=((dest_addr[0]<<5)|(dest_addr[1]>>3));[/COLOR]

The last line is  the one  I am having doubts is it working properly in both modes.



Should work if x is a pointer.
0 Kudos
Reply

796 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by bobi-one on Thu Apr 28 00:58:22 MST 2011
Zero, Thanks for the code.
Most of the time I search for solutions in google, but this time i am trying to  understand it from scratch.

 src_addr[0] = 0xD0;// x
dest_addr[0]=0;
dest_addr[1]=0;

           SSP_Send( (uint8_t *)src_addr, 1 );
   SSP_Receive( (uint8_t *)dest_addr, 2 );


[COLOR=Red]*x=(((dest_addr[0]<<5)|(dest_addr[1]>>3)));[/COLOR]

The last line is  the one  I am having doubts is it working properly in both modes.
0 Kudos
Reply

796 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Wed Apr 27 15:56:35 MST 2011
A little support from Bangalore :)

LPC1768 & ADS7846 Sample Code Download:

http://coineltech.com/shop/product_info.php/products_id/33
0 Kudos
Reply

796 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by larryvc on Wed Apr 27 14:46:45 MST 2011

Quote: bobi-one

Don't judge me, I am often confusing myself when using  pointers + arrays :)



bobi-one,

Do not feel like you are the only one confused when using pointers, arrays, and let's add structures to the list.  These are the most common to have difficulty with and are the biggest pitfalls when using C.  Maybe we should all switch to ADA.:)

Regards,
Larry
0 Kudos
Reply

796 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by NXP_Europe on Wed Apr 27 14:30:46 MST 2011
Hello bobi-one,

did you look at the 'Microwire frame format' ... see User Manual UM10375 chapter SSP.
The 'SI-format' is adjustable. The 'SO-format' is 8 bits.
0 Kudos
Reply