SPI gpio interrupt on cs pin #45663
-
(Quick warning: I'm still new to embbeded and RTOSs (Zephyr included)) I'm trying to initiate an SPI communication between an STM32F411CE (slave) and an Arduino atmega 2560 (master) with an interrupt on the chip select pin and I can't seem to manage to get what I need for spi_transceive(...). I'm configuring my interrupt callback as follow: static const struct gpio_dt_spec cs = GPIO_DT_SPEC_GET_OR(SPI1_NODE, cs_gpios, {0});
static struct gpio_callback cs_callback;
void cs_enabled(const struct device *dev, struct gpio_callback *cb, uint32_t pins)
{
SWOPrintf("Into SPI1 ISR\r\n");
...
}
void main(void)
{
SWOPrintf("Starting \r\n");
const struct device *spi_dev = device_get_binding(SPI1_LABEL);
if (spi_dev == NULL) {...}
ret = gpio_pin_interrupt_configure_dt(&cs,
GPIO_INT_EDGE_FALLING);
if (ret != 0) {
SWOPrintf("Error %d: failed to configure interrupt on %s pin %d\r\n",
ret, cs.port->name, cs.pin);
return;
}
gpio_init_callback(&cs_callback, cs_enabled, BIT(cs.pin));
gpio_add_callback(cs.port, &cs_callback);
while (1) {
SWOPrintf("debug!\r\n");
k_msleep(SLEEP_TIME_MS);
}
} I have an overlay file for my board configured as follow:
My problem is that the I can give source code of both salve and master if needed. Thank you in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
^^@FRASTM |
Beta Was this translation helpful? Give feedback.
-
I've change the way I do it and instead of the gpio interrupt handling the spi_device, I make the gpio interrupt increment a given semaphore when the CS pin encounters a falling edge. By doing so, another dedicated thread waiting for the said semaphore can then use the semaphore and start an spi interraction. This thread can be mark as answered. |
Beta Was this translation helpful? Give feedback.
I've change the way I do it and instead of the gpio interrupt handling the spi_device, I make the gpio interrupt increment a given semaphore when the CS pin encounters a falling edge. By doing so, another dedicated thread waiting for the said semaphore can then use the semaphore and start an spi interraction.
This thread can be mark as answered.