Beispiel #1
0
static uint16_t sht_readw(void)
{
    uint8_t i;
    uint16_t r = 0;

    sda_input();

    for(i = 0; i < 8; i++) {
        scl_high();
        r |= sda_get()?(1<<i):0;
        scl_low();
    }

    sda_output();
    sda_set(0);
    scl_high();
    scl_low();
    sda_input();

    for(i = 8; i < 16; i++) {
        scl_high();
        r |= sda_get()?(1<<i):0;
        scl_low();
    }

    return r;
}
Beispiel #2
0
static void sht_sendb(uint8_t cmd)
{
    uint8_t i;

    sda_output();

    for(i = 0; i < 8; i++) {
        scl_low();
        sda_set((cmd>>i)&1);
        scl_high();
    }

    scl_low();
    sda_input();
    printf("foo!\n");
    while(sda_get());
    scl_high();
    scl_low();

    printf("bar!\n");
    while(!sda_get());

    printf("bla!\n");
    i = 0;
    while(sda_get()) {
        i++;
        if(i == 255) break;

        usleep(10*1000);
    }
}
Beispiel #3
0
//------------------------------------------------------------------------
static unsigned int i2c_write_byte ( unsigned int b )
{
    unsigned int ra;
    for(ra=0x80;ra;ra>>=1)
    {
        i2c_delay();
        if(ra&b) sda_high();
        else     sda_low();
        i2c_delay();
        scl_high();
        i2c_delay();
        scl_low();
        i2c_delay();
        sda_low();
        i2c_delay();
    }
    i2c_delay();
    sda_input();
    i2c_delay();
    scl_high();
    i2c_delay();
    ra=sda_read();
    i2c_delay();
    scl_low();
    i2c_delay();
    sda_output();
    i2c_delay();
    return(ra);
}
Beispiel #4
0
void sht_start(void)
{
    sda_output();

    sda_set(0);
    scl_low();
    scl_high();
    sda_set(1);
    scl_low();
}