Pic32Mz Interrupt

General discussion on mikroPascal PRO for PIC32.
Post Reply
Author
Message
Dany79
Posts: 12
Joined: 11 Jun 2015 15:39
Location: Canada

Pic32Mz Interrupt

#1 Post by Dany79 » 24 Dec 2020 21:40

Hello, I am trying to use the serial ports with the interruptions.

At startup, the mcu initializes the ip address with DHCP and the interrupt for timer1 work and the RBA.14 led flashes.

I'm able to ping the device on the network.

If i send one char on the uart1 the mcu hang on the uart1rx interrupt. the timer1 and network stop working.
Attachments
IRQ test.rar
(261.72 KiB) Downloaded 62 times

Dany79
Posts: 12
Joined: 11 Jun 2015 15:39
Location: Canada

Re: Pic32Mz Interrupt

#2 Post by Dany79 » 27 Dec 2020 21:23

when i send one bit on U1 rx pin the u1rxInt() is exexuted one time but u5rxInt() seem to loop

yo2lio
Posts: 1878
Joined: 19 Sep 2006 12:57
Location: Romania, Arad City
Contact:

Re: Pic32Mz Interrupt

#3 Post by yo2lio » 20 Jan 2021 17:26

Hello Dany,

I have a lot's of software with multiple Uart interrupts on PIC32MZ and all works.

True, all are on priority 7, I didn't was able to change the priority and to work...

Code: Select all

procedure Int_ovf_UART;  // must be called at 1 ms
begin
  if inc(UART1_ovf) > UART1_Timeout then // UART1_Timeout ms
    begin
      UART1_ovf := 0;
      if UART1_len <> 0 then UART1_data_available := true;
    end;
  if inc(UART2_ovf) > UART2_Timeout then // UART2_Timeout ms
    begin
      UART2_ovf := 0;
      if UART2_len <> 0 then UART2_data_available := true;
    end;
  if inc(UART3_ovf) > UART3_Timeout then // UART3_Timeout ms
    begin
      UART3_ovf := 0;
      if UART3_len <> 0 then UART3_data_available := true;
    end;
end;

procedure UART1Interrupt(); iv IVT_UART1_RX; ilevel 7; ics ICS_SRS;
label next1;
begin
next1:
  UART1_buf[UART1_len] := UART1_Read;
  if inc(UART1_len) > 511 then UART1_len := 511;
  UART1_ovf := 0;
  if U1STA.URXDA <> 0 then goto next1;
  U1RXIF_bit := 0;
  if U1STA.OERR <> 0 then U1STA.OERR := 0;
end;

procedure UART2Interrupt(); iv IVT_UART2_RX; ilevel 7; ics ICS_SRS;
label next2;
begin
next2:
  LED := 1;
  UART2_buf[UART2_len] := UART2_Read;
  if inc(UART2_len) > 2599 then UART2_len := 2599;
  UART2_ovf := 0;
  if U2STA.URXDA <> 0 then goto next2;
  U2RXIF_bit := 0;
  if U2STA.OERR <> 0 then U2STA.OERR := 0;
end;

procedure UART3Interrupt(); iv IVT_UART3_RX; ilevel 7; ics ICS_SRS;
label next3;
begin
next3:
  LED := 1;
  UART3_buf[UART3_len] := UART3_Read;
  if inc(UART3_len) > 511 then UART3_len := 511;
  UART3_ovf := 0;
  if U3STA.URXDA <> 0 then goto next3;
  U3RXIF_bit := 0;
  if U3STA.OERR <> 0 then U3STA.OERR := 0;
end;

procedure Timer1Interrupt(); iv IVT_TIMER_1; ilevel 7; ics ICS_SRS;
begin
  T1IF_bit := 0;
  Int_ovf_UART;
  CounterTask;  // must be called at 1ms
  if inc(CC10ms) > 9 then
    begin
      CC10ms := 0;
      inc(sysUpTime);
    end;
  if inc(count_led) > 99 then
    begin
      count_led := 0;
//      LED1 := not LED1;
      inc(cc1);
      inc(cc2);
    end;
  Int_ovf_UART;
end;

