Hi All, the SPI code is working fine with keil simulator and it is going to ISR whenever SPIF is set. but when the same code is loaded to LPC 2294 hardware board it is not working and indefinitely waiting for SPIF bit. In the above case, whenever data is written to S0SPDR interrupt is getting generated (observed on Vector Interrupt Controller) but it is not entering in to ISR and waiting continuously for SPIF.
no activity is detected on the SPI port pins(on logic analyzer )
other interrupts are working fine(timer is checked) but I am understanding why SPI is not working
the code is for interfacing the SPI flash(S70fl256)with LPC2294 MCU and the code is as follows
#define NULL ((void *)0) #define False (0) #define True (1) #define SPIF 1 << 7 #define INTERRUPT_MODE 1 typedef unsigned char BYTE; typedef unsigned short WORD; typedef unsigned long DWORD; typedef unsigned int Bool; #include <LPC22xx.H> #include "spi.h" //all prototypes and variables def void Wait(unsigned long cnt) { while(--cnt); } void Flash_MemWrite(unsigned char *buf,unsigned char *SPI0Add,unsigned char Length) { unsigned char i,Dummy; IOCLR1= 0x00010000; /* to generate #CS1 of SPI flash*/ Wait(5); S0SPDR = 0x06; /* to set write enable latch */ while ( !(S0SPSR & SPIF) ); Dummy = S0SPDR; /* Flush the RxFIFO */ IOSET1= 0x00050000; /* to disable #CS1 and to pull up #Hold of SPI flash */ IOCLR1= 0x00010000; /* to generate #CS1 of SPI flash*/ Wait(5); S0SPDR = 0x02; /*Page Program (PP) command enables memory array data to be programmed*/ while ( !(S0SPSR & SPIF) ); Dummy = S0SPDR; /* Flush the RxFIFO */ /* before sending data 3 bytes of address has to be sent*/ for ( i = 0; i < 3; i++ ) { S0SPDR = *SPI0Add; while ( !(S0SPSR & SPIF) ); Dummy = S0SPDR; /* Flush the RxFIFO */ SPI0Add++; } /* now send the data */ if ( Length == 0 ) { return; } for ( i = 0; i < Length; i++ ) { S0SPDR = *buf; while ( !(S0SPSR & SPIF) ); Dummy = S0SPDR; // Flush the RxFIFO buf++; } Wait(0xF); IOSET1= 0x00050000; // to disable #CS1 and to pull up #Hold of SPI flash } unsigned char *Flash_MemRead(unsigned char *SPI0Add, unsigned char Length) { unsigned char temp[256],Dummy,i; IOCLR1= 0x00010000; /* to generate #CS1 of SPI flash*/ Wait(5); S0SPDR = 0x03; /* read command */ while ( !(S0SPSR & SPIF) ); Dummy = S0SPDR; /* Flush the RxFIFO */ /* before reading data 3 bytes of address has to be sent*/ for (i = 0; i < 3; i++ ) { S0SPDR = *SPI0Add; while ( !(S0SPSR & SPIF) ); Dummy = S0SPDR; /* Flush the RxFIFO */ SPI0Add++; } /* now receive the data */ for ( i = 0; i < Length; i++ ) { S0SPDR = 0xFF; while ( !(S0SPSR & SPIF) ); temp[i]=S0SPDR; } IOSET1= 0x00050000; // to disable #CS1 and to pull up #Hold of SPI flash return temp; } void DefinePins(void) { PINSEL0 = 0x2000155C; PINSEL1 = 0x000002A8; IOSET1 = 0x00050000; // to disable #CS1 and to pull up #Hold /*of SPI flash */ IODIR1 = 0x00050000; } void SPI0Handler (void) __irq { S0SPINT = 0X01; /* clear interrupt flag */ VICVectAddr = 0; /* Acknowledge Interrupt */ } void Spi_Init() { PCONP=0X0D86; /* to enable I2C and SPI ports */ S0SPCR = 0x00A8; //SPI0-active high, master,int enabled,8 bit format and clk //phase is 1 S0SPCCR = 0x0A; #if INTERRUPT_MODE VICIntEnClr =0xFFFFFFFF; /* Disable Interrupts */ VICVectAddr3 = (unsigned long)SPI0Handler; /* set interrupt vector */ VICVectCntl3 = 0x00000020 | 10; VICIntEnable |= 0x00000400; // 10 th bit to enable SPI0 S0SPCR = 0x00A8; //8 bits per transfer,interrupt enable, master //for SPI flash #endif return; } Bool Flash_Test(void) { Bool Mem_flag= True; unsigned char *temp,SPI0Data[256],SPI0Add[3]; unsigned char i; SPI0Add[0]=0x1;//10; SPI0Add[1]=0x2;//0; SPI0Add[2]=0x3;//0; for (i=0 ;i < 2; i++) { SPI0Data[i] =0x0AA; } Flash_MemWrite(SPI0Data,SPI0Add,2); temp = Flash_MemRead(SPI0Add,2); for (i=0 ;i < 2; i++) { if(temp[i]!= 0x0AA) { Mem_flag = False; break; } } if(Mem_flag) { return True; } else { return False; } } int main(void) { Bool flash_flag; DefinePins(); /* Define Pinsel0,1;*/ Spi_Init(); flash_flag=Flash_Test(); while(1); }
please help me and let me know where I am missing.
Thank you in advance