Skip to content

GPIO listener not firing on SPI enabled pins. #147

@jorbo

Description

@jorbo

I am trying to connect the SPI pins to another simulated device. I've added a listener to the specific GPIO pins that are associated with the SPI setup in the firmware, but the listeners are never called.

Here is the firmware and the way I am adding the listener.

#include <stdio.h>
#include "pico/stdlib.h"
#include "pico/binary_info.h"
#include "hardware/spi.h"
#include <stdlib.h>
#include "time.h"
#include <boards/pico.h>


#define SPI_PORT spi0
#define PIN_MISO PICO_DEFAULT_SPI_RX_PIN
#define PIN_CS   PICO_DEFAULT_SPI_CSN_PIN
#define PIN_SCK  PICO_DEFAULT_SPI_SCK_PIN
#define PIN_MOSI PICO_DEFAULT_SPI_TX_PIN


#define BUF_LEN         1
int main()
{
    stdio_init_all();
    srand(time(0));

    spi_init(SPI_PORT, 1000*1000);
    gpio_set_function(PIN_MISO, GPIO_FUNC_SPI);
    gpio_set_function(PIN_SCK, GPIO_FUNC_SPI);
    gpio_set_function(PIN_MOSI, GPIO_FUNC_SPI);
    gpio_set_function(PIN_CS, GPIO_FUNC_SPI);

    const uint LED_PIN = PICO_DEFAULT_LED_PIN;
    gpio_init(LED_PIN);
    gpio_set_dir(LED_PIN, GPIO_OUT);

    uint8_t out_buf[BUF_LEN], in_buf[BUF_LEN];   
    
    for (size_t i = 0; ;++i){
        out_buf[0] = rand() % 255;
        gpio_put(LED_PIN, 1);
        spi_write_blocking(spi_default, out_buf, BUF_LEN);
        gpio_put(LED_PIN, 0);
        busy_wait_ms(500);
    }
}
  mcu.gpio[19].addListener((state: GPIOPinState, oldState: GPIOPinState) => {
    console.log('GPIO 19 state changed:', state);
  });

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions