⚠️
Hi there.. thanks for coming to the forums. Exciting news! we’re now in the process of moving to our new forum platform that will offer better functionality and is contained within the main Dialog website. All posts and accounts have been migrated. We’re now accepting traffic on the new forum only - please POST any new threads at//www.xmece.com/support. We’ll be fixing bugs / optimising the searching and tagging over the coming days.
13 posts / 0 new
Last post
herangli
Offline
Last seen:1 month 3 weeks ago
Joined:2019-12-15 12:42
SPI master clock setup

Dear support

I have a da14695 USB eval board and I'd like to integrate a device to board on SPI.
This slave device requires a maximum 1MHz SCLK frequency to be able to communicate.
I tried to find some solution to set a lower frequency but I haven't found any way.

Is it possible to set a lower SPI Master SCLK frequency? If it is possible please help me how.

Thanks in advance

Device:
PM_Dialog
Offline
Last seen:18 hours 42 min ago
Staff
Joined:2018-02-08 11:03
Hi herangli,

Hi herangli,

Thanks for your question. Please see datasheet section 33 and table Table 345: SPI_CTRL_REG. The SPI_CTRL_REG[SPI_CLK] bitfield is responsible for clock output frequency in master mode. So, in the SPI configuration structure (ad_spi_driver_conf_t), you should select the appropriate clock.

I would recommend first checking theDA1469x Tutorial SPI Adapter Concepts. In that tutorial the .xtal_freq = HW_SPI_FREQ_DIV_8 is selected, so you can change it according to your requirements.

Generally, we strongly recommend the usage of the adapters for accessing hardware peripherals because not only provide access to the peripheral, but also make sure that other tasks which are currently accessing it, suspend their operation until the peripheral is once again released. So you don't have to worry if another task tries accessing the same peripheral at the same time. Also, in sleep mode all the peripheral blocks are powered down.

Thanks, PM_Dialog

herangli
Offline
Last seen:1 month 3 weeks ago
Joined:2019-12-15 12:42
Dear support

Dear support

Thank you for your quick answer.
I checked and used the SPI example in my code. I use ad sw layer all other parts of code.
I tried to decrease the SPI clock in an original way. It means change .xtal_freq value in the maximal divider enum (HW_SPI_FREQ_DIV_14)as you mentioned.
When I measure SPI SCLK signal frequency I see approximately 2.5 MHz. (My USB oscilloscope accuracy not so high but I am sure it is over than 1MHz)

I am a bit confused because I checked the clock tree (page 168) and as I see this divider is the one way to decrease the SCLK frequency because the input of the divider can come from sysclk or divN clock source. divN is a fix value as I know or there isn't any interface function which I would be able to modify this value.
It means for me that it is impossible to go bellow 1MHz with SCLK if I would like to use 32MHz crystal or PLL. I am sure that I miss out on something just I don't know what.

Thanks in advance

PM_Dialog
Offline
Last seen:18 hours 42 min ago
Staff
Joined:2018-02-08 11:03
Hi herangli,

Hi herangli,

Please try to change the dividers :

cm_apb_set_clock_divider(apb_div1);

cm_ahb_set_clock_divider(ahb_div1);

However, you will not able to clock the clock to PLL so the system will run with the 32MHz. Please check hw_clk_set_sysclk() function.

Thanks, PM_Dialog

herangli
Offline
Last seen:1 month 3 weeks ago
Joined:2019-12-15 12:42
Dear support

Dear support

Thanks for your reply.

I switched back to xtal 32 MHz clock in order to modify ahb and apb bus clock divider and I measured SCLK frequency but I couldn't achieve any positive result. I tried several divider parameters but they didn't have any effect for SPI clock frequency.

In the clock tree and datasheet, I saw that these dividers have impact only QSPI peripherals but it is used for flash or ram handling.

I see approximately 2.3-2.5MHz in SPI CLK pin and one way how I can modify this frequency by the SPI clock divider as you also mentioned in the past.

Do you have any other idea how can I achieve a smaller frequency than 1MHz or we may declare that it is not possible with this architecture?

Thanks in advance

PM_Dialog
Offline
Last seen:18 hours 42 min ago
Staff
Joined:2018-02-08 11:03
Hi herangli,

Hi herangli,

Please take a look at Figure 34: Clock Tree Diagram in the datasheet. All the peripheral blocks are fed either from the system clock div1( green line ) or from divN_clk (red line). The green line is the system clock divided by 1, 2. 4 or 8. By default the system clock is divided by 1 and is at 32MHz :

cm_sys_clk_init(sysclk_XTAL32M);

cm_apb_set_clock_divider(apb_div1);

cm_ahb_set_clock_divider(ahb_div1);

The red line is the output of the DivN HW block, and the frequency is always at 32Mhz regardless the aforementioned division.

The CLK_COM_REG handles the selection between the “green” and “red” line. The Low Level Drivers (LLD) are implemented with the 32MHz clock (red line) divN_clk. The clock frequency can be divided in the peripheral HW blocks further ( if it is possible).

专门为SPI边缘块,克罗ck speeds up to 32 MHz for the SPI controller and the SPI source clock can be divided by 2, 4, 8, 14 (according to datasheet). So the minimum SPI clock is at 32MHz / 14.

In case you want to lower down the SPI clock further, you should select the div1 for the peripheral clock and then lower down the System Clock to be able to get lower peripheral frequencies. This is not recommended, as the overall CPU performance will be lower. Additionally, in case of an event which will trigger in your app the change of a higher frequency to the system clock, for example plug in of the USB which require the PLL96, this will result to an unconditional change of the speed in your peripheral. You will have to take extra care in your application, so there will be absolutely no system clock changes during the transaction of your peripheral while using the divN.

