AN2681 Freescale Semiconductor / Motorola, AN2681 Datasheet - Page 10

no-image

AN2681

Manufacturer Part Number
AN2681
Description
1-Wire Interface on the i.MX21 Application Processor
Manufacturer
Freescale Semiconductor / Motorola
Datasheet
Program Source Code
}
int init_1wire(void) {
}
void write1 (void) {
}
void write0 (void) {
}
void read (uint8_t addr) {
10
}
// Send a reset pulse
*(p_uint16_t)OWIRE_CTRL = 0x0080;
// wait for RPP bit to clear
while ( (*(p_uint16_t)OWIRE_CTRL & 0x0080) != 0);
if ( (*(p_uint16_t)OWIRE_CTRL & 0x0040) == 0 ) {
}
// Send "Skip Net Address" Command (0xCC = 11001100)
write0(); write0(); write1(); write1();
write0(); write0(); write1(); write1();
return 1;
// write a 1 to the 1-wire data pin
*(p_uint16_t)OWIRE_CTRL |= 0x0010;
// wait until the transaction is complete
while ( (*(p_uint16_t)OWIRE_CTRL & 0x0010) != 0);
// write a 0 to the 1-wire data pin
*(p_uint16_t)OWIRE_CTRL |= 0x0020;
// wait until the transaction is complete
while ( (*(p_uint16_t)OWIRE_CTRL & 0x0020) != 0);
// Send the "Read" command (0x69 = 01101001)
write1(); write0(); write0(); write1();
write0(); write1(); write1(); write0();
// Send the address to read from
(addr & 0x01) ? write1() : write0();
printf("%f\n", volts_decode(voltage));
// clear the stopwatch interrupt
*(p_uint32_t)(RTC_RTCISR) |= 0x00000001;
// set the stopwatch to 5 mins again
*(p_uint32_t) RTC_STPWCH = 4;
printf("One-Wire Device not present.\n");
return 0;
Freescale Semiconductor, Inc.
For More Information On This Product,
MC9328MX21 Application Note
Go to: www.freescale.com
MOTOROLA

Related parts for AN2681