Jump to content
  • 0

WaveForms 3 SPI master


attila

Question

1 answer to this question

Recommended Posts

Yes. Here you have the script and attached the project:
// bit 0 - data, LSB first
// bit 1 - clk, sample on rising 
// bit 2 - select, active low
function setSPI(data, bits, hz){

   Patterns1.States.Repeat.value = 1
   Patterns1.States.RepeatTrigger.value = 0
   Patterns1.States.Run.value = (bits+1)/hz 
   // we need 2 samples for each SPI CLK
   Patterns1.Channels.Bus1.Frequency.value = 2*hz 

   var rg = new Array()
   rg.push(4) // select inactive high
   for(var i = 0; i < bits; i++, data>>=1){
      var f = data & 1
      rg.push(f) // set data 
      rg.push(f|2) // set clock
   }
   rg.push(4) // select inactive high
   Patterns1.Channels.Bus1._custom = rg
}

setSPI(0x8F, 8, 1000)
Patterns1.run()

PatternsSPI.png

PatternsSPI.dwf3work

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...