SPI MODE0


keesj

Recommended Posts

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

 

Link to comment
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.

Link to comment
Share on other sites

  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.