News:

;) This forum is the property of Proton software developers

Main Menu

sample code for shin and shout in mode slave

Started by Pepe, Mar 18, 2025, 11:52 PM

Previous topic - Next topic

Pepe

Since I don't know if shin and shout can work in slave mode, I give an example
to replace the two functions with code so that they can be used in slave mode
so that they do not generate clock and use the master's clock


'SHOut SDA, SCL, 5,[DataValue\16]
                         
'Serial Send DataValue (16 bits)                       

Proc Shout_Slave (Datavalue as word)                         

Dim index as byte

  PinOutput SDA
  For index = 15 To 0 Step -1
    SDA = DataValue.0 
    While SCL = 1 : Wend     
    DataValue = DataValue >> 1
    While SCL = 0 : Wend     
  Next
  PinInput SDA
EndProc
 

'SHIn SDA, SCL, 5, [RegAddr\8]
 
'Serial Read bdata (8 bits)

Proc Shin_Slave (),byte

Dim bdata as byte = 0
Dim index as byte   
 
    For index = 7 To 0 Step -1
    bdata = bdata << 1
    While SCL = 1 : Wend 
    bdata.0 = SDA     
    While SCL = 0 : Wend               
    Next
    result = bdata
EndProc


Pepe


tumbleweed

In actual use getting that to be at all reliable would be a real trick. It would rely on the slave to operate much faster than the master, and to always be ready to accept communications with the master.

Pepe

I think you're wrong it was just a demonstration of being able to use the shin and shout functions as a slave and as you can see in the next demo you can also use interrupts

top204

It is feasible to create a software SPI slave interface, as I did it for I2C, many years ago, and it worked quite well.

To trigger the software pin toggle detections for the SPI slave, an INTx can be used, so a low on the CS line will fire an interrupt, and the interrupt will receive the bits based upon the clock, until the CS line is brought high again etc...

All SPI interfaces have a speed limit of some sort, so a bit-bashed SPI slave would have a lower bandwidth, but on a device that has no SPI slave capabilities, it would be useful, and very creative. I've even seen USB tranceivers using bit-bashing on some devices, so HID can be implemented on a device that does not have USB capabilities.

Pepe

Another example with simulation in proteus for 2 slaves without using shin and shout