AN2681 Freescale Semiconductor / Motorola, AN2681 Datasheet - Page 12

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
}
float temp_decode(uint16_t temperature) {
}
float acc_curr_decode(int16_t acc_curr) {
}
/************************************************************/
/***************** END OF FILE ******************************/
4.2.1 Reusability of 1-Wire Code
Communication with any 1-Wire device requires sending an initial reset pulse, subsequently, all devices
on the 1-Wire bus respond with a presence pulse. After the detection of a presence pulse, the net address
command is sent by the i.MX21. The net address command may be one of the four enumerated in Section
1.2, on page 2. All 1-Wire devices must follow this handshaking procedure to ensure proper
communication with the bus master. Therefore, the device detection and addressing portions of the code,
along with the i.MX21 setup and control code, can be reused for other 1-Wire devices.
After the handshaking procedure has successfully completed, and communication between the i.MX21
processor and the slave device has been established, the i.MX21 issues a function command (such as read
the voltage register on the DS2751). This command can be unique to each 1-Wire device. Code Sample 2
(main.c), presented above, must be modified accordingly.
12
int coded_temp;
float decoded_temp;
coded_temp = temperature >> 5;
// check sign bit, front fill with 1's if negative
if (temperature & 0x8000)
// units are .125 deg C -> convert to deg C
decoded_temp = coded_temp * .125;
return decoded_temp;
int coded_acc_curr;
float decoded_curr;
coded_acc_curr = acc_curr >> 3;
if (acc_curr & 0x8000)
// units are 6.25 uV, convert to mA given 25 mohm resistor
decoded_curr = coded_acc_curr * 6.25 / 1000 / 25;
return decoded_curr;
coded_temp |= 0xFFFFF800;
coded_acc_curr |= 0xFFFFE000;
Freescale Semiconductor, Inc.
For More Information On This Product,
MC9328MX21 Application Note
Go to: www.freescale.com
MOTOROLA

Related parts for AN2681