how to use SPI IRQ Handler?

This forum is about you. Feel free to discuss anything is related to embedded and electronics, your awesome projects, your ideas, your announcements, not necessarily related to ChibiOS but to embedded in general. This forum is NOT for support.
laksonobudi
Posts: 7
Joined: Wed Mar 27, 2019 10:50 am

how to use SPI IRQ Handler?

Postby laksonobudi » Fri Jul 26, 2019 4:07 am

hi...i use SPI mode slave in STM32F746.
i want to use SPI IRQ Handler to detect interrupt in RXNE flag, how to do that?
in my case there is hang when run nvicenablevector function...

my SPI setting
================================================================
/* SPI setup and enable.*/
spip->spi->CR1 = 0;
if (spip->config->slave_mode) {
spip->spi->CR1 = spip->config->cr1;
spip->spi->CR2 = SPI_CR2_FRXTH | SPI_CR2_RXNEIE | SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN;
}

/*
Bit 12 FRXTH: FIFO reception threshold
This bit is used to set the threshold of the RXFIFO that triggers an RXNE event
0: RXNE event is generated if the FIFO level is greater than or equal to 1/2 (16-bit)
1: RXNE event is generated if the FIFO level is greater than or equal to 1/4 (8-bit)

Bit 6 RXNEIE: RX buffer not empty interrupt enable
0: RXNE interrupt masked
1: RXNE interrupt not masked. Used to generate an interrupt request when the RXNE flag is
set.
*/
================================================================

my code
================================================================
/*
* The reference variable must be initially set to NULL.
*/
thread_reference_t spi_thread_ref = NULL;

//Table 44. STM32F75xxx and STM32F74xxx vector table
#define SPI2_IRQ VectorD0

/*
* ISR serving the SPI RX FIFO interrupt.
*/
CH_IRQ_HANDLER(SPI2_IRQ) {
CH_IRQ_PROLOGUE();
chprintf(chp,"RUN...\r\n");

if ((SPI2->SR & SPI_SR_RXNE) != 0) {

/* Entering I-Locked state and resuming the thread, if suspended.*/
chSysLockFromISR();
chThdResumeI(&uart_thread_ref, MSG_OK);
chprintf(chp,"DETECT...\r\n");
chSysUnlockFromISR();

/* Resetting interrupt source.*/
SPI2->SR &= ~SPI_SR_RXNE;
}
CH_IRQ_EPILOGUE();
}

int main(){
.
.
nvicEnableVector(SPI2_IRQn,STM32_SPI_SPI2_IRQ_PRIORITY);
.
.
}

laksonobudi
Posts: 7
Joined: Wed Mar 27, 2019 10:50 am

Re: how to use SPI IRQ Handler?

Postby laksonobudi » Fri Jul 26, 2019 12:01 pm

anyone could help will apreciate...

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: how to use SPI IRQ Handler?

Postby Giovanni » Fri Jul 26, 2019 8:47 pm

Hi,

ChibiOS SPI driver does not support slave mode, so cannot comment on your changes.

One possible problem is chprintf() used in an ISR, depending on what you use as output stream you cannot do that.

Giovanni

laksonobudi
Posts: 7
Joined: Wed Mar 27, 2019 10:50 am

Re: how to use SPI IRQ Handler?

Postby laksonobudi » Mon Jul 29, 2019 2:26 am

Giovanni wrote:Hi,

ChibiOS SPI driver does not support slave mode, so cannot comment on your changes.

One possible problem is chprintf() used in an ISR, depending on what you use as output stream you cannot do that.

Giovanni


why it doesn't suport?
i try directly read spi interface in register level code, not use spi driver in chibios. and i have comment out chprintf and change it to GPIO set, it still hang when activate nvic... :(
another thing that i do in my code is i use timer for generate SCLK for stm32 & ADC external, because in my case i try communicate with high speed ADC external, if i disable timer it not hang, but i need timer for generate SCLK & SPI RXNE interrupt when data recieved

mikeprotts
Posts: 166
Joined: Wed Jan 09, 2019 12:37 pm
Has thanked: 19 times
Been thanked: 31 times

Re: how to use SPI IRQ Handler?

Postby mikeprotts » Mon Jul 29, 2019 2:22 pm

I use STM32 in master mode, with pwm to generate CONVST to an SPI attached ADC. This gives a regular trigger to the ADC.

I am then using either the trigger off BUSY or the callback from the pwm (with a tight wait loop until BUSY is off) to resume a thread. The reason for the pwm & wait loop is to reduce jitter, but I suspect I'll work out a better way.

The thread processes the data with spiPolledExchange()

I'm able to process at about 150ksps with a STM32F4.

If you can't switch to master mode, then I think you'll have to use the interactive debugger, setting breakpoints so you'll get control within the IRQ code (setting a few GPIO pins to narrow down the area of code helps). It's possible that when you enable the vector, it's immediately driven and that takes control away earlier than you expect, which might mean the resume running before the other thread has suspended.

Mike

laksonobudi
Posts: 7
Joined: Wed Mar 27, 2019 10:50 am

Re: how to use SPI IRQ Handler?

Postby laksonobudi » Wed Aug 14, 2019 3:51 am

mikeprotts wrote:I use STM32 in master mode, with pwm to generate CONVST to an SPI attached ADC. This gives a regular trigger to the ADC.

I am then using either the trigger off BUSY or the callback from the pwm (with a tight wait loop until BUSY is off) to resume a thread. The reason for the pwm & wait loop is to reduce jitter, but I suspect I'll work out a better way.

The thread processes the data with spiPolledExchange()

I'm able to process at about 150ksps with a STM32F4.

If you can't switch to master mode, then I think you'll have to use the interactive debugger, setting breakpoints so you'll get control within the IRQ code (setting a few GPIO pins to narrow down the area of code helps). It's possible that when you enable the vector, it's immediately driven and that takes control away earlier than you expect, which might mean the resume running before the other thread has suspended.

Mike


what ADC type that u use?

mikeprotts
Posts: 166
Joined: Wed Jan 09, 2019 12:37 pm
Has thanked: 19 times
Been thanked: 31 times

Re: how to use SPI IRQ Handler?

Postby mikeprotts » Wed Aug 14, 2019 1:11 pm

I've used LTC2328, LTC2326 and AD7616 (single channel only). There are minor differences, but mostly I use the same code.

Mike

laksonobudi
Posts: 7
Joined: Wed Mar 27, 2019 10:50 am

Re: how to use SPI IRQ Handler?

Postby laksonobudi » Thu Aug 15, 2019 5:10 am

mikeprotts wrote:I've used LTC2328, LTC2326 and AD7616 (single channel only). There are minor differences, but mostly I use the same code.

Mike


ok, thanks for ur information , now i can aquire data 1 chanel ADC external using SPI DMA interrupt max in 40Ksps because i use 32 bit SPI communication, but now i have problem when use it in UGFX, the interrupt now show up :cry:


Return to “User Projects”

Who is online

Users browsing this forum: No registered users and 4 guests