AN2681 Freescale Semiconductor / Motorola, AN2681 Datasheet - Page 9

no-image

AN2681

Manufacturer Part Number
AN2681
Description
1-Wire Interface on the i.MX21 Application Processor
Manufacturer
Freescale Semiconductor / Motorola
Datasheet
#include "testcase.h"
/* Modify SysInit() for different system initialization settings */
extern int SysInit(void);
extern int MemInit(void);
/****************************************************************
# D E F I N E S
****************************************************************/
/*****************************************************************
*****************************************************************/
int init_1wire(void);
void write1(void);
void write0(void);
void read(uint8_t addr);
uint16_t receive(void);
float volts_decode(uint16_t volts);
float temp_decode(uint16_t temp);
float acc_curr_decode(int16_t acc_curr);
int32_t main(void)
{
MOTOROLA
Public Functions
uint16_t voltage, temperature, acc_current;
SysInit();
MemInit();
// enable the stopwatch interrupt
*(p_uint32_t)(RTC_RTCIENR) = 0x00000001;
// enable the RTC in the PCCR1
*(p_uint32_t)(CRM_PCCR1) |= 0x20000000;
// set the time dividor=44-1 to produce a ~1 MHz clock
*(p_uint16_t)OWIRE_TIME_DIV = 0x002B;
// set the stopwatch to 5 mins
*(p_uint32_t) RTC_STPWCH = 4;
while (1) {
// wait for stopwatch interrupt
while ((*(p_uint32_t)(RTC_RTCISR) & 0x00000001) != 0x00000001);
// initialize communication with 1-wire device
if (init_1wire() == 0 )
// read from voltage register
read(0x0C);
// Receive voltage register MSB & LSB from DS2751
voltage = receive();
return -1;
Freescale Semiconductor, Inc.
For More Information On This Product,
MC9328MX21 Application Note
Go to: www.freescale.com
Program Source Code
9

Related parts for AN2681