Keil™, An ARM® Company

Discussion Forum

LPC21 SPI IRQ

Next Thread | Thread List | Previous Thread Start a Thread | Settings

DetailsMessage
Read-Only
Author
miroslav fiala
Posted
21-Jun-2006 09:13
Toolset
ARM
New! LPC21 SPI IRQ
Hi, I'm sorry for a stupid question but I'm having BIG troubles trying to run SPI using IRQ.

I have SSEL0 pulled up to +3.3V. And SPI works fine when I just poll SPIF like:

S0SPDR=0xXX;

while(!(S0SPSR & 0x80)){}

But when I want to setup IRQ after SPI transfer is done. It don't work. It don't go into ISR at all. I think that after I fill S0SPDR with data to transfer, it should go into ISR after some time right? Or do I have to do something else??? Very strange is that in emulator it works fine! But in real LPC2129 it don't (I've put a breakpoint there using ULINK JTAG (It works fine for USART0 ISR))!!! I setup SPI like this:


/* Configure Pin Connect Block */
PINSEL0=0x5500;

/* Set pclk to same as cclk */
VPBDIV=0x01;

 /* Set to highest speed for SPI at 60 MHz -> 7.5 MHz */
S0SPCCR=0x08;

VICIntSelect &= ~( 0x0400 );
VICIntEnable |= 0x0400;
VICVectAddr2 = ( unsigned long ) vSPI0_ISR;
VICVectCntl2 = 0x02a;


/* Device selected as master, IRQ on */
S0SPCR=0xa0;


Thank You in advance, Mirek
Read-Only
Author
miroslav fiala
Posted
22-Jun-2006 06:50
Toolset
ARM
New! RE: LPC21 SPI IRQ
I've found this. It should help.

http://www.keil.com/download/docs/297.asp

Mirek
Read-Only
Author
miroslav fiala
Posted
22-Jun-2006 08:03
Toolset
ARM
New! RE: LPC21 SPI IRQ
Hey, it does the same...

Directory EX22-SPI
file main.c
it loops on line 34 waiting for 'lock' forever...

030 SPI_write(output_buffer,8);
031 while(lock)
032 {
033 ;
034 }

'lock' is set in ISR, so it apparently don't go into ISR too!!!

It don't seem to be a debugger bug, It don't send anything to SPI (just first byte)...

Don't anyone have a working examle of SPI on LPC2129 with IRQ???

PLEASE!!!

Thanx a lot, Mirek
Read-Only
Author
miroslav fiala
Posted
23-Jun-2006 03:00
Toolset
ARM
New! RE: LPC21 SPI IRQ - Keil ULINK BUG?
Hi folks, it's me again.

I think it must be some kinda ULINK bug.

It works now, but only if I reset device manualy e.g. press reset. If I reset CPU and RUN it from Keil debugger (using Keil ULINK), LPC sends just TWO (?!?!?!) bytes to SPI and then gives it up. But it don't die, LEDs keep blinking. Just IRQ don't work...

Can You explain me this, please?

If You wanna try it yourself, its based on blinky example in c:\Keil\ARM\Examples\Blinky\, but put into one file only:

/******************************************************************************/
/*  This file is part of the uVision/ARM development tools                    */
/*  Copyright KEIL ELEKTRONIK GmbH 2002-2004                                  */
/******************************************************************************/
/*                                                                            */
/*  BLINKY.C:  LED Flasher                                                    */
/*                                                                            */
/******************************************************************************/

#include <LPC21xx.H>                            /* LPC21xx definitions */


long timeval;

void wait (void)  {                             /* wait function */
  unsigned long i;

  i = timeval;
  while ((i + 10) != timeval);                  /* wait 100ms */
}



/* Timer Counter 0 Interrupt executes each 10ms @ 60 MHz CPU Clock */
void tc0 (void) __irq  {
  ++timeval;
  T0IR        = 1;                            // Clear interrupt flag
  VICVectAddr = 0;                            // Acknowledge Interrupt
}


/* Setup the Timer Counter 0 Interrupt */
void init_timer (void) {
  T0MR0 = 149999;                             // 10mSec = 150.000-1 counts
  T0MCR = 3;                                  // Interrupt and Reset on MR0
  T0TCR = 1;                                  // Timer0 Enable
  VICVectAddr0 = (unsigned long)tc0;          // set interrupt vector in 0
  VICVectCntl0 = 0x20 | 4;                    // use it for Timer 0 Interrupt
  VICIntEnable = 0x00000010;                  // Enable Timer0 Interrupt
}


//------------------------------------------------------------------------------------------------------
// SPI0 ISR used to send next char
void vSPI0_ISR( void ) __irq
{

	char cChar;

//	while(1);

	// What caused the interrupt? Flags are cleared by reading the register folowed by accesing SPI data register...
	switch( S0SPSR & 0xc0 )
	{
		cChar=S0SPSR;
		case 0x40:		// ignore for now

			cChar=S0SPDR;
			break;
		case 0x80:		// post another char, if U have one

			cChar=S0SPDR;
		  	S0SPDR=0x42;

			break;
	}


	S0SPINT=0x01;

	// Clear the ISR in the VIC.
	VICVectAddr = 0;


}

int main (void)  {
  unsigned int j;                               /* LED var */


/////////////////////////////////////////////////////////////////////////////////////////
	/* Configure Pin Connect Block */
	PINSEL0=0x5500;

  /* Set pclk to same as cclk */
//	VPBDIV=0x01;

  /* Set to highest speed for SPI at 60 MHz -> 7.5 MHz */
	S0SPCCR=0x08;

			VICIntSelect &= ~( 0x0400 );
			VICIntEnable |= 0x0400;
			VICVectAddr2 = ( unsigned long ) vSPI0_ISR;
			VICVectCntl2 = 0x02a;


	/* Device selected as master */
	S0SPINT=0x01;
	S0SPCR=0xa0;

/////////////////////////////////////////////////////////////////////////////////////////

	IODIR1 = 0xFF0000;                            /* P1.16..23 defined as Outputs */

	init_timer();

  	S0SPDR=0x42;

  	while (1)  {


// 	S0SPDR=0x42;
/* Wait for transfer to be completed */
//	while(!(S0SPSR & 0x80)){}                         /* Loop forever */


    for (j = 0x010000; j < 0x800000; j <<= 1) { /* Blink LED 0,1,2,3,4,5,6 */
      IOSET1 = j;                               /* Turn on LED */
      wait ();                                  /* call wait function */
      IOCLR1 = j;                               /* Turn off LED */
    }
    for (j = 0x800000; j > 0x010000; j >>=1 ) { /* Blink LED 7,6,5,4,3,2,1 */
      IOSET1 = j;                               /* Turn on LED */
      wait ();                                  /* call wait function */
      IOCLR1 = j;                               /* Turn off LED */
    }
  }
}


Have a nice day, Mirek
Read-Only
Author
Reinhard Keil
Posted
23-Jun-2006 04:00
Toolset
ARM
New! RE: LPC21 SPI IRQ - Keil ULINK BUG?
Did you read this?

http://www.keil.com/support/docs/2767.htm
Read-Only
Author
miroslav fiala
Posted
23-Jun-2006 07:16
Toolset
ARM
New! RE: LPC21 SPI IRQ - Keil ULINK BUG?
...Yes... it's much clearer now. Thank you. Mirek

Next Thread | Thread List | Previous Thread Start a Thread | Settings