cancel
Showing results for 
Search instead for 
Did you mean: 

Use SPI on STM32F410RB via Zephyr

DKOO
Associate

Hello.

 

I'm working with Nucleo-F410Rb, which has STM32F410Rb as MCU.

Now I'm developing SPI connection by using Zephyr.

Zephyr is maybe not suitable for this forum, but i wish get any clue or idea for my problem.(something like hardware parameters, physical issues etc.)

 

I make test source code referred to /samples/driver/spi_fujitsu_fram source code,

here's a oscilloscope result. It shows SPI1 MOSI, and each value is 0x01, 0x02, 0xff.

 

0690X000008vuPUQAY.jpg

 

As you see, patterns looks very weird, and I don't know why MOSI output looks like above..

 

Here's my test source code.

#include <errno.h>
#include <zephyr.h>
#include <misc/printk.h>
#include <device.h>
#include <spi.h>
 
static int koo_spi_write(struct device *spi, struct spi_config *spi_cfg,
			    u8_t cmd, u8_t addr, u8_t data)
{
	struct spi_buf bufs[] = {
		{
			.buf = cmd,
			.len = 1
		},
		{
			.buf = addr,
			.len = 1
		},
		{
			.buf = data,
			.len = 1
		}
	};
	struct spi_buf_set tx = {
		.buffers = bufs
	};
 
	tx.count = 3;
 
	return spi_write(spi, spi_cfg, &tx);
}
 
void main(void)
{
	struct device *spi;
	struct spi_config spi_cfg;
	struct spi_cs_control spi_cs;
	int err, i;
 
	printk("KOO SPI example application\n");
 
	spi = device_get_binding(DT_SPI_1_NAME);
	if (!spi) {
		printk("Could not find SPI driver\n");
		return;
	}
 
	spi_cfg.operation = SPI_WORD_SET(8);
	spi_cfg.frequency = 5000000;
 
	spi_cs.gpio_dev = device_get_binding(DT_ST_STM32_SPI_1_CS_GPIOS_CONTROLLER);
	spi_cs.gpio_pin = DT_ST_STM32_SPI_1_CS_GPIOS_PIN;
	spi_cs.delay = 0;
 
	spi_cfg.cs = &spi_cs;
 
	k_sleep(1);
 
	while(1) {
		for(i=0; i<16; i++) {
			err = koo_spi_write(spi, &spi_cfg, 0x01, 0x02, 0xff);
			printk("%d: SPI OUTPUT %d\n", err, i);
			k_sleep(100); 
		}
	}
}

Thanks for read my post, and plz tell me what's the problem or what i have to look for.

 

Regards.

0 REPLIES 0