Hi all,
Not a Teensyduino question, but I have a Teensy 4.1 that I'm investigating from the NXP MCUXpresso environment. I have successfully initialised all the GPIOs and UARTS and written code to do so by selecting the IOMUXC and pins and calling their individual "init" functions. I have written standalone code that is not coming from the config toolsets, although I did use these as hints for what needed to be done and tried to do it myself from first principles.
However, I am stuck with the SPI side of things. I have no problem getting it to run for about a second and then turn off. If I brute-force initialisation repeatedly in the main loop, it will produce a string of characters with no problem; Also. I am not using interrupts, just sending data to the transmission register. The code is here for you to refer to. Perhaps some background task is either disabling it or disconnecting the clock. This, of course, does not happen with the Teensyduino Arduino code. Is there a trap for young players here that I'm blissfully unaware of? I'd be very appreciative if there is any light to throw on this.
Regards, Steve
Not a Teensyduino question, but I have a Teensy 4.1 that I'm investigating from the NXP MCUXpresso environment. I have successfully initialised all the GPIOs and UARTS and written code to do so by selecting the IOMUXC and pins and calling their individual "init" functions. I have written standalone code that is not coming from the config toolsets, although I did use these as hints for what needed to be done and tried to do it myself from first principles.
However, I am stuck with the SPI side of things. I have no problem getting it to run for about a second and then turn off. If I brute-force initialisation repeatedly in the main loop, it will produce a string of characters with no problem; Also. I am not using interrupts, just sending data to the transmission register. The code is here for you to refer to. Perhaps some background task is either disabling it or disconnecting the clock. This, of course, does not happen with the Teensyduino Arduino code. Is there a trap for young players here that I'm blissfully unaware of? I'd be very appreciative if there is any light to throw on this.
C:
/*
* Copyright 2016-2025 NXP
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
/**
* @file MIMXRT1062_Project_TryAgain_2.c
* @brief Application entry point.
*/
#include <stdio.h>
#include "board.h"
#include "peripherals.h"
#include "pin_mux.h"
#include "clock_config.h"
#include "fsl_debug_console.h"
#include "fsl_iomuxc.h"
#include "fsl_lpspi.h"
#include "fsl_lpuart.h"
#include "fsl_gpio.h"
#include "DelayUtils.h"
#include "GPIO_config.h"
#include "UART_Config.h"
// @brief Application entry point.
void init_LPSPI4(void);
void set_pins_LPSPI4(void);
//---------------------------------------------------------------------------------------
int main(void)
{
uint16_t i;
/* Init board hardware. */
BOARD_ConfigMPU();
BOARD_InitBootPins();
BOARD_InitBootClocks();
BOARD_InitBootPeripherals();
#ifndef BOARD_INIT_DEBUG_CONSOLE_PERIPHERAL
BOARD_InitDebugConsole();
#endif
i = 0x55;
GPIO_SetTeensyPin(0, kGPIO_DigitalOutput); // my code to manange Teensy pins (54 of them)
set_pins_LPSPI4(); // separate IOMUXC code to assign pins to LPSPI4
init_LPSPI4(); // call to LPSPI_MasterInit()
while (1)
{
GPIO_PinWrite(PIN0, 1); // cro trigger, rising edge.
LPSPI_WriteData(LPSPI4, i); // transmit i
while (!(LPSPI4->SR & LPSPI_SR_TDF_MASK)) ; // wait until data has cleared the transmit register.
// set_pins_LPSPI4();
init_LPSPI4(); // everything stops if I don't call this - or if I transmit more than 16 bytes . It's a time out kind of thing.
GPIO_PinWrite(PIN0, 0); // cro trigger, falling edge.
delay_us(10);
__asm volatile ("nop");
}
return 0;
}
//---------------------------------------------------------------------------------------
void set_pins_LPSPI4()
{
IOMUXC_SetPinMux(IOMUXC_GPIO_B0_00_LPSPI4_PCS0, 1U); // with other defaults intentionally selected e.g. Keeper, pull down etc.
IOMUXC_SetPinMux(IOMUXC_GPIO_B0_01_LPSPI4_SDI, 1U);
IOMUXC_SetPinMux(IOMUXC_GPIO_B0_02_LPSPI4_SDO, 1U);
IOMUXC_SetPinMux(IOMUXC_GPIO_B0_03_LPSPI4_SCK, 1U);
IOMUXC_SetPinConfig(IOMUXC_GPIO_B0_00_LPSPI4_PCS0, 0x10B0U);
IOMUXC_SetPinConfig(IOMUXC_GPIO_B0_01_LPSPI4_SDI, 0x10B0U);
IOMUXC_SetPinConfig(IOMUXC_GPIO_B0_02_LPSPI4_SDO, 0x10B0U);
IOMUXC_SetPinConfig(IOMUXC_GPIO_B0_03_LPSPI4_SCK, 0x10B0U);
}
//---------------------------------------------------------------------------------------
void init_LPSPI4()
{
const lpspi_master_config_t LPSPI4_config =
{ .baudRate = 500000UL, .bitsPerFrame = 8UL, .cpol =
kLPSPI_ClockPolarityActiveHigh, .cpha = kLPSPI_ClockPhaseFirstEdge,
.direction = kLPSPI_MsbFirst, .pcsToSckDelayInNanoSec = 1000UL,
.lastSckToPcsDelayInNanoSec = 1000UL,
.betweenTransferDelayInNanoSec = 1000UL, .whichPcs = kLPSPI_Pcs0,
.pcsActiveHighOrLow = kLPSPI_PcsActiveLow, .pinCfg = kLPSPI_SdiInSdoOut, .pcsFunc = kLPSPI_PcsAsCs,
.dataOutConfig = kLpspiDataOutRetained, .enableInputDelay = false };
LPSPI_MasterInit(LPSPI4, &LPSPI4_config, CLOCK_GetClockRootFreq(kCLOCK_LpspiClkRoot));
}
//---------------------------------------------------------------------------------------
Regards, Steve