Hello everyone, I am trying to implement spi of arm board mcb2140 and another chip pn544. Basically i want to send a command(sequence of bytes) from arm board to pn544 through spi0 and get some response(sequence of bytes) from pn544, which in turn want to show in the terminal through uart1. My problem is for simulation purpose i assign a dummy byte to S0SPDR which in turn i want uart1 to display it in debug mode .But when i trace S0spdr,it does not show any assigned value in the watch & call stack window.Any guess why??
My code is as follows
/* main.c */ #include <stdio.h> #include <RTL.h> #include <LPC214x.H> /* LPC214x definitions */ int main(void) { SPIInitialize(); init_serial1 (); sendcmd(); while (!(U1LSR & 0x20)); U1THR = readresp(); } /*************************************/ /*Spi.c */ #include <stdio.h> #include <RTL.h> #include <LPC214x.H> /* LPC214x definitions */ void SPIInitialize() { PINSEL0 = 0x00005500; S0SPCCR = 0x08; // this makes the SPI0 rate 1.5Mhz // (PCLK/8 = 12Mhz/8) S0SPCR = 0x24; //SPI Control Register // master mode, active high clock, no IRQ,16 bit transfer } void sendcmd(){ int cmd[2]= 0; int i =0; cmd[i] = 0x84; cmd[i+1]= 0x00; for(i = 0;i < 2;i++) { S0SPDR = cmd[i]; //write data to SPI data register, AA after inv. while(!(S0SPSR & 0x80)){} //wait until SPIF bit is set } IODIR1 = 0x00FF0000; IOSET1 = 0x00040000; } char readresp() { //char a = 0x01; //return a; S0SPDR = 0x02; return S0SPDR; } /******************************************/ /*serial.c*/ #include <LPC21xx.H> /* LPC21xx definitions */ #include <stdio.h> void __irq u1_interrupt (void) __attribute__ ((interrupt)); /* generate interrupt */ void __irq u1_interrupt(void) { char intrpt =0x00; char dummy = 0x00; volatile char stat; stat = U1IIR & 0x0F; IODIR1 = 0x00FF0000; IOCLR1 = 0x00FF0000; while (stat != 1) { switch (stat) { case 0x06: /* Receive Line Status */ dummy = U1LSR; /* Just clear the interrupt source */ break; case 0x04: /* Receive Data Available */ case 0x0C: /* Character Time-Out */ intrpt = U1IIR; U1IIR |= 0x01; /* Clear Interrupt */ intrpt = U1RBR; // clear Rx buffer, and reset interrupt putchar_uart1( intrpt ); IODIR1 = 0x00FF0000; IOSET1 = 0x00020000; break; case 0x02: /* THRE Interrupt */ intrpt = U1IIR; U1IIR |= 0x01; /* Clear Interrupt */ IODIR1 = 0x00FF0000; IOSET1 = 0x00010000; break; case 0x00: /* Modem Interrupt */ dummy = U1MSR; /* Just clear the interrupt source */ break; default: break; } stat = U1IIR & 0x0F; } VICVectAddr = 0x01; /* acknowledge interrupt */ } void init_serial1 (void) { PINSEL0 = 0x00055500; /* Enable RxD1 and TxD1 */ U1LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */ U1DLL = 97; //0x61 /* 9600 Baud Rate @ 15MHz VPB Clock */ U1LCR = 0x03; /* DLAB = 0 */ U1IER = 0x00; /* Disable UART1 Interrupts */ U1FCR = 0x07; /* set up the interrupts */ VICVectAddr0 = (unsigned long) u1_interrupt; /* set interrupt vector */ VICVectCntl0 = 0x20 | 7; // use VICVectAddr1 for UART1 interrupts */ VICIntEnable = 0x00000080; // enable uart1 interrupts */ U1IER = 0x03; /* Enable UART1 RX and THRE Interrupts */ } /*******************************/ /* RETARGET.C: 'Retarget' layer for target-dependent low level functions */ #include <stdio.h> #include <time.h> #include <rt_misc.h> #pragma import(__use_no_semihosting_swi) // disable semihosting #define CR 0x0D #include <lpc21xx.h> // device specific header file int putchar_uart1(int ch) { while (!(U1LSR & 0x20)); return (U1THR = ch); } int putchar_uart0(int ch) { //init_serial0(); while (!(U0LSR & 0x20)); return (U0THR = ch); } int sendchar (int ch) { while (!(U1LSR & 0x20)); return (U1THR = ch); } int getkey (void) { if( PINSEL0 == 0x00050000) { while (!(U1LSR & 0x01)); return (U1RBR); } else if( PINSEL0 == 0x00000005) { while (!(U0LSR & 0x01)); return (U0RBR); } } struct __FILE { int handle; /* Add whatever you need here */ }; FILE __stdout; FILE __stdin; // simplified fputc version that only redirects STDOUT int fputc(int ch, FILE *f) { // redirect STDOUT return (sendchar(ch)); } // simplified fgetc version that only redirects STDIN int fgetc(FILE *f) { // redirect STDIN return (sendchar(getkey())); } int ferror(FILE *f) { /* Your implementation of ferror */ return EOF; } void _ttywrch(int ch) { sendchar (ch); } void _sys_exit(int return_code) { while (1); /* endless loop */ } /*********************/
Any suggestions are appreciated.