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.
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:
3. Send/read spi data using spi_transaction()
BR, Yibin
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.
此外,有趣的是,一旦我下载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.
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
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.
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:
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