ich empfehle mal wieder das AVRco Manual zu lesen.
Code
program XMega_SLIP;
Device = XMega128A1, VCC=3.3;
{ $BOOTRST $20000} {Reset Jump to $20000}
Import SysTick, BeepPort, SLIPportC0, SLIPportC1, SLIPportD0, SLIPportD1;
From System Import ;
Define
// The XMegas don't provide any Oscillator fuses.
// So the application must setup the desired values
// possible OSC types: extXTAL, extClock, ext32kHz, int32Khz, int2MHz, int32MHz
//>> CPU=32MHz, PeripherX4=32MHz, PeripherX2=32MHz
OSCtype = int32MHz, PLLmul=4, prescB=1, prescC=1;
SysTick = 10; {msec}
StackSize = $0032, iData;
FrameSize = $0064, iData;
BeepPort = PortA, 0;
SLIPportC0 = 19200;
SLIPportCtrlC0 = PortA, 0, positive; // optional RS485 driver control
SLIPportC1 = 19200;
SLIPportCtrlC1 = PortA, 1, positive; // optional RS485 driver control
SLIPportD0 = 19200, Master; // onBoard local network
SLIPportD1 = 19200, Slave; // onBoard local network
Implementation
{$IDATA}
{--------------------------------------------------------------}
{ Type Declarations }
type
{--------------------------------------------------------------}
{ Const Declarations }
const
{--------------------------------------------------------------}
{ Var Declarations }
{$IDATA}
var
RxBuff : array[0..31] of byte;
TxBuff : array[0..31] of byte;
TxResultC0 : tSLIPstate;
RxResultC1 : tSLIPstate;
bc : boolean; // used to switch to broadcast
{--------------------------------------------------------------}
{ functions }
{--------------------------------------------------------------}
{ Main Program }
{$IDATA}
begin
// fill the Tx buffer with some data
TxBuff[0]:= $10;
TxBuff[1]:= $C0;
TxBuff[2]:= $11;
TxBuff[3]:= $DC;
TxBuff[4]:= $12;
TxBuff[5]:= $DB;
TxBuff[6]:= $13;
TxBuff[7]:= $DD;
TxBuff[8]:= $14;
SLIPsetTxAddrC0(01); // for the address mode
SLIPsetRxAddrC1(01);
SLIPsetModeC0([slpAddr, slpHsk, slpChkS]); // combine several modes
SLIPsetModeC1([slpAddr, slpHsk, slpChkS]);
SLIPsetTimeOutC0(10); // timeout used for handshake
SLIPsetTimeOutC1(10); // and frame failures
SLIPsetRxBufferC1(@RxBuff, sizeOf(RxBuff));
SLIPsetTxBufferC0(@TxBuff, 9);
// enable receive on portC1
SLIPresumeRxC1;
EnableInts($87);
loop
// here we switch between broadcast and unique address
if bc then
SLIPsetTxAddrC0($FF);
else
SLIPsetTxAddrC0(01);
endif;
// bc:= not(bc);
repeat
until SLIPstartTxC0;
// transmit a frame
repeat
TxResultC0:= SLIPgetTxStateC0;
until TxResultC0 <> SLIPbusy;
if TxResultC0 <> SLIPready then
BeepOut(800, 10);
endif;
// receive a frame
repeat
RxResultC1:= SLIPgetRxStateC1;
until RxResultC1 <> SLIPbusy;
// process the received data or the error
// ....
// ....
if RxResultC1 = SLIPready then
if SLIPwasBC_C1 then
BeepOut(800, 2);
else
BeepClick;
endif;
else
BeepOut(800, 10);
endif;
repeat
until SLIPresumeRxC1;
endloop;
end XMega_SLIP.