Datasheet
ADuC7033
Rev. B | Page 128 of 140
Example LIN Hardware Synchronization Routine
Consider the following C-Source Code LIN initialization routine.
void LIN_INIT(void )
{
char HVstatus;
GPCON = 0x110000; // Enable LHS on GPIO pins
LHSCON0 = 0x1; // Reset LHS interface
do{
HVDAT = 0x02; // Enable normal LIN TX mode
HVCON = 0x08; // Write to Config0
do{
HVstatus = HVCON;
}
while(HVstatus & 0x1);// Wait until command is finished
}
while (!(HVstatus & 0x4)); // Transmit command is correct
while((LHSSTA & 0x20) == 0 )
{ // Wait until the LHS hardware is reset
}
LHSCON1 = 0x062; // Sets Stop Edge as the fifth falling edge
// and the Start Edge as the first falling
// edge in the sync byte
LHSCON0 = 0x0114; // Gates UART RX line, ensure no interference
// from the LIN into the UART
// Selects the stop condition as a falling edge
// Enables generation of an Interrupt on the
// stop condition
// Enables the interface
LHSVAL1 = 0x03F; // Set number of 131 kHz periods to generate
// a break interrupt 0x3F / 131 kHz ~ 480 μs
// which is just over 9.5 tbits
}
Using this configuration, LHSVAL1 begins to count on the first
falling edge received on the LIN bus. If LHSVAL1 exceeds the
value written to LHSVAL1, in this case 0x3F, a break compare
interrupt is generated.
On the next falling edge, LHSVAL0 begins counting. LHSVAL0
monitors the number of falling edges and compares this to the
value written to LHSCON1[7:4]. In this example, the number of
edges to monitor is the sixth falling edge of the LIN frame, or
the fifth falling edge of the sync byte. When this number of
falling edges is received, a stop condition interrupt is generated.
It is at this point that the UART is configured to receive the
protected identifier.
The UART must not be ungated (through LHSCON0[8]) before
the LIN bus returns high. If this occurs, UART communication
errors can occur. This process is shown in detail in Figure .
Example code to ensure this is as follows: