LPC54628 SPI Master-Slave query

cancel
Showing results for 
Search instead for 
Did you mean: 

LPC54628 SPI Master-Slave query

551 Views
aswinprabhu
Contributor III

Hello,

I'm writing code for interrupt based SPI comm between three boards consisting of LPC54628 in Master-Slave configuration in Keil IDE without using the SDK drivers (I'm trying to directly access and modify target registers while avoiding the use of drivers as much as possible to keep the code simple).

After the master LPC54628 asserts slave-select for one of the slave boards, it is supposed to send an address on MOSI line (0xADDRESS).

The slave LPC54628 configured in interrupt mode should go to ISR when Rx FIFO becomes non-empty (one entry) and check the received byte against its hard-coded address.

If they match, the slave LPC54628 should send two bytes of data (status of some Digital Input pins) to the Master controller.

Query 1:

My understanding about SPI is that when a slave is receiving some data from Master, the slave has to send out some data called DummyData in SDK examples back to the master. Is it correct? If yes, which function in the SDK example (SPI_INTERRUPT_B2B_SLAVE) ensures so? I can only see a function

SPI_SetDummyData(base, (uint8_t)SPI_DUMMYDATA);

being defined in Slave_Init(), but cannot locate the part of the code which sends out the DummyData while a byte is being received from the Master. Can someone help me with this?

Query 2:

This is regarding ISR. When the Rx FIFO becomes non-empty, an interrupt is to be generated which causes the program to loop to ISR for the SPI (Flexcomm3). In SDK examples

SPI_SLAVE_IRQHandler(void)

performs the functions of the ISR which is defined as

#define SPI_SLAVE_IRQHandler FLEXCOMM3_IRQHandler.

My question is this:

When I am writing a code without using the inbuilt SDK drivers (essentially starting from scratch with only the automatically added device files such as LPC54628.h and startup files), how do I tell the IDE (Keil/uVision) what my ISR is? If I just define a function with the name

FLEXCOMM3_IRQHandler

and write the ISR code inside it, will the code work?

Please note: Right now I do not have access to LPC54628 board. Will take a 2-3 weeks for it to reach me. So I'm trying to keep the code ready by the time the boards become available to me.

Thanks in advance.

Labels (1)
0 Kudos
1 Reply

364 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Aswin,

Query 1:

My understanding about SPI is that when a slave is receiving some data from Master, the slave has to send out some data called DummyData in SDK examples back to the master. Is it correct? If yes, which function in the SDK example (SPI_INTERRUPT_B2B_SLAVE) ensures so? I can only see a function

SPI_SetDummyData(base, (uint8_t)SPI_DUMMYDATA);

being defined in Slave_Init(), but cannot locate the part of the code which sends out the DummyData while a byte is being received from the Master. Can someone help me with this?

Answer: For SPI communication, one is master which drive the clock SCK and chip select /CS, another is slave, whose SCK and /CS siganals are driven by master. when the master sends the address you called, while it must receive a data which you call the dummy data. Whether you call it dummy data or not, it is dependent on your application, in other words, if the received data is needed in application.

Query 2:

This is regarding ISR. When the Rx FIFO becomes non-empty, an interrupt is to be generated which causes the program to loop to ISR for the SPI (Flexcomm3). In SDK examples

Answer: after you use MCUXpresso or any tools to create a template project or load an example, the startup_lpcxxx.c is established automatically, it includes the vector table, for example the Flexcomm3 vector name is "FLEXCOMM3_IRQHandler", assume you do not use spi driver in SDK, you can write the ISR like:

void FLEXCOMM9_IRQHandler(void)
{
    static uint32_t index=0;
    //clear interrupt flag

    SPI9->FIFOSTAT|=0x03;
    ..................................


}

But you have to configure the interrupt module NVIC so that interrupt is enabled.

void SPI9InterruptInit(void)
{
    //set priority of SPI9
    NVIC->ISPR[41]=0x00;
    NVIC->ISER[1]|=1<<9;
    NVIC->ICPR[1]|=1<<9;

    __asm("cpsie i");

}

Hope it can help you

BR

Xiangjun rong

0 Kudos