How to dynamically configure SPI baudrate?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to dynamically configure SPI baudrate?

982 Views
fedora
Contributor III

Hi Team:

   I'm using S32K144 and configure the baudrate of spi2 to 100K through PE tools(refer to the attached image),  I want to dynamically configure the speed of spi2 to 50K/20K/10K/5K during the device running.

The following is the test code:

//***********************************************

uint32_t baud2;
status_t ret_sts;

lpspi_master_config_t spiConfig1;


spiConfig1.bitsPerSec = 10000; //10Kbps baudrate
spiConfig1.whichPcs = LPSPI_PCS2;
spiConfig1.pcsPolarity = LPSPI_ACTIVE_LOW;
spiConfig1.isPcsContinuous = false;
spiConfig1.bitcount = 16;
spiConfig1.clkPhase = LPSPI_CLOCK_PHASE_1ST_EDGE;
spiConfig1.clkPolarity = LPSPI_SCK_ACTIVE_HIGH;
spiConfig1.lsbFirst= false;
spiConfig1.transferType = LPSPI_USING_INTERRUPTS;

ret_sts = LPSPI_DRV_MasterConfigureBus(LPSPICOM2, (lpspi_master_config_t *)&spiConfig1, &baud2);
printf("ret_sts = %d,baud2=%d\r\n",ret_sts,baud2);

//****************************************************

After running, printf output:  ret_sts = 1,baud2=0

so LPSPI_DRV_MasterConfigureBus() return STATUS_ERROR,  trace into it and find the STATUS_ERROR is caused by the following code:

//****************************************************

if ((spiConfig->bitcount < 8U) || (spiConfig->bitcount > 4096U))
{

    printf("spi bitcount=%d\r\n",spiConfig->bitcount);
    return STATUS_ERROR;
}

//****************************************************

Then output   spi bitcount=0  ,  but the actual value of bitcount should be equal to 16.

 

May I ask where my method went wrong?

How to achieve dynamic configuration of SPI baudrate?

Thank you for your suggestion.

 

Best regards,

Fed

0 Kudos
Reply
2 Replies

952 Views
davidtosenovjan
NXP TechSupport
NXP TechSupport

Could you specify used RTD and example code?

0 Kudos
Reply

947 Views
fedora
Contributor III

Thanks !

I don't know what's the RTD.

The requirement is that when the device is activated, the speed of SPI can be 100k, but when the device is in sleep mode, the speed of SPI can only be 10k or even lower. Therefore, it is necessary to dynamically change the SPI speed.

Thanks and regards,

Fed

 

0 Kudos
Reply