Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[ARM] SPI interfacing using LPC2138

Status
Not open for further replies.

Ravindrakant Jha

Junior Member level 2
Junior Member level 2
Joined
Nov 2, 2014
Messages
24
Helped
1
Reputation
2
Reaction score
1
Trophy points
3
Location
India
Visit site
Activity points
274

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <LPC213X.H>
void delay(int msec)
{
    T0MCR=0X04;  //timer 0 match control register
    T0MR0=3000*msec;   //Timer 0 Match Register
    T0TC=0X00;        //Timer 0 timer counter
    T0TCR=0X01;      //Timer 0 timer control register
    while(T0TC<T0MR0);
                    }
 
void SPI_init() //initialization function
{  
  
   PINSEL0|=1<<8;   //SCK0 for SPI0 p0.5
   PINSEL0&=~(1<<9);
   PINSEL0|=1<<10; //MISO p0.5 Master i/p slave o/p
   PINSEL0&=~(1<<11); 
   PINSEL0|=1<<12;  //MOSI P0.6 Master o/p slave i/p
   PINSEL0&=~(1<<13);
   S0SPCCR = 64; 
   S0SPCR|=(1<<2)|(1<<3)|(1<<4)|(1<<5);//spi enable using microcontroller as master
                                       //spi sends and receive 8 bits of data
                                       //CPHA
                                       //CPOL
}
void SPI_tx(char data)   //SPI transmit function
{                  
  S0SPDR=data;//SPI data register
  while(!(S0SPSR&(0X80))); //SPIF low
}
char SPI_rx ()  //receive function
{
  while(!(S0SPSR&(0X80)));//SPI data receive 
  return(S0SPDR);
}
 void SPI_string(char *str)
 {
   while(*str!='\0')
   SPI_tx(*str);
 }
 
 
int main()
{
 
   IO0DIR |= (1<<7); //Port 0 direction register
    SPI_init();   // SPI initialization
   IO0CLR |= (1<<7); // slave select pin initially low
   SPI_string("Hello");
  while(1)
  {
    
    SPI_rx();
    delay(1);
  
  }
  //IO0SET |= (1<<7);
  
}




In the above code data is received continuously with a constant value 48 in the SPI Debugger.
I just want to know where my code is lagging.
 
Last edited by a moderator:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top