コード例 #1
0
ファイル: onewire.c プロジェクト: EtherGraf/ethersex
uint8_t noinline ow_read(uint8_t busmask)
{
    /* a read timeslot is sent by holding the data line low for
     * 1us, then wait approximately 14us, then sample data and
     * wait */
    /* this is also used as ow_write_1, as the only difference
     * is that the return value is discarded */

    OW_CONFIG_OUTPUT(busmask);
    OW_LOW(busmask);

    _delay_loop_2(OW_READ_TIMEOUT_1);

    OW_HIGH(busmask);
    OW_CONFIG_INPUT(busmask);

    _delay_loop_2(OW_READ_TIMEOUT_2);

    /* sample data now */
    uint8_t data = (uint8_t)(OW_GET_INPUT(busmask) > 0);

    /* wait for remaining slot time */
    _delay_loop_2(OW_READ_TIMEOUT_3);

    OW_CONFIG_OUTPUT(busmask);
    return data;
}
コード例 #2
0
ファイル: onewire.c プロジェクト: EtherGraf/ethersex
void noinline ow_write_0(uint8_t busmask)
{
    /* a write 0 timeslot is initiated by holding the data line low for
     * approximately 80us */

    OW_LOW(busmask);
    _delay_loop_2(OW_WRITE_0_TIMEOUT);
    OW_HIGH(busmask);
}
コード例 #3
0
ファイル: onewire.c プロジェクト: EtherGraf/ethersex
int8_t ow_temp_start_convert(ow_rom_code_t *rom, uint8_t wait)
{
    int8_t ret;

    if (rom == NULL)
        ret = ow_skip_rom();
    else {

        /* check for known family code */
        if (!ow_temp_sensor(rom))
            return -2;

        ret = ow_match_rom(rom);

    }

    if (ret < 0)
        return ret;

    /* transmit command byte */
    ow_write_byte(ONEWIRE_BUSMASK, OW_FUNC_CONVERT);

    OW_CONFIG_OUTPUT(ONEWIRE_BUSMASK);
    OW_HIGH(ONEWIRE_BUSMASK);

    if (!wait)
        return 0;

    _delay_ms(800); /* The specification say, that we have to wait at
                       least 500ms in parasite mode to wait for the
                       end of the conversion.  800ms works more reliably */

    while(!ow_read(ONEWIRE_BUSMASK));

    return 1;
}
コード例 #4
0
ファイル: onewire.c プロジェクト: ninharp/ethersex
uint8_t noinline
reset_onewire(uint8_t busmask)
{
  uint8_t data1, data2;
  ATOMIC_BLOCK(ATOMIC_RESTORESTATE)
  {
    /* pull bus low */
    OW_CONFIG_OUTPUT(busmask);
    OW_LOW(busmask);

    /* wait 480us */
    _delay_loop_2(OW_RESET_TIMEOUT_1);

    /* release bus */
    OW_CONFIG_INPUT(busmask);

    /* wait 60us (maximal pause) + 30 us (half minimum pulse) */
    _delay_loop_2(OW_RESET_TIMEOUT_2);

    /* sample data */
    data1 = OW_GET_INPUT(busmask);

    /* wait 390us */
    _delay_loop_2(OW_RESET_TIMEOUT_3);

    /* sample data again */
    data2 = OW_GET_INPUT(busmask);

    /* if first sample is low and second sample is high, at least one device
     * is attached to this bus */

    OW_HIGH(busmask);
    OW_CONFIG_OUTPUT(busmask);
  }
  return (uint8_t) (~data1 & data2 & busmask);
}