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)){}
/* 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;
I've found this. It should help. http://www.keil.com/download/docs/297.asp Mirek
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 }
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 */ } } }
Did you read this? http://www.keil.com/support/docs/2767.htm
...Yes... it's much clearer now. Thank you. Mirek