User manual
374
mikoPascal PRO for PIC32
MikroElektronika
U2RXIF_bit := 0; // ensure interrupt not pending
end;
begin
CHECON := 0x32;
AD1PCFG := 0xFFFF;
TRISB := 0;
TRISD := 0;
PORTB := 0;
PORTD := 0;
UART2_Init(19200); // initialize UART2 module
Delay_ms(100);
RS485Slave_Init(160); // Intialize MCU as slave, address 160
dat[0] := 0xAA;
dat[1] := 0xF0;
dat[2] := 0x0F;
dat[4] := 0; // ensure that message received ag is 0
dat[5] := 0; // ensure that error ag is 0
dat[6] := 0;
U2IP0_bit := 1; // set interrupt
U2IP1_bit := 1; // priority
U2IP2_bit := 1; // to 7
URXISEL1_U2STA_bit := 0; // 0x = Interrupt ag bit is set when a character is
received
U2RXIF_bit := 0; // ensure interrupt not pending
MVEC_bit := 1; // Interrupt controller congured for multi vectored mode
asm
ei R0; // Enable all interrupts
end;
U2RXIE_bit := 1; // enable intterupt
while (TRUE) do
begin
if (dat[5] <> 0) then // if an error detected, signal it by
begin
PORTD := 0xAA; // setting portd to 0xAA
dat[5] := 0;
end;
if (dat[4] <> 0) then // upon completed valid message receive
begin
dat[4] := 0; // data[4] is set to 0xFF
j := dat[3];
for i := 1 to dat[3] do // show data on PORTB
PORTB := dat[i-1];
dat[0] := dat[0]+1; // increment received dat[0]
Delay_ms(1);
RS485Slave_Send(dat,1); // and send it back to master
end;
end;
end.