Unable to debug the spi_master example demo code

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Unable to debug the spi_master example demo code

1,205 Views
rewatee_poonia
Contributor I

Hi There

I am debugging the example code of lpc17xx SPI master.

Problem: data is not copying in the SPDR data registor.

lpc17xx_spi_master.PNG

Labels (1)
0 Kudos
4 Replies

931 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello rewatee poonia,

In SPI model of LPC17xx, there is no buffer between the data register and the internal shift register. A write to the
data register goes directly into the internal shift register, so we can not read the send data in SPI Data Register (S0SPDR).

The SPI Data Register (S0SPDR) is used to provide the transmit and receive data bytes, Read data is buffered.
When a transfer is complete, the receive data is transferred to a single byte data buffer, where it is later read. A read of the SPI Data Register returns the value of the read data buffer.

About the detail you also can have a look at User manual of your chip , the SPI part:

pastedImage_1.png


Have a great day,
TIC

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos

931 Views
rewatee_poonia
Contributor I

Hello   Alice_Yang

I have tried the SPI example with Open LPC1768(Master) microcontroller and Arduino Mega 2560(Slave).

problem: The data is not getting at the slave arduino.

I have tried the SPI communication between two arduino mega(MASTER & SLAVE). In that case SPDR is updating. Whatever data i am sending from master, it is getting receive at slave device.

** In case of open LPC1768  it is not working. I am receiving 0 at slave. 

SPI master code (Example code from cmsis library)

I did some changes in spi_master.c

1. mode 0->CPHA  & CPOL =0

      SPI_ConfigStruct.CPHA = SPI_CPHA_FIRST;
      SPI_ConfigStruct.CPOL = SPI_CPOL_HI;

2.    #define SPI_DATABIT_SIZE    8

         /** Max buffer length */
      #define BUFFER_SIZE    1

3. 

         void Buffer_Init(void)
               {
                     uint32_t i;
                     for (i = 0; i < BUFFER_SIZE; i++) {
                     Tx_Buf[i] = i+1;
                     Rx_Buf[i] = 0;
                     }
                  }

Arduino slave code

//SPI SLAVE (ARDUINO)
#include<SPI.h>
#define LEDpin 13
volatile boolean received;
volatile byte Slavereceived,Slavesend;
void setup()

{
Serial.begin(115200);
pinMode(LEDpin,OUTPUT); // Setting pin 7 as OUTPUT
pinMode(MISO,OUTPUT); //Sets MISO as OUTPUT (Have to Send data to Master IN
SPI.beginTransaction(SPISettings(2500000, MSBFIRST, SPI_MODE0));
SPCR |= _BV(SPE); //Turn on SPI in Slave Mode
SPCR |= _BV(SPIE);
received = false;

//SPI.attachInterrupt(); //Interuupt ON is set for SPI commnucation

}

ISR (SPI_STC_vect) //Inerrrput routine function
{
Slavereceived = SPDR; // Value received from master if store in variable slavereceived
received = true; //Sets received as True
}

void loop()

{

if(received) //Logic to SET LED ON OR OFF depending upon the value recerived from master
{
if (Slavereceived==1)
{
digitalWrite(LEDpin,HIGH); //Sets pin 7 as HIGH LED ON
Serial.println("Slave LED ON");
Serial.println(Slavereceived);
}else
{
digitalWrite(LEDpin,LOW); //Sets pin 7 as LOW LED OFF
Serial.println("Slave LED OFF");
Serial.println(Slavereceived);
}
Slavesend = 2;
SPDR = Slavesend; //Sends the  value to master via SPDR
delay(1000);
}
}

0 Kudos

931 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello rewatee ,

First of all , we should confirm  there is right output signal on MOSI of LPC1768,  Please use logic analyzer check it .

0 Kudos

931 Views
rewatee_poonia
Contributor I

HelloAlice_Yang

I have checked. There is no data available on MOSI pin and clock pin.

0 Kudos