i tried with diffrent baudrate but still its not change if changes it less than 1mhz only
LPSPI4_CLK_ROOT 24mhz
#include <stdio.h>
#include "board.h"
#include "peripherals.h"
#include "pin_mux.h"
#include "clock_config.h"
#include "MIMXRT1176_cm7.h"
#include "fsl_debug_console.h"
/* TODO: insert other include files here. */
#include "fsl_lpspi.h"
/* TODO: insert other definitions and declarations here. */
void spi_init(void);
#define LPSPI61 1
#define LPSPI41 0
#if LPSPI41
#define LPSPI_MASTER_CLK_FREQ (CLOCK_GetFreqFromObs(CCM_OBS_LPSPI4_CLK_ROOT))
#endif
#if LPSPI61
#define LPSPI_MASTER_CLK_FREQ (CLOCK_GetFreqFromObs(CCM_OBS_LPSPI6_CLK_ROOT))
#endif
/*
* @brief Application entry point.
*/
//LPSPI_MasterSetBaudRate()
int main(void)
{
unsigned char str[]="hello";
/* Init board hardware. */
BOARD_InitBootPins();
BOARD_InitBootClocks();
BOARD_InitBootPeripherals();
#ifndef BOARD_INIT_DEBUG_CONSOLE_PERIPHERAL
/* Init FSL debug console. */
BOARD_InitDebugConsole();
#endif
spi_init();
PRINTF("Hello World\n");
lpspi_transfer_t fifo_read;
fifo_read.dataSize=6;
fifo_read.rxData=0;
fifo_read.txData=str;
#if LPSPI41
fifo_read.configFlags=kLPSPI_MasterPcs1 | kLPSPI_MasterPcsContinuous | kLPSPI_SlaveByteSwap;
#endif
#if LPSPI61
fifo_read.configFlags=kLPSPI_MasterPcs0 | kLPSPI_MasterPcsContinuous | kLPSPI_SlaveByteSwap;
#endif
while(1)
{
#if LPSPI61
LPSPI_MasterTransferBlocking(LPSPI6,&fifo_read);
#endif
#if LPSPI41
LPSPI_MasterTransferBlocking(LPSPI4,&fifo_read);
#endif
for(int i=1000000;i--;);
}
return 0 ;
}
void spi_init(void)
{
PRINTF("\r\nSPI INTERFACE CALLED");
uint32_t srcClock_Hz;
lpspi_master_config_t masterConfig;
masterConfig.baudRate =10000000;
masterConfig.bitsPerFrame=8;
masterConfig.cpol=kLPSPI_ClockPolarityActiveHigh;
masterConfig.cpha = kLPSPI_ClockPhaseFirstEdge;
masterConfig.direction = kLPSPI_MsbFirst;
masterConfig.pcsToSckDelayInNanoSec=1000;
masterConfig.lastSckToPcsDelayInNanoSec=1000;
masterConfig.betweenTransferDelayInNanoSec=1000;
#if LPSPI41
masterConfig.whichPcs = kLPSPI_Pcs1;
#endif
#if LPSPI61
masterConfig.whichPcs = kLPSPI_Pcs0;
#endif
masterConfig.pinCfg = kLPSPI_SdiInSdoOut;
masterConfig.dataOutConfig=kLpspiDataOutRetained;
masterConfig.pcsActiveHighOrLow=kLPSPI_SdiInSdoOut;
srcClock_Hz = LPSPI_MASTER_CLK_FREQ;
PRINTF("\n\rsrcClock_Hz ==%d\n\r",srcClock_Hz);
#if LPSPI41
LPSPI_MasterInit(LPSPI4, &masterConfig, srcClock_Hz);
#endif
#if LPSPI61
LPSPI_MasterInit(LPSPI6, &masterConfig, srcClock_Hz);
#endif
}
1) as you mentioned LPSPI_MasterSetBaudRate() i used this function this fun returns the best prescale value i checked with diffrent baudrate values
2) the presclae value i changed manually from 0 to 8 in fsl_lpspi.c driver
tcrPrescaleValue=2=28khz
tcrPrescaleValue=4=7khz
tcrPrescaleValue=6=3.5khz
tcrPrescaleValue=8=200khz
/* Set baudrate and delay times*/
(void)LPSPI_MasterSetBaudRate(base, masterConfig->baudRate, srcClock_Hz, &tcrPrescaleValue);
/* Set default watermarks */
LPSPI_SetFifoWatermarks(base, (uint32_t)kLpspiDefaultTxWatermark, (uint32_t)kLpspiDefaultRxWatermark);
// tcrPrescaleValue=0;
/* Set Transmit Command Register*/
base->TCR = LPSPI_TCR_CPOL(masterConfig->cpol) | LPSPI_TCR_CPHA(masterConfig->cpha) |
LPSPI_TCR_LSBF(masterConfig->direction) | LPSPI_TCR_FRAMESZ(masterConfig->bitsPerFrame - 1U) |
LPSPI_TCR_PRESCALE(tcrPrescaleValue) | LPSPI_TCR_PCS(masterConfig->whichPcs);