USB and CAN not simultaneously

General discussion on mikroPascal PRO for PIC32.
Post Reply
Author
Message
mur@t
Posts: 25
Joined: 18 Jul 2014 14:58

USB and CAN not simultaneously

#1 Post by mur@t » 30 Jul 2014 20:06

Hi,

I'm writing a code for MX975F512H.

reads the data from the CANbus and send data to USB.
CAN and USB samples working separately. But in the same code does not work. (sending out a few times, after crashing)

Code: Select all

procedure USB1Interrupt(); iv IVT_USB_1; ilevel 7; ics ICS_SRS;
begin
   USB_Interrupt_Proc();
end;


begin
  CHECON := 0x32;
  AD1PCFG := 0xFFFF;      // Configure AN pins as digital I/O
  AD1PCFGSET := 0xFFFF;   // CAN2 module enabled

  USBIE_bit := 0;
  IPC11SET := 7 shl 10;   // Interrupt priority 7
  EnableInterrupts();

  LATB := 0;
  LATD := 0;
  TRISB := 0;
  TRISD := 0;

  HID_Enable(@readbuff,@writebuff);

  Can_Init_Flags := 0;                     
  Can_Send_Flags := 0;                             // clear flags
  Can_Rcv_Flags  := 0;                    
  Can_Conf_Flags := 0;

  Can_Send_Flags := _CAN_TX_STD_FRAME and _CAN_TX_NO_RTR_FRAME;

  Can_Conf_Flags := _CAN_CONFIG_SAMPLE_ONCE and
                    _CAN_CONFIG_PHSEG2_PRG_ON and
                    _CAN_CONFIG_STD_MSG and
                    _CAN_CONFIG_MATCH_MSG_TYPE and
                    _CAN_CONFIG_LINE_FILTER_OFF;


  //CAN 1 Initialize
  ...

  writebuff[0] := '>';
  writebuff[1] := 'D';

  while(TRUE) do
  begin
    while(HID_Read() > 0) do
    ;

    Msg_Rcvd := CAN1Read(Rx_ID, Rx_Data, Rx_Data_Len, Can_Rcv_Flags);        // receive message
    if (Msg_Rcvd <> 0) then begin

      writebuff[2] := 'A';
      writebuff[3] := Hi(HiWord(Rx_ID));
      writebuff[4] := Lo(HiWord(Rx_ID));
      writebuff[5] := Hi(LoWord(Rx_ID));
      writebuff[6] := Lo(LoWord(Rx_ID));
      writebuff[7] := rx_stat;
      writebuff[8] := Rx_Data_Len;
      for i:=0 to Rx_Data_Len-1 do writebuff[9+i] := Rx_Data[i];

      HID_Write(@writebuff,64);

    end;


  end;

JimKueneman
Posts: 417
Joined: 10 Jan 2009 22:03

Re: USB and CAN not simultaneously

#2 Post by JimKueneman » 02 Aug 2014 05:52

Hi

Have you read my saga?

http://www.mikroe.com/forum/viewtopic.php?f=172&t=60987

Just for fun remove the iLevel and SRS keywords. Make it use the software context saving.

Jim

mur@t
Posts: 25
Joined: 18 Jul 2014 14:58

Re: USB and CAN not simultaneously

#3 Post by mur@t » 13 Aug 2014 20:43

Thanks Jim,
I used another usb library (from libstock) to fix the problem.

Post Reply

Return to “mikroPascal PRO for PIC32 General”