Simultaenous SPI/SSP read write

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

Simultaenous SPI/SSP read write

552 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by LearnERR on Fri Oct 18 15:43:51 MST 2013
Hello!
I am very new to lpc11xx. Could someone help me with an example (if it is possible) how to make SSP read/write simultaneous function?
I am interested in manual Chip Select (CS), and I have used SSP_Send( 0, &MCU_Writebyte, 1 ); and SSP_Receive( 0, &MCU_Readbyte, 1 ); but would it give me a simultaneous read/write? I mean would I catch a reply of for the dummy frame for example send via SSP_Send (please see image attached for requirement). This is just a routine for write and read one byte, and I call this routine very often controlling CS as GPIO pin outside of it.
Also how to make a simple delay routine that would wait in the code for 20ms? Should I use sys tick, or timer32?

Is this one ok?

void delay32Ms(uint8_t timer_num, uint32_t delayInMs)
{
  if (timer_num == 0)
  {
    /* setup timer #0 for delay */
    LPC_TMR32B0->TCR = 0x02;/* reset timer */
    LPC_TMR32B0->PR  = 0x00;/* set prescaler to zero */
    LPC_TMR32B0->MR0 = delayInMs * ((SystemCoreClock/(LPC_TMR32B0->PR+1)) / 1000);
    LPC_TMR32B0->IR  = 0xff;/* reset all interrrupts */
    LPC_TMR32B0->MCR = 0x04;/* stop timer on match */
    LPC_TMR32B0->TCR = 0x01;/* start timer */

    /* wait until delay time has elapsed */
    while (LPC_TMR32B0->TCR & 0x01);
  }
  else if (timer_num == 1)
  {
    /* setup timer #1 for delay */
    LPC_TMR32B1->TCR = 0x02;/* reset timer */
    LPC_TMR32B1->PR  = 0x00;/* set prescaler to zero */
    LPC_TMR32B1->MR0 = delayInMs * ((SystemCoreClock/(LPC_TMR32B0->PR+1)) / 1000);
    LPC_TMR32B1->IR  = 0xff;/* reset all interrrupts */
    LPC_TMR32B1->MCR = 0x04;/* stop timer on match */
    LPC_TMR32B1->TCR = 0x01;/* start timer */

    /* wait until delay time has elapsed */
    while (LPC_TMR32B1->TCR & 0x01);
  }
  return;
}

Thank you!!
Uli
Labels (1)
0 Kudos
2 Replies

404 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Thu Oct 31 17:23:23 MST 2013
There's a SSP sample in your Example folder:

...\LPCXpresso_6.1.0_164\lpcxpresso\Examples\NXP\LPC1000\LPC11xx\NXP_LPCXpresso1114-302_2011-02-07.zip\ssp

And Wiki is your friend:


Quote:

Transmissions normally involve two shift registers of some given word size, such as eight bits, one in the master and one in the slave; they are connected in a ring. Data is usually shifted out with the most significant bit first, while shifting a new least significant bit into the same register. After that register has been shifted out, the master and slave have exchanged register values. Then each device takes that value and does something with it, such as writing it to memory. If there is more data to exchange, the shift registers are loaded with new data[1] and the process repeats.



See: http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus

And yes, a simple SSP byte write/read function is just writing a byte and then waiting for a received byte.

Something like:
uint8_t SPI0_wr(uint8_t byte)
{
 uint8_t readback;
#if !USE_CS0
 LPC_GPIO0->DATA &=~(1<<2);
#endif
 LPC_SSP0->DR = byte;
/* Wait until the Busy bit is cleared */
  while ((LPC_SSP0->SR & (SSPSR_BSY|SSPSR_RNE)) != SSPSR_RNE );
  readback = LPC_SSP0->DR;
#if !USE_CS0
 LPC_GPIO0->DATA |=(1<<2);
#endif
 return(readback);
}


0 Kudos

404 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Mesozoic on Thu Oct 31 16:15:01 MST 2013
I would use SysTick. 

Configure it for whatever period you want... say 1 ms updates:
<code>SysTick_Config(SystemCoreClock / 1000);</code>

Then in your SysTick_Handler:
<code>
void SysTick_Handler(void)
{
static uint16_t tickCount  = 0;
tickCount++;

// general service flag up
if (!(tickCount % GEN_SVC_PERIOD_MS))
gServiceFlag ^= GEN_SVC;
}
</code>
0 Kudos