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);
.
.
}
how to use SPI IRQ Handler?
-
- Posts: 7
- Joined: Wed Mar 27, 2019 10:50 am
- Giovanni
- Site Admin
- Posts: 14455
- Joined: Wed May 27, 2009 8:48 am
- Location: Salerno, Italy
- Has thanked: 1076 times
- Been thanked: 922 times
- Contact:
Re: how to use SPI IRQ Handler?
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
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
-
- Posts: 7
- Joined: Wed Mar 27, 2019 10:50 am
Re: how to use SPI IRQ Handler?
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
-
- 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?
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
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
-
- Posts: 7
- Joined: Wed Mar 27, 2019 10:50 am
Re: how to use SPI IRQ Handler?
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?
-
- 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?
I've used LTC2328, LTC2326 and AD7616 (single channel only). There are minor differences, but mostly I use the same code.
Mike
Mike
-
- Posts: 7
- Joined: Wed Mar 27, 2019 10:50 am
Re: how to use SPI IRQ Handler?
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
Who is online
Users browsing this forum: No registered users and 20 guests