Привожу пример кода для STM32, вроде все должно работать
Код
u32 OWReset(void)
{
u8 command;
u8 status;
u32 poll_count = 0;
// 1-Wire reset (Case B)
// S AD,0 [A] 1WRS [A] Sr AD,1 [A] [Status] A [Status] A\ P
// \--------/
// Repeat until 1WB bit has changed to 0
// [] indicates from slave
command = CMD_1WRS;
while (I2C_GetFlagStatus(I2C1, I2C_FLAG_BUSY));
I2C_Master_BufferWrite(I2C_address, &command, 1);
// loop checking 1WB bit for completion of 1-Wire operation
// abort if poll limit reached
do
{
while (I2C_GetFlagStatus(I2C1, I2C_FLAG_BUSY));
status = I2C_Master_BufferRead1Byte(I2C_address);
}
while ((status & STATUS_1WB) && (poll_count++ < POLL_LIMIT));
// check for failure due to poll limit reached
if (poll_count >= POLL_LIMIT)
{
DS2482_reset();
return FALSE;
}
// check for short condition
if (status & STATUS_SD)
short_detected = TRUE;
else
short_detected = FALSE;
// check for presence detect
if (status & STATUS_PPD)
return TRUE;
else
return FALSE;
}
{
u8 command;
u8 status;
u32 poll_count = 0;
// 1-Wire reset (Case B)
// S AD,0 [A] 1WRS [A] Sr AD,1 [A] [Status] A [Status] A\ P
// \--------/
// Repeat until 1WB bit has changed to 0
// [] indicates from slave
command = CMD_1WRS;
while (I2C_GetFlagStatus(I2C1, I2C_FLAG_BUSY));
I2C_Master_BufferWrite(I2C_address, &command, 1);
// loop checking 1WB bit for completion of 1-Wire operation
// abort if poll limit reached
do
{
while (I2C_GetFlagStatus(I2C1, I2C_FLAG_BUSY));
status = I2C_Master_BufferRead1Byte(I2C_address);
}
while ((status & STATUS_1WB) && (poll_count++ < POLL_LIMIT));
// check for failure due to poll limit reached
if (poll_count >= POLL_LIMIT)
{
DS2482_reset();
return FALSE;
}
// check for short condition
if (status & STATUS_SD)
short_detected = TRUE;
else
short_detected = FALSE;
// check for presence detect
if (status & STATUS_PPD)
return TRUE;
else
return FALSE;
}
Заранее благодарен за любую помощь! Она нужна как воздух, срочно!