This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Fine Tuning MSP430 SPI Clock Frequency

Other Parts Discussed in Thread: MSP430F5310, MSP430F5340

Hello all,

I am working with an MSP430F5310, with the core running at 25 MHz using DCO. I do not have any external crystals on my system. I am trying to run my SPI (UCB1) at 8 Mhz, however the problem is that 25 Mhz is not divisible by 8 Mhz. This means that I can't tell the UCB1 peripheral to use a scaler to derive its clock, since using 3 gives me 8.33 Mhz, and using 4 gives me 6.25. Can anyone give me any insight on how I can set my SPI clock speed to 8 Mhz while keeping my core frequency at 25 MHz?

This is how I set my core to 25 MHz (comes from a TI example):

void setClocks()
{
	// Increase Vcore setting to level3 to support fsystem=25MHz
	// NOTE: Change core voltage one level at a time..
	SetVcoreUp (0x01);
	SetVcoreUp (0x02);
	SetVcoreUp (0x03);

	UCSCTL3 = SELREF_2;                       // Set DCO FLL reference = REFO
	UCSCTL4 |= SELA_2;                        // Set ACLK = REFO

	__bis_SR_register(SCG0);                  // Disable the FLL control loop
	UCSCTL0 = 0x0000;                         // Set lowest possible DCOx, MODx
	UCSCTL1 = DCORSEL_7;                      // Select DCO range 50MHz operation
	UCSCTL2 = FLLD_1 + 762;                   // Set DCO Multiplier for 25MHz
											// (N + 1) * FLLRef = Fdco
											// (762 + 1) * 32768 = 25MHz
											// Set FLL Div = fDCOCLK/2
	__bic_SR_register(SCG0);                  // Enable the FLL control loop

	// Worst-case settling time for the DCO when the DCO range bits have been
	// changed is n x 32 x 32 x f_MCLK / f_FLL_reference. See UCS chapter in 5xx
	// UG for optimization.
	// 32 x 32 x 25 MHz / 32,768 Hz ~ 780k MCLK cycles for DCO to settle
	__delay_cycles(782000);

	// Loop until XT1 & DCO stabilizes - In this case only DCO has to stabilize
	do
	{
	//UCSCTL7 &= ~(XT1LFOFFG + XT1HFOFFG + DCOFFG);
	UCSCTL7 &= ~(XT1LFOFFG + DCOFFG);
											// Clear XT1,DCO fault flags
	SFRIFG1 &= ~OFIFG;                      // Clear fault flags
	}while (SFRIFG1&OFIFG);                   // Test oscillator fault flag


}

  • Hi,

    First of all, I won't recommend you to use up to 25MHz according to my experience using MSP430F5340 for many years. I know it claims to support up to 25MHz for F5x, but it won't be stable according to my long-time test. It would be safer to use 20MHz. Btw, 25MHz also consumes more power.

    Secondly, why don't you use a core frequency of multiple of 8MHz? That is 16MHz or 24MHz. In this case, you need to modify setClocks() function.
  • Do you really need to run the SPI at 8 MHz? SPI is synchronous; the exact frequency usually does not matter.
  • What kind of instability did you experience running at 25 Mhz? I have never had issues with stability at 25 Mhz. For my system, power isn't an issue, performance is much more important. It is a high performance system that has a lot of recursive loops (also IQMath Fixed Point Operations), which is why I need to squeeze as much out of the core as possible.
  • I am doing 1 KB streams of data over SPI 30 times every second. So I need the most bandwidth I can extract. I am currently running at 6.25 MHz with the prescalar set to 4. I tried a prescalar of 3, which yielded 8.33 MHz, which the SPI slave could not handle. Thanks!
  • What frequency is your SPI slave specified to handle?
  • About two years ago, I have a product using MSP430F5340, some boards can not get to work on frequency over 20MHz. The clock tuning loop will blocks. Yes, I know it may be related to layout issue. But we just can't find anything wrong about hardware. So, both hardware and software engineers conclude the rule: don't use MSP430 over 20MHz. If you can run 25MHz without problem then you can still use it.

    For 8MHz SPI clock, how about using 4% CPU power (25MHz --> 24MHz) to get higher SPI bandwidth? Btw, have you tried DMA to save CPU time?

**Attention** This is a public forum