almindor / max7219

A platform agnostic driver to interface with the MAX7219 (LED display driver)
MIT License
16 stars 7 forks source link

Using this crate in a raspberry pi pico gives me weird errors if I use DS=8 #9

Open exo-cortex opened 1 year ago

exo-cortex commented 1 year ago

Hi, I was trying to use this crate with a raspberry pi pico. I used it like that:

let mut data_pin = pins.gpio15.into_mode::<bsp::hal::gpio::FunctionSpi>();
let mut cs_pin = pins.gpio13.into_mode::<bsp::hal::gpio::FunctionSpi>();
let mut sck_pin = pins.gpio14.into_mode::<bsp::hal::gpio::FunctionSpi>();

let spi = bsp::hal::Spi::<_, _, 8>::new(pac.SPI1);

let spi = spi.init(
    &mut pac.RESETS,
    clocks.peripheral_clock.freq(),
    1_000_000u32.Hz(),
    &embedded_hal::spi::MODE_0,
);

let mut display = MAX7219::from_spi(1, spi).unwrap();

If I then write data to it via write_rat() I sometimes get weird errors and suddenly all the pixels turn on, or the intensity is higher (even though). In the MAX7219's Datasheet I can find that it expects 16bits over SPI. But with MAX7219 I can only use 8 as DS-parameter (see the 8 in let spi = bsp::hal::Spi::<_,_,8>::new(pac.SPI1);). Is there an error here?

Could it be that in the spi-implementation there is only the Write<u8>-traits used and not a Write<u16> ?

impl<SPI> MAX7219<SpiConnector<SPI>>
where
    SPI: Write<u8>,
{
...
}

impl<SPI, CS> MAX7219<SpiConnectorSW<SPI, CS>>
where
    SPI: Write<u8>,
    CS: OutputPin,
{
...
}

I found another example where someone put text on this display and it used DS=16,but implemented the MAX7219-thing from scratch. See here.

I am still a noob in embedded rust, so sorry if that is wrong and I am wasting somebodies time.

That is all. Thank you :-)

SpeedSX commented 9 months ago

@exo-cortex Have you found any solution of the issue? I also tried this crate and cannot figure out how to work with it. clear_display() does not work correctly for me, clears the last column only. I only managed to use write_raw().

By the way, when I tried from_spi() like you did, it does not work at all for me. So I'm using from_spi_cs

    let spi_sclk: gpio::Pin<_, gpio::FunctionSpi, gpio::PullNone> = pins.gpio2.reconfigure();
    let spi_mosi: gpio::Pin<_, gpio::FunctionSpi, gpio::PullNone> = pins.gpio3.reconfigure();
    let spi_miso: gpio::Pin<_, gpio::FunctionSpi, gpio::PullUp> = pins.gpio4.reconfigure();
    let spi_cs = pins.gpio5.into_push_pull_output();

    // Create the SPI driver instance for the SPI0 device
    let spi = spi::Spi::<_, _, _, 8>::new(pac.SPI0, (spi_mosi, spi_miso, spi_sclk));

    // Exchange the uninitialised SPI driver for an initialised one
    let spi = spi.init(
        &mut pac.RESETS,
        clocks.peripheral_clock.freq(),
        1.MHz(),
        embedded_hal::spi::MODE_0,
    );

    let mut display = MAX7219::from_spi_cs(1, spi, spi_cs).unwrap();
exo-cortex commented 5 months ago

Not yet unfortunately. I on-and-off tried to work around the problem. I think I found other code to address the max7219 somewhere that I used. But it's not a very nice solution. I'd rather use this library. Will try again!