6 years, 6 months ago.

spi.frequency for KL25Z

I write spi.frequency(1000000); in my program and compile it. but I get 500KHz SPI frequency. Is it bug or my Logic analyzer is broken??? I tried same setting on mbed LPC1768, it was no problem.


Question relating to:

2 Answers

6 years, 6 months ago.


I don't have the board at the moment to verify. Please can you check what values are set to SPPR and SPR bits inside SPI BR register. Here's the last line in spi_frequency function:

 obj->spi->BR = ((ref_prescaler & 0x7) << 4) | (ref_spr & 0xf);

The baudrate depends on the bus clock frequency (48MHz for KL25Z), SPPR and SPR registers. This could be a reason why you can't achieve 1000kHz SPI frequency. Check those 2 a use this to calculate baudrate

Rate = (bus clock) / ((SPPR+1)x2^(SPR+1))

That equation could be found in KL25 Reference manual (37.4.6 SPI Baud Rate Generation)


Regards, 0xc0170

6 years, 6 months ago.

Thank you Martin. I understand KL25Z is half clock of mbed LPC1768. And maybe I have to set double vaule like spi.frequency(2000000); on mbed web site compiler.