Hello, I am trying to interface the Particle Photon board and a MS5540C barometric sensor. I need to generate a clock signal for the sensor board at 32 kHz. Is this possible with the Photon board and how would I go about doing that? Using GPIO?
Tried tone() but that has a limit of 20 kHz.
You could use the Spark Interval Timer library. That library allows sub- millisecond timers. I was playing around with it the other night. I don’t know what kind of precision that library offers though. Maybe @peekay123 can comment on using that library for what you are trying to do.
@youmster, the specs call for an MCLK frequency of 30KHz to 35KHz with no specific requirement for a 32.768Hz frequency. As such, you could use SparkIntervalTimer but at 16us to produce a half period, interrupt latency may become an issue. Instead, as @ScruffR pointed out, you should be able to use a PWM output set for 50% duty cycle.
I went through the datasheet. The protocol reminded me of SPI. Why not use the SPI protocol to communicate with your device? It’s already integrated in the Photon.
I googled “MS5540C SPI” it and found an interresting article https://www.amsys.info/sheets/amsys.en.an510_e.pdf
Thanks all for the help! This helped make a breakthrough. We ended up stting the PWM freq to 32kHz awith a 50% duty cycle. Looks like it’s working like a charm!
Nope, SPI is meant to support multiple devices which can be explicitly selected via the dedicated CS (chip select) or SS (slave select) pins, which need to be pulled LOW for max. one and only one slave at any given time.
If a save does not see its own SS pin pulled LOW it has to stay silent and should also ignore any data transmitted over the bus.
@youmster, what @ScruffR says is right. However, anytime you have more than one of those sensors on the bus, you will need to add tri-state buffers on the MISO line since the MS5540C does not tri-state that line by itself. All SPI devices must tri-state their data lines when not selected but that is not always the case with many devices.