Дабы не начинать новую тему. Много уже сказано про 1-Wire, но сегодня, изучая апноут от Atmel нашел следующий фрагмент:
Код
/*! \brief Read the temperature from a DS1820 temperature sensor.
*
* This function will start a conversion and read back the temperature
* from a DS1820 temperature sensor.
*
* \param bus A bitmask of the bus where the DS1820 is located.
*
* \param id The 64 bit identifier of the DS1820.
*
* \return The 16 bit signed temperature read from the DS1820.
*/
signed int DS1820_ReadTemperature(unsigned char bus, unsigned char * id)
{
signed int temperature;
// Reset, presence.
if (!OWI_DetectPresence(bus))
{
return DS1820_ERROR; // Error
}
// Match the id found earlier.
OWI_MatchRom(id, bus);
// Send start conversion command.
OWI_SendByte(DS1820_START_CONVERSION, bus);
// Wait until conversion is finished.
// Bus line is held low until conversion is finished.
while (!OWI_ReadBit(bus))
{
}
// Reset, presence.
if(!OWI_DetectPresence(bus))
{
return -1000; // Error
}
// Match id again.
OWI_MatchRom(id, bus);
// Send READ SCRATCHPAD command.
OWI_SendByte(DS1820_READ_SCRATCHPAD, bus);
// Read only two first bytes (temperature low, temperature high)
// and place them in the 16 bit temperature variable.
temperature = OWI_ReceiveByte(bus);
temperature |= (OWI_ReceiveByte(bus) << 8);
return temperature;
}
Смутивший меня фрагмент
// Wait until conversion is finished.
// Bus line is held low until conversion is finished.
while (!OWI_ReadBit(bus))
{}Далее привожу предлагаемую функцию чтения бита.
Код
/*! \brief Read a bit from the bus(es). (Software only driver)
*
* Generates the waveform for reception of a bit on the 1-Wire(R) bus(es).
*
* \param pins A bitmask of the bus(es) to read from.
*
* \return A bitmask of the buses where a '1' was read.
*/
unsigned char OWI_ReadBit(unsigned char pins)
{
unsigned char intState;
unsigned char bitsRead;
// Disable interrupts.
intState = __save_interrupt();
__disable_interrupt();
// Drive bus low and delay.
OWI_PULL_BUS_LOW(pins);
__delay_cycles(OWI_DELAY_A_STD_MODE);
// Release bus and delay.
OWI_RELEASE_BUS(pins);
__delay_cycles(OWI_DELAY_E_STD_MODE);
// Sample bus and delay.
bitsRead = OWI_PIN & pins;
__delay_cycles(OWI_DELAY_F_STD_MODE);
// Restore interrupts.
__restore_interrupt(intState);
return bitsRead;
}
Разве не должна "шина" оставаться в единичке на момент конверсии??