SPI Transmit data interrupt enable

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
SaGh_4441651
Level 3
Level 3
First like received First like given

I am trying to port a NXP project to a Cypress Project. I have a Transmit data interrupt enable (LPSPI_IER_TDIE_MASK) that I am using in my NXP project. I enable and disable this interrupt and then service the interrupt and do some api calls. I need similar behavior in Cypress PSOC4. Is it possible?

0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

I wish you had written that you are using PSoC 4100S Plus.

Anyway, I tried some, as I do not have access to PSoC 4100S Plus now, I'm just using PSoC Creator.

I Created a project for PSoC 4100S Plus and drag and drop a SPI (SCB) component.

000-SPI_Component.JPG

Then I double clicked the SPI_1 component

There I selected "Master" in the "Mode" pull-down menu.

I also changed the name to "SPI"

001-SPI_Basic.JPG

Then I changed the tab to "SPI Advanced"

There, I changed Interrupt to "External"

And I checked Interrupt sources

TX FIFO empty and RX FIFO not empty.

(you can choose any combination as you like)

002-SPI_Advanced.JPG

Then I added an Interrupt component from System > Interrupt

003-interrupt_added.JPG

I double clicked the component and changed the name to isr_spi

003-isr_spi.JPG

For debug print I added an UART

004-UART_added.JPG

I changed the name of UART_1 to "UART"

005-UART_Basic.JPG

Then select Workspace Explorer > Pins

and select pins for each functions.

Using the pull-down menu in the Port field will show you usable candidate, so choose one from there for your board.

006-assign_pin.JPG

After you finish pin assignment, select "Generate Application"

007a-generate_application.JPG

Now drivers for the selected components were generated in the "Generated Source"

Please take a look at in SPI > SPI.h etc to see what kind of API and defines are provided.

008-Application_generated.JPG

In the SPI.h I could find SPI_ENABLE_INTR_TX() etc.

009-SPI_ENABLE_INTR.JPG

Then main.c seems to be like below.

(Note: I have not tested)

=====================

#include "project.h"

CY_ISR(my_spi_isr)

{

  uint32_t intr_source ;

  intr_source = SPI_GetMasterInterruptSource() ;

  SPI_CLEAR_INTR_MASTER(intr_source) ;

  // check bit of intr_source and decide what to do

}

int main(void)

{

    CyGlobalIntEnable; /* Enable global interrupts. */  

    UART_Start() ;

    isr_spi_StartEx(my_spi_isr) ;

    SPI_Start() ;

    /* Place your initialization/startup code here (e.g. MyInst_Start()) */

    for(;;)

    {

        /* Place your application code here. */

    }

}

=====================

moto

View solution in original post

0 Likes
10 Replies
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

This sample is my SPI_TEST with schematic

000-schematic.JPG

When I open SPIM component by double clicking it, Configure dialog opens.

And in the left bottom, there is a [Datasheet] Button.

002-Datasheet.JPG

When I open the Datasheet, in the left pane, there is Application Programming Interface > Functions.

You can see all SPIM APIs, which includes,

SPIM_EnableTxInt()

SPIM_EnableRxInt()

SPIM_DisableTxInt()

SPIM_DisableRxInt()

SPIM_SetTxInterruptMode()

SPIM_SetRxInterruptMode()

etc.

003-Datasheet2.JPG

Then each function's descriptions are provided

004-INT_1.JPG

005-INT_2.JPG

Note: The reason I started this explanation from schematic is that there is/are difference between SCB SPI and UDB SPI or between versions.

So, IMHO, you should refer to the datasheet of the component you are using.

moto

I am using a PSoC 4100S Plus Device. Why am I not able to find the SPI Master Component in the Component Catalog?

0 Likes
lock attach
Attachments are accessible only for community members.
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

I wish you had written that you are using PSoC 4100S Plus.

Anyway, I tried some, as I do not have access to PSoC 4100S Plus now, I'm just using PSoC Creator.

I Created a project for PSoC 4100S Plus and drag and drop a SPI (SCB) component.

