keesj

SPI MODE0

4 posts in this topic

Hi,

I am trying to interface with an 8x8 Led-Digit driver.  I Started by bit banging the code to get something working

void send(int value) {

  // enable CS
  digitalWrite(MX_CS, LOW);
  w();
  int v = value;
  for (signed int x = 15; x >= 0; x--) {
    digitalWrite(MX_DATA, ((v >> x) & 0x1) ? 1 : 0);
    w();
    digitalWrite(MX_CLK, HIGH);
    w();
    digitalWrite(MX_CLK, LOW);
    w();
  }
  digitalWrite(MX_CS, HIGH);
  w();
}

 

Next I moved to using the zpuino SPI block. I looked at the datasheet above and the wikipedia article on SPI and determined I need to send my SPI message using "MODE0".

59f0507e61b23_Screenshotfrom2017-10-2510-50-43.thumb.png.000df8399c5c32a15133cf33fc052bb1.png

 

When I do so the SPI device is not working properly

59f04f4646bc7_Screenshotfrom2017-10-2510-39-26.thumb.png.af3ab693086d3019a52d7a1695138212.png

And from looking at the SPI implementation I think the problem is that the values are always set on the rising edge of the clock while for MODE0 the value should be set before (e.g. on the falling edge).

Am I missing something? (from experimenting using MODE2 apprears to work but then clock stays high in between cycles)

59f051f7e4c55_Screenshotfrom2017-10-2510-56-32.thumb.png.b8b6c6914147c56faeb45ae693c2cac6.png

 

Here is my setup (for the fun o it): I hoped to be able to use a pin of the IO BufferWing to be able to drive the display but this did not work.

out.thumb.jpg.a839e96b13066f69cc98429689b0ac40.jpg

 

Share this post


Link to post
Share on other sites

Hey, 

Did you have any luck with this? I was sick all last week so was not watching the forums very well. This is a question that Alvie can probably answer easily, but I think a search of the forum might answer it too... I seem to remember a post about this topic before.

Jack.

Share this post


Link to post
Share on other sites
8 hours ago, Jack Gassett said:

Hey, 

Did you have any luck with this? I was sick all last week so was not watching the forums very well. This is a question that Alvie can probably answer easily, but I think a search of the forum might answer it too... I seem to remember a post about this topic before.

Jack.

Hi,

I started looking into the code to try and understand the problem myself. the SPI master does have enough flags passed to the code

 e.g. spi_samprise is kinda taken into account to determine when to sample the signal (at rise or fall of the clock)

https://github.com/GadgetFactory/DesignLab_Examples/blob/master/libraries/ZPUino_Wishbone_Peripherals/COMM_zpuino_wb_SPI.vhd#L250

and (I think sets the do_sample correctly)

https://github.com/GadgetFactory/DesignLab_Examples/blob/master/libraries/ZPUino_Wishbone_Peripherals/spi.vhd#L81

However

https://github.com/GadgetFactory/DesignLab_Examples/blob/master/libraries/ZPUino_Wishbone_Peripherals/spi.vhd#L95

Will alway shift on the rising edge of the spi clock. I made small modifications trying to fix it but I am getting into trouble because I need to skip the first rising edge

e.g. if try to I skip the first rising edge all my data if off by one clock cycle.

Share this post


Link to post
Share on other sites

Let me take a look at that and I'll get back to you. Probably there's a bug there, I don't recall testing it with non-usual modes (it's also tricy to implement).

 

Alvie

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now