SPI clock cannot be detected

⚠️
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.wsdof.com/support. We’ll be fixing bugs / optimising the searching and tagging over the coming days.
7 posts / 0 new
Last post
hasiky
Offline
Last seen:2 years 4 months ago
Joined:2019-05-03 08:21
SPI clock cannot be detected

Hi,

We are using DA14580DEVKT-B. We try to use SPI interface to transmit data from accelerometer to DA14580 chip, and then send data via BLE.

However, the SPI clock signal can not be detected from P0_0, even though we have configure as follow (We are using ble_app_peripheral sample in SDK):

SetBits16(CLK_PER_REG, SPI_ENABLE, 1);

// initialize SPI
SetBits16(SPI_CTRL_REG, SPI_ON, 0); // close SPI block, if opened
SetBits16(SPI_CTRL_REG, SPI_WORD, bitmode); // set SPI bitmode
SetBits16(SPI_CTRL_REG, SPI_SMN, role); // select role (master/slave)
SetBits16(SPI_CTRL_REG, SPI_POL, clk_pol); // select SPI clock idle polarity
SetBits16(SPI_CTRL_REG, SPI_PHA, pha_mode); // select SPI sampling edge selection (pha_mode - refer to datasheet p.53-54)
SetBits16(SPI_CTRL_REG, SPI_MINT, irq); // enable/disable SPI interrupt to the NVIC
SetBits16(SPI_CTRL_REG, SPI_CLK, freq); // SPI block clock divider
SetBits16(SPI_CTRL_REG, SPI_ON, 1); // enable SPI block

GPIO_ConfigurePin(SPI_GPIO_PORT, SPI_CS_PIN, OUTPUT, PID_SPI_EN, true);
GPIO_ConfigurePin(SPI_GPIO_PORT, SPI_CLK_PIN, OUTPUT, PID_SPI_CLK,false);
GPIO_ConfigurePin(SPI_GPIO_PORT, SPI_DO_PIN, OUTPUT, PID_SPI_DO, false);
GPIO_ConfigurePin(SPI_GPIO_PORT, SPI_DI_PIN, INPUT, PID_SPI_DI, false);

Then, we wanted to figure out what was wrong such that we tried to run blinky and SPI_flash. The SPI clock signal can be seen as suqare wave from P0_0 as the same configuration above.

However, no matter how we changed the SPI_CLK of SPI_CTRL_REG from 00 to 11, the clock frequency cannot be changed.

code: SetBits16(SPI_CTRL_REG, SPI_CLK, freq);

Even, we changed all the codes in blinky one by one, the clock signal remain unchanged. So we are so confused about the spi clock signal on how to generate and be changed?

Thanks.

Device:
CYibin
Offline
Last seen:1 year 4 months ago
Staff
Joined:2017-12-14 02:48
Hi hasiky,

Hi hasiky,

To impletement a spi master, you should follow below steps:

1. Configure pads of spi peripheral using set_pad_functions() and GPIO_reservations()

2. Init the spi by calling spi_init() in periph_init() function

You can choose the enum SPI_XTAL_Freq_t to configure the freq of the clk, note that:

  • clock speeds up to 16 MHz for the SPI controller
  • Clock divided by 1, 2, 4, 8
  • SPI clock line speed up to 8 MHz

3. Send/read spi data using spi_transaction()

BR, Yibin

hasiky
Offline
Last seen:2 years 4 months ago
Joined:2019-05-03 08:21
Hi,

Hi,

Thank you for your response. I did follow your step to have a try, but it did not work either.

I used the "ble_app_peripheral" for testing and used oscilloscope to observe the clock signal. It was interesting that once I download the code into the chip, the clock signal seemed to be beautiful square wave for 1 s, then disappeared into a line.

顺便问一下,你在哪里叫periph_init()功能ion? Should I call in the main() function? However, I couldn't find where was it.

Thank you so much.

hasiky
Offline
Last seen:2 years 4 months ago
Joined:2019-05-03 08:21
Moreover, it was interesting

此外,有趣的是,一旦我下载the code into the chip, the clock signal seemed to be beautiful square wave for 1 s, then disappeared into a dc line at about 0.

MHv_Dialog
Offline
Last seen:7 months 2 weeks ago
Staff
Joined:2013-12-06 15:10
Hi hasiky,

Hi hasiky,

I suggest that you try to work with the spi project in the peripheral_examples folder of the SDK. It should be fairly easy to see the correct flow of defining the GPIOs and initializing the SPI interface.

/MHv

hasiky
Offline
Last seen:2 years 4 months ago
Joined:2019-05-03 08:21
Thank you. I did work with

Thank you. I did work with the spi project in the peripheral_examples in SDK folder. I did observe the 2 MHz clock signal coming from P0_0. However, when I changed the value of SPI_XTAL_Freq_t and commented out the spi_init() function respectively, the output of P0_0 remained unchanged. Even I use blinky example without any seetting about spi, the output remained. That was really confusing.

MHv_Dialog
Offline
Last seen:7 months 2 weeks ago
Staff
Joined:2013-12-06 15:10
Hi hasiky,

Hi hasiky,

You can only change the frequency within the specified values. To do that, you should specify the frequency using a value from the predefined enum:

typedef enum SPI_FREQ_MODES{ SPI_XTAL_DIV_8, SPI_XTAL_DIV_4, SPI_XTAL_DIV_2, SPI_XTAL_DIV_14, }SPI_XTAL_Freq_t;such asSetBits16(SPI_CTRL_REG, SPI_CLK,SPI_XTAL_DIV_4 );

If you comment out the spi_init call, you shouldn't expect any SPI activity.

When the device boots or reboots, it will run a bootloader attempting to load code from various external sources (check the AN-B-001 App note). This includes some SPI activity, and I am guessing that this is what you are observing.

/MHv