AN2681 Freescale Semiconductor / Motorola, AN2681 Datasheet - Page 7

no-image

AN2681

Manufacturer Part Number
AN2681
Description
1-Wire Interface on the i.MX21 Application Processor
Manufacturer
Freescale Semiconductor / Motorola
Datasheet
4 Program Source Code
The following code configures the i.MX21 application processor 1-Wire interface, and reads the value
from the DS2751 voltage register every five minutes. The Battery_Gauge_1-Wire_Test.mcp file contains
all the supporting software necessary to run this code on an i.MX21L ADS or EVB. The file was created
in the Metrowerks CodeWarrior IDE.
4.1 Configuration Code
The SysInit() function, found in the file SysInit.c, performs the necessary configuration of the PLLs and
GPIO port E as noted in section 3. It initializes the MPLL to 266 MHz, with a PRESC divide factor of 1,
and an IPDIV divide factor of 2, resulting in a 44.3 MHz IPG_CLOCK.
void SysInit(void)
{
MOTOROLA
// initialize PLL and clocks here
// Set up the MPLL for 266.0000537MHz
// PD = 0; MFI = 7; MFN = 115; MFD = 123
*(p_uint32_t)CRM_MPCTL0 = 0x007B1C73;
*(p_uint32_t)CRM_MPCTL1 = 0x00000040;
// Set up the SPLL for 287.9999978Mhz operation
*(p_uint32_t)CRM_SPCTL0 = 0x03B02227;
// now configure the CSCR register
// clear all bits except for PRESC
*(p_uint32_t)CRM_CSCR &= 0x0000C000;
// Now set USBDIV=5; SD_CNT=3; BCLKDIV=2; IPDIV=1; HCLK will be 88.6MHz
// IPG_CLOCK = HCLK / (IPDIV+1) => IPG_CLOCK will be 44.3 MHz
*(p_uint32_t)CRM_CSCR |= 0x17000A07;
// Last step, clear PRESC to 0
*(p_uint32_t)CRM_CSCR &= 0xFFFF3FFF;
// Now, restart the PLLs
*(p_uint32_t)CRM_CSCR |= 0x00600000;
// Wait for lock flag to set
while((*(p_uint32_t)CRM_MPCTL1 & 0x00008000) != 0x00008000);
while((*(p_uint32_t)CRM_SPCTL1 & 0x00008000) != 0x00008000);
// enable the following in the PCCR0
// HCLK_DMA, LCDC, LCDC_PIXCLK, DMA_EN, GPIO_EN
*(p_uint32_t)CRM_PCCR0 |= 0x44042800;
/* Enable 1-Wire Bus */
// Configure GPIO pin for 1-Wire use
*(p_uint32_t)GPIOE_GIUS &= 0xFFFEFFFF;
*(p_uint32_t)GPIOE_GPR |= 0x00010000;
// enable the ipg_clock to 1-Wire interface
*(p_uint32_t)CRM_PCCR1 |= 0x80000000;
// Configure AIPI for 16 bit 1-Wire communication
*(p_uint32_t)AIPI1_PSR0 |= 0x00000200;
// set BRMO since 1/10 < MFN/MFD+1 < 9/10
Freescale Semiconductor, Inc.
For More Information On This Product,
Code Example 1.
MC9328MX21 Application Note
Go to: www.freescale.com
SysInit()
Program Source Code
7

Related parts for AN2681