Dear sir,
I want to configure Aduc7039 board as the LIN slave. and i want to transmit and receive the data as per the command sent by the master.
for example i am having 3 frames of PID 0x11, 0x12,0x13, so i want to transmit appropriate data when ever master requests for the data. i was able to do it with aduc7033 but not able to get it correctly with aduc7039. can you please send me example code to do the above, and another thing the data sent should be in LIN format menace we have to even calculate check-sum and should transmit it also.
the below code is for aduc7033 sent by one of your Engg Zone people. please send me the code with same functionalists as the below code for aduc7039 controller
#include<ADuC7033.h>
#define LIN_Slave_Address 0x24 // Slave Address for IV Result
void LIN_TX(unsigned char *Data_To_Tranmist,int Number_of_Bytes);
void LIN_INIT(void);
void My_FIQ_Function(void) ;
int main()
{
volatile unsigned long it1,it2;
it1 = 0x1234;
it2 = 0x4321;
FIQ = My_FIQ_Function; // Initialise Interrupt Routine
while((PLLSTA&0x2) ==0) // Ensure That thePLL is locked to the 3%
{}
LIN_INIT();
// Enables the interface
// Configure Interrupts
FIQEN = 0x80; // Generate a FIQ on:
// LIN Hardware SYNC System
/* POWKEY0 = 0x1; // Put all peripherals, PLL and Core Asleep
POWCON = 0x01;
POWKEY1 = 0xf4;
it1 = it1*it2; // Dummy cycle to ensure correct power down
*/
// Configure the ADC for range IADC_RANGE
while(1) // Infinite Loop
}
void LIN_INIT(void )
char HVstatus;
// Enable LHS on GPIO Pins
GP2CON = 0x110000;
LHSCON0 = 0x1; // Reset LHS Interface
do{ // Enable LIN
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.
LHSVAL1 = 0x030; // Set number of 131kHz periods to generate a Break Interrupt
// 0x3F / 131kHz ~ 480us which is just over 9.5 TBits.
// According to LIN V2.0, a slave with a clock accuracy of <2% may
// use a break detection of 9.5 bit, otherwise a break detection of
// 11 bits is required
// This is for 19200bps
void My_FIQ_Function()
int iFIQ_Source,itemp,iDL,iDL_Power,iDL_temp;
unsigned char Data_To_Tranmist[8];
iFIQ_Source = FIQSTA; // Save a temporary copy of IRQSTA
if ( ( iFIQ_Source & 0x80) !=0) // LIN Interrupt
itemp = LHSSTA;
if ((itemp & 0x1 ) != 0 ) // LIN Break Symbol
if ((itemp & 0x2 ) != 0 ) // LIN Start Condition
if ((itemp & 0x4 ) != 0 ) // LIN Stop Condition
// Configure UART
// DL = LHSVAL0 >> CD_Bits + 6
// For explanation please refer to technote
iDL = LHSVAL0 >> (( POWCON & 0x7)+6);
iDL_Power = 0;
iDL_temp = iDL;
while(iDL >> (iDL_Power +1 ))
iDL_Power++;
// If using the fractional divider:
iDL_temp = iDL_Power + (POWCON & 0x7);
if ( iDL_temp > 5 )
iDL_temp= (LHSVAL0 >> ( iDL_temp -5 )) - 2048;
else
iDL_temp= (LHSVAL0 << (5 - iDL_temp )) - 2048;
COMDIV2 = 0x8800 + iDL_temp;
COMCON0 = 0x080; // Set DLAB
// Setting DIV0 and DIV1 to DL calculated
COMDIV0 = (1<< iDL_Power ) & 0xff;
COMDIV1 = (1<< iDL_Power ) & 0xff00;
COMCON0 = 0x03; // Clear DLAB
COMIEN0 = 0x1; // Enable RX interrupt only
while((GP2DAT & 0x10 ) == 0 )
LHSCON0 = 0x4; // Enable LHS to detect Break Condition
// Ungate RX Line
// Disable all interrupts, less Break
FIQEN = 0x800; // Enable UART Interrupts
// The UART is now configured and ready to be used for LIN
if ( ( iFIQ_Source & 0x800) !=0) // UART Interrupt
// Remember, each time you transmit a byte, you will also receive
// it as the LIN bus connects TX and RX
FIQCLR = 0x800; // Disable UART Interrupts
itemp = ( COMRX & 0x3f ); // Do not care about Parity bits
if ( itemp == LIN_Slave_Address )
Data_To_Tranmist[0] = 0x11;
Data_To_Tranmist[1] = 0xff; // TX LSB of last V reading
Data_To_Tranmist[2] = 0x22; // TX MSB of last I reading
Data_To_Tranmist[3] = 0x33; // TX LSB of last I reading
Data_To_Transmit[4] = 0x45;
Data_To_Transmit[4] = 0x68;
LIN_TX(Data_To_Tranmist,4);
LIN_INIT(); // Re initialise LHS
return;
void LIN_TX(unsigned char *Data_To_Tranmist,int Number_of_Bytes)
int i = 0,itemp;
unsigned short LIN_Classic_CS = 0;
for ( i = 0 ; i < Number_of_Bytes; i++)
LIN_Classic_CS += Data_To_Tranmist[i]; // Add the data to the CS
if ( LIN_Classic_CS > 256 )
LIN_Classic_CS -= 255; // If the cehckusm is greater than 256, subtract 255
COMTX = Data_To_Tranmist[i]; // Place data into COMTX buffer
itemp = 0xfff;
while ( (Data_To_Tranmist[i]&0xff) != itemp ) // Wait until data is recieved on LINRX path
while(!(0x01==(COMSTA0 & 0x01)))
itemp = COMRX;
LIN_Classic_CS = ((~LIN_Classic_CS)&0xff); // Invert Checksum and transmit
COMTX = LIN_Classic_CS;
while ( LIN_Classic_CS != itemp ) // Wait until data is recieved on LINRX path
Regards
Naga Venu
Hi Naga,
Find attached some simple LIN slave code,
the LIN slave will reply to any PID sent by the LIN master.
I hope this helps
Holger