000-SPI_Component.JPG

Then I double clicked the SPI_1 component

There I selected "Master" in the "Mode" pull-down menu.

I also changed the name to "SPI"

001-SPI_Basic.JPG

Then I changed the tab to "SPI Advanced"

There, I changed Interrupt to "External"

And I checked Interrupt sources

TX FIFO empty and RX FIFO not empty.

(you can choose any combination as you like)

002-SPI_Advanced.JPG

Then I added an Interrupt component from System > Interrupt

003-interrupt_added.JPG

I double clicked the component and changed the name to isr_spi

003-isr_spi.JPG

For debug print I added an UART

004-UART_added.JPG

I changed the name of UART_1 to "UART"

005-UART_Basic.JPG

Then select Workspace Explorer > Pins

and select pins for each functions.

Using the pull-down menu in the Port field will show you usable candidate, so choose one from there for your board.

006-assign_pin.JPG

After you finish pin assignment, select "Generate Application"

007a-generate_application.JPG

Now drivers for the selected components were generated in the "Generated Source"

Please take a look at in SPI > SPI.h etc to see what kind of API and defines are provided.

008-Application_generated.JPG

In the SPI.h I could find SPI_ENABLE_INTR_TX() etc.

009-SPI_ENABLE_INTR.JPG

Then main.c seems to be like below.

(Note: I have not tested)

=====================

#include "project.h"

CY_ISR(my_spi_isr)

{

  uint32_t intr_source ;

  intr_source = SPI_GetMasterInterruptSource() ;

  SPI_CLEAR_INTR_MASTER(intr_source) ;

  // check bit of intr_source and decide what to do

}

int main(void)

{

    CyGlobalIntEnable; /* Enable global interrupts. */  

    UART_Start() ;

    isr_spi_StartEx(my_spi_isr) ;

    SPI_Start() ;

    /* Place your initialization/startup code here (e.g. MyInst_Start()) */

    for(;;)

    {

        /* Place your application code here. */

    }

}

=====================

moto

0 Likes

Is there a reason to use External Interrupts vs Internal Interrupts?

0 Likes
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

Usually, we don't need "External Interrupt" if we can go with the APIs provided.

But you asked "Tx Interrupt Enable" in the subject title, so I thought it was mandatory for you.

moto

0 Likes

Even if I just enable Internal Interrupts (and do not enable the External Interrupts), I can still see the SPI_ENABLE_INTR_TX() option in the SPI.h file.

0 Likes
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

Yes, if all you need is enable and disable the interrupt, you don't need the external interrupt.

But if you want to handle/modify the ISR, it is pre-defined in the "Generated source".

And I prefer not to touch the generated source, so I use external interrupt(s).

moto

0 Likes

I plan on using the SCB_SPI_UART_ISR_ExitCallback() function to handle the Interrupt. One more question - what source mask should I be using, if I want the interrupt on SPI_1_INTR_TX_EMPTY? Should I be just using - SPI_1_ENABLE_INTR_TX(SPI_1_INTR_TX_EMPTY); or I also need to enable those in the PSOC Creator?

0 Likes

I tried enabling the SPI_1_INTR_TX_EMPTY interrupt. But now what is happening is that the interrupt is constantly occurring. If I try to clear the interrupt or do anything inside the ISR, I am getting a debugging error with my J Link that says - cannot read register 15 while CPU is running.

0 Likes
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

Have you seen my response above?

In the ISR, I had

==================

  intr_source = SPI_GetMasterInterruptSource() ;

  SPI_CLEAR_INTR_MASTER(intr_source) ;

==================

I think that this intr_source holds all bit(s) caused by interrupt.

So if you clear SPI_1_INTR_TX_EMPTY bit, but there is/are still other bit(s) set,

they are the source of recurrent interrupt(s).

One brain-dead approach is clearing all of them at once, which I used...

==================

  SPI_CLEAR_INTR_MASTER(intr_source) ;

==================

moto

0 Likes