# Unable to set SPI master clock rate to 16Mhz

**URL:** <https://forum.amebaiot.com/t/unable-to-set-spi-master-clock-rate-to-16mhz/1650>\
**Category:** Peripherals\
**Tags:** rtl872xd\
**Created:** [January 7, 2023, 3:10pm UTC](https://forum.amebaiot.com/t/unable-to-set-spi-master-clock-rate-to-16mhz/1650 "2023-01-07T15:10:23Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jitendra\_Singh](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.amebaiot.com/jitendra_singh/32/820_2.png) [@Jitendra\_Singh](https://forum.amebaiot.com/u/Jitendra_Singh)\
**Post date:** [January 7, 2023, 3:10pm UTC](https://forum.amebaiot.com/t/unable-to-set-spi-master-clock-rate-to-16mhz/1650/1 "2023-01-07T15:10:23Z")

</div>

Hi,

I am evaluating spi\_trx\_in\_dma\_mode on RTL8720DF.  
How do I set the SPI clock rate to 16 MHz? I am to set it to 25Mhz and 12.5Mhz but i have a requirement for 16Mhz. Is it possible?

Regards

---

<div class="post-metadata">

**Author:** ![wyy](https://avatars.discourse-cdn.com/v4/letter/w/bc8723/32.png) [@wyy](https://forum.amebaiot.com/u/wyy)\
**Post date:** [January 9, 2023, 3:49am UTC](https://forum.amebaiot.com/t/unable-to-set-spi-master-clock-rate-to-16mhz/1650/2 "2023-01-09T03:49:16Z")

</div>

Hi @Jitendra_Singh

By default, the example uses SPI1 as the master. You can try changing the master to use SPI0.  
SPI1 has a peripheral clock of 50Mhz, which makes it difficult to get an even clock divider that results in 16Mhz.  
SPI0 has a peripheral clock of 100Mhz, which is possible to get an even clock divider that results in 16.67Mhz.

> <https://github.com/ambiot/ambd_sdk/blob/dev/component/common/mbed/targets/hal/rtl8721d/spi_api.c#L629>

---

<div class="post-metadata">

**Author:** ![Jitendra\_Singh](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.amebaiot.com/jitendra_singh/32/820_2.png) [@Jitendra\_Singh](https://forum.amebaiot.com/u/Jitendra_Singh)\
**Post date:** [January 9, 2023, 4:09am UTC](https://forum.amebaiot.com/t/unable-to-set-spi-master-clock-rate-to-16mhz/1650/3 "2023-01-09T04:09:13Z")

</div>

Hi,

SIP0 is not available I am using SDIO master.  
I only have HS\_USI\_SPI\_MOSI and SPI1.  
Can I get 16Mhz with HS\_USI\_SPI\_MOSI?

Regards

---

<div class="post-metadata">

**Author:** ![wyy](https://avatars.discourse-cdn.com/v4/letter/w/bc8723/32.png) [@wyy](https://forum.amebaiot.com/u/wyy)\
**Post date:** [January 9, 2023, 6:09am UTC](https://forum.amebaiot.com/t/unable-to-set-spi-master-clock-rate-to-16mhz/1650/4 "2023-01-09T06:09:11Z")

</div>

Unfortunately, it looks like USI\_SPI also has the same issue.

SPI0 is available on `PA_16 to PA_19` or `PB_18 to PB_21`. `PB_18 to PB_21` conflicts with SDIO pins, but are `PA_16 to PA_19` pins also not available?

---

<div class="post-metadata">

**Author:** ![Jitendra\_Singh](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.amebaiot.com/jitendra_singh/32/820_2.png) [@Jitendra\_Singh](https://forum.amebaiot.com/u/Jitendra_Singh)\
**Post date:** [January 9, 2023, 7:14am UTC](https://forum.amebaiot.com/t/unable-to-set-spi-master-clock-rate-to-16mhz/1650/5 "2023-01-09T07:14:52Z")

</div>

These pins are also not available…since i am using RTL8720DF

---

<div class="post-metadata">

**Author:** ![wyy](https://avatars.discourse-cdn.com/v4/letter/w/bc8723/32.png) [@wyy](https://forum.amebaiot.com/u/wyy)\
**Post date:** [January 9, 2023, 7:32am UTC](https://forum.amebaiot.com/t/unable-to-set-spi-master-clock-rate-to-16mhz/1650/6 "2023-01-09T07:32:00Z")

</div>

It seems like this is a hard limit that cannot be solved without changing some components.

I can think of a few options, but none of them are ideal:

1. Try to get the SPI peripheral to accept 12.5MHz. In my experience, most devices can accept a range of SPI speeds and only set an upper limit.
2. Use some combination of external components to allow switching the pins between SPI and SDIO (Multiplexer?). However this means that both cannot be used at the same time.
3. Assuming SDIO is used for a SD card, use the SD card in SPI mode. This results in a decrease in speed, and will require writing of drivers for communicating with the card through SPI.
4. Change to a chip/module with more pins.

---

<div class="post-metadata">

**Author:** ![Jitendra\_Singh](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.amebaiot.com/jitendra_singh/32/820_2.png) [@Jitendra\_Singh](https://forum.amebaiot.com/u/Jitendra_Singh)\
**Post date:** [January 10, 2023, 6:23am UTC](https://forum.amebaiot.com/t/unable-to-set-spi-master-clock-rate-to-16mhz/1650/7 "2023-01-10T06:23:02Z")

</div>

> [@wyy](#):
>
> ?). However this means that both cannot be used at the same time.

Do you have any recommended part number for the multiplexer?

---

<div class="post-metadata">

**Author:** ![wyy](https://avatars.discourse-cdn.com/v4/letter/w/bc8723/32.png) [@wyy](https://forum.amebaiot.com/u/wyy)\
**Post date:** [January 10, 2023, 9:27am UTC](https://forum.amebaiot.com/t/unable-to-set-spi-master-clock-rate-to-16mhz/1650/8 "2023-01-10T09:27:08Z")

</div>

I do not actually have any experience with using it this way, was just listing out a possibility, thus I do not have a recommended part number for that.
