SPI interrupt and auto SSEL configuration

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

SPI interrupt and auto SSEL configuration

430件の閲覧回数
Am-Dev
Contributor I

Hello everyone,

I need your support with my project using the LPC55S06-EVK.

I'm currently working on SPI communication with the FRDM-STBC-AGM01 sensor and i'm struggling on using it in interrupt mode. I state that I've been able to communicate with the sensor in polling mode and the hardware setup isn't changed since that condition.

The main problem is that i can't get the interrupt to be fired again when i finish to send my data to the SPI, regardless which kind of watermark i choose. 

Code below:

スポイラ
#include <stdio.h>
#include "board.h"
#include "peripherals.h"
#include "pin_mux.h"
#include "clock_config.h"
#include "LPC55S06.h"
#include "fsl_debug_console.h"
 
#define BUFFER_SIZE 32
#define SPI_MASTER_IRQ FLEXCOMM8_IRQn
#define SPI_MASTER SPI8
#define LED_GREEN_PIN BOARD_INITLEDSPINS_LED_GREEN_PIN
#define LED_GREEN_PORT BOARD_INITLEDSPINS_LED_GREEN_PORT
 
spi_master_config_t masterConfig;
spi_transfer_t xfer;
 
static volatile bool masterFinished = false;
static volatile bool slaveFinished  = false;
volatile bool isTransferCompleted = false;
volatile bool isMasterOnTransmit  = false;
volatile bool isMasterOnReceive   = false;
volatile bool isFinished = false;
volatile bool machine_state = false;
volatile uint32_t g_systickCounter;
 
uint8_t sendData[BUFFER_SIZE] = {};
uint8_t receiveBuff[BUFFER_SIZE];
uint8_t receivedValue = 0;
 
 
//DELAY FUNCTIONS
void SysTick_Handler(void)
{
if (g_systickCounter != 0U)
{
g_systickCounter--;
}
}
 
void SysTick_DelayTicks(uint32_t n)
{
g_systickCounter = n;
while (g_systickCounter != 0U)
{
}
}
 
void led_pin_toggle() {
GPIO_PinWrite(GPIO, LED_GREEN_PORT, LED_GREEN_PIN, 1);
SysTick_DelayTicks(100);
GPIO_PinWrite(GPIO, LED_GREEN_PORT, LED_GREEN_PIN, 0);
SysTick_DelayTicks(100);
}
 
 
int main(void) {
spi_master_handle_t spiHandle;
BOARD_InitBootPins();
BOARD_InitPins();
BOARD_InitLEDsPins();
BOARD_InitBootClocks();
BOARD_InitBootPeripherals();
GPIO_PinWrite(GPIO, LED_GREEN_PORT, LED_GREEN_PIN, 0);
#ifndef BOARD_INIT_DEBUG_CONSOLE_PERIPHERAL
/* Init FSL debug console. */
BOARD_InitDebugConsole();
#endif
SysTick_Config(SystemCoreClock / 250);
SPI_MasterTransferCreateHandle(FLEXCOMM8_PERIPHERAL, &spiHandle, NULL, NULL);
//configure each 1ms
EnableIRQ(FLEXCOMM8_FLEXCOMM_IRQN);
SPI_EnableInterrupts(FLEXCOMM8_PERIPHERAL, (kSPI_TxLvlIrq));
 
while (1){
if (machine_state) {
sendData[0] = (uint8_t)(0b00001101);
sendData[1] = (uint8_t)(0b00000000);
sendData[2] = (uint8_t)(0b00000000);
// Prepare to send.
xfer.txData = sendData;
xfer.rxData = receiveBuff;
xfer.dataSize = 3;
xfer.configFlags = kSPI_FrameAssert;
GPIO_PinWrite(GPIO, BOARD_INITPINS_CS_MANUAL_PORT, BOARD_INITPINS_CS_MANUAL_PIN, 0);
SysTick_DelayTicks(1);
for (uint8_t i = 0; i < BUFFER_SIZE; i++) {
SPI_WriteData(SPI_MASTER, (uint16_t)sendData[i], kSPI_FrameAssert);
machine_state = false;
led_pin_toggle();
}
SysTick_DelayTicks(1);
GPIO_PinWrite(GPIO, BOARD_INITPINS_CS_MANUAL_PORT, BOARD_INITPINS_CS_MANUAL_PIN, 1);
//SPI_MasterTransferNonBlocking(FLEXCOMM8_PERIPHERAL, &spiHandle, &xfer);
SPI_EnableInterrupts(FLEXCOMM8_PERIPHERAL, (kSPI_TxLvlIrq));
led_pin_toggle();
}
}
return 0 ;
}//MAIN
 
 
/* FLEXCOMM8_IRQn interrupt handler */
void FLEXCOMM8_FLEXCOMM_IRQHANDLER(void) {
SPI_DisableInterrupts(FLEXCOMM8_PERIPHERAL, (kSPI_RxLvlIrq | kSPI_TxLvlIrq));
uint32_t intStatus;
intStatus = SPI_GetStatusFlags(FLEXCOMM8_PERIPHERAL);
//when ready to send data
machine_state = true;
#if defined __CORTEX_M && (__CORTEX_M == 4U)
__DSB();
#endif
}

When in debug mode, i can see the code jumping from the main to the FLEXCOMM8_FLEXCOMM_IRQHANDLER just after the SPI_EnableInterrupts(FLEXCOMM8...) and than moving again into the if (machine_state) but at the GPIO_PinWrite(GPIO, BOARD_INITPINS_CS_MANUAL_PORT, BOARD_INITPINS_CS_MANUAL_PIN, 0);
it goes and get stuck into the callback function.

There is also a function to clear the interrupt registers?

And the secondary issue that i'm facing is that i can't get the "auto SSL" working even if routed using the configurator. It would be great to have the code managing the CS itself. 

ammicrosystems_0-1690473430594.png

 

ammicrosystems_1-1690473460019.png

 

Thanks in advance for your support, have a great day.

0 件の賞賛
返信
1 返信

388件の閲覧回数
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello @Am-Dev 

1) About SPI interrupt, how about firstly test the spi_interrupt demo under SDK? Whether it can work well on your side.

2)" It would be great to have the code managing the CS itself. "

->>If you want to use code control slave select,  You can use a simple GPIO to control.

 

BR

Alice

 

 

0 件の賞賛
返信