I made your function change, Gordon, but I'm getting pretty much the same results.
I see what you are trying to do with using mosi to send data as clock ticks. However, when I dig into it, it doesn't look to be very "clock like". I hooked it up to a scope, and here's what I'm seeing:
The yellow on the bottom is the actual spi clock (sck), and the cyan on the top is your mosi 0b10101010 data. If you were to scroll rightward along time, you'd see 6 of those 0b10101010 waveforms followed by the finalClk. This image only captures the first two bytes. A few things to note:
1) There appears to be a 30 microsecond spacing between each byte of data transmitted.
2) mosi appears to be normally high between bytes, which appears to result in a very long clock tick between each 0b10101010.
3) Since the mosi signal is normally high, that very first "1" tick probably doesn't count since it was already at 1, and thus didn't go from 0 to 1, which might be why all the bits are shifted over by one resulting in the data reporting back as 2x the actual value. Yup, I just verified this by changing your 0b10101010 to 0b01010101, and the 2x multiplier went away.
You probably have some additional tricks up your sleeve which I'm more than happy to try. In the mean time, If you are okay with it, I'd like to modify your module to use hardware SPI1, and to use the actual SPI clock to send the 24 ticks. It seems to work great even though, as you say, the data sheet doesn't specify what 24 clocks does. It also doesn't allow one to change the gain, etc., but it's very stable and seems to work really well with whatever gain 24 clocks is resulting in...
© Espruino, powered by microcosm.
Report a problem