Hi,
I use mc9s08dz96.To send data in the form of the LIN protocol, I have set the CodeWarrior settings to asynchronous mode. According to the frame LIN protocol, I have defined and sent the data.
This is my data:
byte break_1={0x00};
byte break_2={0x00};
byte Sync_={0x55};
byte ID_={0x11};
byte data1={0x80};
byte data2={0x29};
byte chsum={0x56};
Then in main I sent these data:
AS1_Init();
Enable_Lin = 1;
while(1){
c=AS1_SendChar(break_1);
c=AS1_SendChar(break_2);
c=AS1_SendChar(Sync_);
c=AS1_SendChar(ID_);
c=AS1_SendChar(data1);
c=AS1_SendChar(data2);
c=AS1_SendChar(chsum);
delayy(5000);
}
Data sending function is:
byte AS1_SendChar(AS1_TComData Chr)
{
if (!EnMode) { /* Is the device disabled in the actual speed CPU mode? */
return ERR_SPEED; /* If yes then error */
}
if (SCI1S1_TDRE == 0U) { /* Is the transmitter full? */
return ERR_TXFULL; /* If yes then error */
}
SCI1D = (byte)Chr; /* Store char to the transmitter register */
return ERR_OK; /* OK */
}
Now, 010 is added between each byte of data that I send with the above codes, which causes the receiving device to misread the data. What do you suggest to remove this 010?
The file is attached.
Best regards
Thank you so much for your kind reply.
I think that my problem is the synchronizing the S08’s Internal Clock for LIN or registers. But I set these.
This is my init function:
void AS1_Init(void)
{
/* SCI1C1: LOOPS=1,SCISWAI=0,Rsrc=1,M=0,WAKE=1,ILT=1,PE=0,PT=0 */
setReg8(SCI1C1, 0xACU); /* Configure the SCI */
/* SCI1C3: R8=0,T8=0,TXDIR=1,TXINV=0,ORIE=0,NEIE=0,FEIE=0,PEIE=0 */
setReg8(SCI1C3, 0x20U); /* Disable error interrupts */
/* SCI1C2: TIE=0,TCIE=0,RIE=0,ILIE=0,TE=0,RE=0,RWU=0,SBK=0 */
setReg8(SCI1C2, 0x00U); /* Disable all interrupts */
/* SCI1S2: LBKDIF=0,RXEDGIF=0,??=0,RXINV=0,RWUID=0,BRK13=1,LBKDE=0,RAF=0 */
setReg8(SCI1S2, 0x04U);
AS1_SetHigh(); /* Initial speed CPU mode is high */
}
and I have this function:
static void HWEnDi(void)
{
if (EnMode) { /* Enable device? */
SCI1BDH = 0x00U; /* Set high divisor register (enable device) */
SCI1BDL = 0x1AU; /* Set low divisor register (enable device) */
SCI1C2_TE = 0x01U; /* Enable transmitter */
SCI1C2_RE = 0x01U; /* Enable receiver */
} else {
SCI1C2_RE = 0x00U; /* Disable receiver */
SCI1C2_TE = 0x00U; /* Disable transmitter */
SCI1BDH = 0x00U; /* Set high divisor register to zero (disable device) */
SCI1BDL = 0x00U; /* Set low divisor register to zero (disable device) */
}
}
Is it possible for you to view the file I have attached? I really appreciate it.
PLease check the LIN stack
Also check the application note
https://www.nxp.com/docs/en/application-note/AN3756.pdf