If you still need to use 1MHz SPI clock, a possible workaround might be the following :

  1. Divide the System Clock by 4 in the main() function as follow

cm_sys_clk_init(sysclk_XTAL32M);

cm_apb_set_clock_divider(apb_div4);

cm_ahb_set_clock_divider(ahb_div4);

The new System Clock will be 32MHz / 4 = 8MHz

  1. Change the hw_spi_init_clk_reg() accordingly and select the Div1 clock - CLK_COM_REG[SPI_CLK_SEL] = 0x01
  2. Divide further the SPI clock by 8 - SPI_CTRL_REG[SPI_CLK] = 0x00 . The result will be 8MHz / 8 = 1MHz

Thanks, PM_Dialog

herangli
Offline
Last seen:1 month 3 weeks ago
Joined:2019-12-15 12:42
Dear support

Dear support
谢谢你的详细的回答。我检查这个workaround. It means
1. Set HCLK and PCLK divider
cm_sys_clk_init(sysclk_XTAL32M);
cm_apb_set_clock_divider(apb_div4);
cm_ahb_set_clock_divider(ahb_div4);
cm_lp_clk_init();
2. Modify hw_spi_init_clk_reg() function (I use SPI1)
void hw_spi_init_clk_reg(HW_SPI_ID id)
{
ASSERT_WARNING(REG_GETF(CRG_TOP, PMU_CTRL_REG, COM_SLEEP) == 0);
if (id == HW_SPI1) {
CRG_COM->RESET_CLK_COM_REG = CRG_COM_RESET_CLK_COM_REG_SPI_CLK_SEL_Msk;
CRG_COM->SET_CLK_COM_REG = (CRG_COM_SET_CLK_COM_REG_SPI_ENABLE_Msk |CRG_COM_SET_CLK_COM_REG_SPI_CLK_SEL_Msk);
} else {
CRG_COM->RESET_CLK_COM_REG = CRG_COM_RESET_CLK_COM_REG_SPI2_CLK_SEL_Msk;
CRG_COM->SET_CLK_COM_REG = CRG_COM_SET_CLK_COM_REG_SPI2_ENABLE_Msk;
}
}
3. divide SPI clock (with 14 -> 500k SCLK)
/* External sensor/module SPI driver */
const ad_spi_driver_conf_t drv_SPI1_adis = {
.spi = {
.cs_pad = {DEVICE_CS_GPIO_PORT, DEVICE_CS_GPIO_PIN},
.word_mode = HW_SPI_WORD_8BIT, // Here you can define the required
.smn_role = HW_SPI_MODE_MASTER,
.polarity_mode = HW_SPI_POL_LOW, // Here you can define the required SPI polarity
.phase_mode = HW_SPI_PHA_MODE_0, // Here you can define the required SPI phase
.mint_mode = HW_SPI_MINT_DISABLE,
.xtal_freq = HW_SPI_FREQ_DIV_14,
.fifo_mode = HW_SPI_FIFO_RX_TX,
.disabled = 0, /* Should be disabled during initialization phase */
.ignore_cs = false,
.use_dma = true,
.rx_dma_channel = HW_DMA_CHANNEL_2,
.tx_dma_channel = HW_DMA_CHANNEL_4
}
};

The result is unfortunately the same.

I checked again the datasheet but not clear for me why did you write that ,,The green line is the system clock divided by 1, 2. 4 or 8". The green line is the system clock. The ahb and apb bus clock are the system clock divided by 1,2,4,8 . The green line comes from sys_clk selector and comes directly from XTAL32, RC32, PLL , LP clock. I can modify ahb and apb bus clock but as I see the SPI periphery clock is independent from ahb or apb bus clock. (Figure 84: SPI Block Diagram) . These buses only take part in data movement.

Thanks in advance

PM_Dialog
Offline
Last seen:18 hours 42 min ago
Staff
Joined:2018-02-08 11:03
Hi herangli,

Hi herangli,

I meant that if the ahb and apb bus clocks are divided, then the system clock is divided by 1,2,4,8 too. Please let me check it in my side and I’ll let you know.

Can I ask what is the SPI interface that you are using and required SPI clack speed less than 1MHz ?

Thanks PM_Dialog

herangli
Offline
Last seen:1 month 3 weeks ago
Joined:2019-12-15 12:42
Dear support

Dear support

Thank you for check this issue on your side.

Of course, I would like to make high precision IMU measurement with an ADIS16460 and send out measurements via Bluetooth.
This is the datasheet of ADIS sensorhttps://www.analog.com/en/products/adis16460.html
In the datasheet, you can see the maximal SPI clock frequency on the top of page 5.

(I think after this post we may ask some money from Analog Devices, as advertise cost :) )

Thanks in advance

herangli
Offline
Last seen:1 month 3 weeks ago
Joined:2019-12-15 12:42
Dear support

Dear support

Did you have a chance to check this issue in an eval board?

Thank you in advance

herangli
Offline
Last seen:1 month 3 weeks ago
Joined:2019-12-15 12:42
Dear support

Dear support

Did you have a chance to check this issue in an eval board?

Thank you in advance

PM_Dialog
Offline
Last seen:18 hours 42 min ago
Staff
Joined:2018-02-08 11:03
Hi herangli,

Hi herangli,

Thanks for the reminder and my apologies for the late response. I’ll give a try again.

Thanks, PM_Dialog

PM_Dialog
Offline
Last seen:18 hours 42 min ago
Staff
Joined:2018-02-08 11:03
Hi herangli,

Hi herangli,

Would it be possible to attach your project here to take a look?

Thanks, PM_Dialog