//Timer1
//Prescaler 1:8; PR1 Preload = 9250; Actual Interrupt Time = 1 ms
procedure InitTimer1();
begin
  T1CON         := 0x8010;
  T1IP0_bit     := 1;
  T1IP1_bit     := 0;
  T1IP2_bit     := 0;
  T1IF_bit      := 0;
  PR1           := 9250;
  TMR1          := 0;
  T1IE_bit      := 1;
end;

Procedure Init_;
Begin
  HiWord(WDTCON) := 0x5743;
  
  ANSELB := 0;
  nop;
  ANSELE := 0;
  nop;
  ANSELG := 0;
  nop;

  ANSELB.12 := 1; // AN7
  nop;
  TRISB.12 := 1;
  nop;
  
  // enable pbclk5; used as ethernet clock; default div 2
  // unlock
  SYSKEY := 0xAA996655;// Write Key1 to SYSKEY
  SYSKEY := 0x556699AA;//

  PB5DIV.B15 := 1;

  SYSKEY := 0;
  
  delayms(50);
  
  LED_dir := 0;
  nop;
  LED := 0;
  nop;

  rs485_ctrl := 0;
  nop;
  rs485_ctrl_dir := 0;
  nop;

  Unlock_IOLOCK();

  PPS_Mapping(_RPB5, _INPUT, _U1RX);    // UART1 RS485
  PPS_Mapping(_RPB3, _OUTPUT, _U1TX);

  PPS_Mapping(_RPB7, _INPUT, _U2RX);    // UART2
  PPS_Mapping(_RPB6, _OUTPUT, _U2TX);
  
  PPS_Mapping(_RPG7, _INPUT, _U3RX);    // UART3 Nextion
  PPS_Mapping(_RPG8, _OUTPUT, _U3TX);
  
  Lock_IOLOCK();

  delayms(10);
  
  I2C1_Init(100000);
  
  delayms(10);
  
  UART1_Init(115200);   //RS485

  UART1_len := 0;
  UART1_ovf := 0;
  UART1_data_available := false;

  UART1_Read;
  UART1_Read;
  UART1_Read;
  UART1_Read;
  UART1_Read;
  UART1_Read;
  UART1_Read;
  UART1_Read;
  U1RXIP0_bit := 1;
  U1RXIP1_bit := 1;
  U1RXIP2_bit := 1;
  U1RXIF_bit := 0;           // ensure interrupt not pending
  U1RXIE_bit := 1;                    // enable intterupt

  UART2_Init(115200);   //MCP

  UART2_len := 0;
  UART2_ovf := 0;
  UART2_data_available := false;

  UART2_Read;
  UART2_Read;
  UART2_Read;
  UART2_Read;
  UART2_Read;
  UART2_Read;
  UART2_Read;
  UART2_Read;
  U2RXIP0_bit := 1;
  U2RXIP1_bit := 1;
  U2RXIP2_bit := 1;
  U2RXIF_bit := 0;           // ensure interrupt not pending
  U2RXIE_bit := 1;                    // enable intterupt

  UART3_Init(115200);   //MCP3

  UART3_len := 0;
  UART3_ovf := 0;
  UART3_data_available := false;

  UART3_Read;
  UART3_Read;
  UART3_Read;
  UART3_Read;
  UART3_Read;
  UART3_Read;
  UART3_Read;
  UART3_Read;
  U3RXIP0_bit := 1;
  U3RXIP1_bit := 1;
  U3RXIP2_bit := 1;
  U3RXIF_bit := 0;           // ensure interrupt not pending
  U3RXIE_bit := 1;                    // enable intterupt
  
  reset_flag := 0;

  calib_enabled := 0;
  
  data_out_cnt := 0;

  CC10ms := 0;

  cc1 := 0;
  cc2 := 0;

  CC1m := 0;

  reset_flag := 0;

  But_cnt := 0;
  Disp_cnt := 0;
  refresh_disp_cnt := 0;

  tft_index := 0;
  must_send := 0;
  
  InitTimer1();

  init_adc;
  
  EnableInterrupts();
End;
I hope, the example will help you.
Best regards, Florin Andrei Medrea.

http://www.microelemente.ro/
http://www.microelemente.ro/produse-si-servicii/
http://www.microelemente.ro/custom-software/

mail : florin@microelemente.ro

Post Reply

Return to “mikroPascal PRO for PIC32 General”