Shop OBEX P1 Docs P2 Docs Learn Events
Synchronous Serial Communication with External Clock — Parallax Forums

Synchronous Serial Communication with External Clock

nrk752nrk752 Posts: 8
edited 2006-06-30 18:33 in General Discussion
I am trying to communicate with an·IR temperature sensor which outputs synchronous serial data on one channel and a clock on another.· Both start high and pulse low.· The frequency of the data output is 2 kilohertz, with pulses of about 270 uS.· The sensor sends out bursts of·40 clock pulses and 40 bits of data about 10 times per second.· The problem is I can't seem to get the timing right to read the data.· The shiftIn function uses its own clock and operates too fast.· I tried just reading the pin logic and storing it in an array and then after the burst·converting that from binary to decimal, but it·doesn't work because reading the pins seems impossible to time well enough and do fast enough.· Any suggestions as how to read from this sensor?·

Comments

  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-06-30 18:33
    You can try the following:

    int clkInPin = CPU.pin0;
    int dataInPin = CPU.pin1;

    char[noparse]/noparse data = new char[noparse][[/noparse]5]; //40bits
    char dataIn;
    int byteCount,bitCount;

    for (byteCount=0; byteCount<5; byteCount++) {
    · for (bitCount=0; bitCount<8; bitCount++) {
    ··· while (CPU.readPin(clkInPin)) ; //wait for low
    ··· dataIn = (dataIn<<1) | (CPU.readPin(dataInPin) ? 1 : 0); //read bit
    ··· while (!CPU.readPin(clkInPin)) ;· //wait for high
    · }
    · data[noparse][[/noparse]byteCount] = dataIn;
    }

    The question is how to detect where the first byte starts.
    are there any timings that identify when the first bit is outputted?
    Also, are the bits outputted LSB or MSB first? Change the code
    if necessary.

    With pulsewidth of 270 uSec the javelin maybe just fast enough.
    If not, an external cascaded serial in shiftregister (5 of them for 40 bits)
    may be required.

    regards peter
Sign In or Register to comment.