Unknown origin of error
markus.prager@...
Thanks for the directions, Jamie. &spi2 {
pinctrl-0 = <&spi2_sck_pb13
&spi2_miso_pb14 &spi2_mosi_pb15>;/*PIN34,PIN35,PIN36*/
cs-gpios = <&gpioc 6 GPIO_ACTIVE_LOW>;/* PC6, Acc_CS */
status = "okay";
};
This is based on the information found in "spi-device.yaml". &spi2 {
lis3dhh: lis3dhh@0 {
compatible = "st,lis3dhh","st,spi_lis3dhh";
status = "okay";
reg = <0>;
label = "LIS3DHH";
spi-max-frequency = <1000000>;
irq-gpios = <&gpioc 7 GPIO_ACTIVE_HIGH>, <&gpioc 8 GPIO_ACTIVE_HIGH>; //INT1, PC7 & INT2, PC8
};
};
int lis3dhh_spi_init(const struct device *dev)
{
struct lis3dhh_data *lis3dhh_drv_data = dev->data;
const struct lis3dhh_config *cfg = dev->config;
const struct lis3dhh_spi_cfg *spi_cfg = cfg->bus_cfg.spi_cfg;
LOG_ERR("config->cs: %p", spi_cfg->spi_conf.cs);
LOG_ERR("config->cs->gpio_dev: %p", spi_cfg->spi_conf.cs->gpio_dev);
lis3dhh_drv_data->hw_tf = &lis3dhh_spi_transfter_fn;
if (spi_cfg->cs_gpios_label != NULL)
{
lis3dhh_drv_data->cs_ctrl.gpio_dev = device_get_binding(spi_cfg->cs_gpios_label);
if (!lis3dhh_drv_data->cs_ctrl.gpio_dev)
{
LOG_ERR("unable to get GPIO SPI CS device");
return -ENODEV; //no such device
}
LOG_DBG("SPI GPIO CS configured on %s:%u", spi_cfg->cs_gpios_label, lis3dhh_drv_data->cs_ctrl.gpio_pin);
}
if (spi_cfg->cs_gpios_label == NULL) {LOG_ERR("spi_cfg cs_gpios_label is NULL");}
return 0;
}
int lis3dhh_init(const struct device *dev)
{
struct lis3dhh_data *lis3dhh_drv_data = dev->data;
const struct lis3dhh_config *cfg = dev->config;
int status;
uint8_t id;
lis3dhh_drv_data->bus = device_get_binding(
cfg->bus_name);
if (!lis3dhh_drv_data->bus)
{
LOG_ERR("master not found: %s", cfg->bus_name);
return -EINVAL; // error: invalid value
}
cfg->bus_init(dev); //spi bus initialization
status = lis3dhh_drv_data->hw_tf->read_reg(
dev, LIS3DHH_REG_WAI,
&id);
if (status < 0)
{
LOG_ERR("failed to read chip id.");
return status;
}
if (id != LIS3DHH_CHIP_ID)
{
LOG_ERR("invalid chip id: %02x (hex)\n", id);
return -EINVAL; // error: invalid value
}
LOG_INF("bus=%s", cfg->bus_name);
status = lis3dhh_drv_data->hw_tf->write_reg(dev, LIS3DHH_CTRL_REG1,
(LIS3DHH_CTRL_REG1_NORM_MODE_EN |
LIS3DHH_CTRL_REG1_IF_ADD_INC |
LIS3DHH_CTRL_REG1_BOOT));
if (status < 0)
{
LOG_ERR("failed to configure ctrl reg 1");
printk("failed to configure ctrl reg 1");
return status;
}
status = lis3dhh_drv_data->hw_tf->write_reg(dev, LIS3DHH_CTRL_REG4, LIS3DHH_CTRL_REG4_ONE_1);
return status;
}
|
|
lairdjm
Hi Markus,
Do you have the include at the top of the driver you're developing which incluces the spi-device.yaml file, e.g. from one of the other LIS2XX devices:
include: ["spi-device.yaml", "st,lis2dh-common.yaml"]
The SPI frequency should be for the device not the SPI controller, not that I've tested it and don't know if it's implemented or works but in theory you could have an SPI bus with 3 devices attached, one device could take at 250Kbps, one at 1Mbps and the
other at 20Mbps hence the SPI maximum frequency being part of the device configuration
Thanks, Jamie On Fri, 2021-09-10 at 06:07 -0700, markus.prager via lists.zephyrproject.org wrote:
|
|
markus.prager@...
Alright, so thanks to Nick (thank you!) I have now narrowed down my problem a little. |
|
markus.prager@...
Hi everyone |
|