USB issue with Flip&Click with 3.3V CANSPI Click

mikroC, mikroBasic and mikroPascal PRO for Microchip’s 32-bit PIC MCUs
Post Reply
Author
Message
ColinI
Posts: 42
Joined: 29 Mar 2017 21:19

USB issue with Flip&Click with 3.3V CANSPI Click

#1 Post by ColinI » 07 Mar 2019 21:38

Hi,
I'm attempting to communicate over the onboard CAN bus on a fusion 7 with a mx795F512L and the 3.3V CANSPI Click board in position D on a Flip&Click (f&c).
An issue has come up when trying to build for the f&c. Taking the 3.3V CAN SPI and f&c USB examples and combining them then modifying for the f&c P32MZ2048EFH100 @ 80 Mhz so that it simply outputs a letter or a number to the HID terminal if it detects CAN communication.
I have tried both making a USBdsc.c file and using the one from the f&c USB example. In the case of just using the sample USBdsc.c file the code below compiles but 'USB HID Library' does not show up in the list in HID terminal. The original f&c USB sample compiles and functions correctly.

It almost appears as if the v4 PIC32 C compiler HID Terminal is building a more up to date descriptor yet the USB library is looking for a different or perhaps a previous version. I have searched in the forum and on Libstock but so far haven't found anything.

Attempting to build and use a new descriptor file gives these errors:

0 360 Unresolved extern 'hidInit0' __Lib_USB_MZ_HS.c
0 360 Unresolved extern 'stringDescriptors' __Lib_USB_MZ_HS.c

Lastly, not being too familiar with PPS the settings in the code for mikrobus D on the Flip&Click may be incorrect. I took a stab at it reading the data sheet and there's a great chance it's wrong. Probably among the many things awry with my code.
Any help is appreciated, thanks much.
-Colin

Here is the code for the newly created USBdsc.c file, it is quite different from the sample:

Code: Select all

const unsigned int USB_VENDOR_ID = 0x2DBC;
const unsigned int USB_PRODUCT_ID = 0x0001;
const char USB_SELF_POWER = 0x80;            // Self powered 0xC0,  0x80 bus powered
const char USB_MAX_POWER = 50;               // Bus power required in units of 2 mA
const char HID_INPUT_REPORT_BYTES = 64;
const char HID_OUTPUT_REPORT_BYTES = 64;
const char USB_TRANSFER_TYPE = 0x03;         //0x03 Interrupt
const char EP_IN_INTERVAL = 1;
const char EP_OUT_INTERVAL = 1;

const char USB_INTERRUPT = 1;
const char USB_HID_EP = 1;
const char USB_HID_RPT_SIZE = 33;

/* Device Descriptor */
const struct {
    char bLength;               // bLength         - Descriptor size in bytes (12h)
    char bDescriptorType;       // bDescriptorType - The constant DEVICE (01h)
    unsigned int bcdUSB;        // bcdUSB          - USB specification release number (BCD)
    char bDeviceClass;          // bDeviceClass    - Class Code
    char bDeviceSubClass;       // bDeviceSubClass - Subclass code
    char bDeviceProtocol;       // bDeviceProtocol - Protocol code
    char bMaxPacketSize0;       // bMaxPacketSize0 - Maximum packet size for endpoint 0
    unsigned int idVendor;      // idVendor        - Vendor ID
    unsigned int idProduct;     // idProduct       - Product ID
    unsigned int bcdDevice;     // bcdDevice       - Device release number (BCD)
    char iManufacturer;         // iManufacturer   - Index of string descriptor for the manufacturer
    char iProduct;              // iProduct        - Index of string descriptor for the product.
    char iSerialNumber;         // iSerialNumber   - Index of string descriptor for the serial number.
    char bNumConfigurations;    // bNumConfigurations - Number of possible configurations
} device_dsc = {
      0x12,                   // bLength
      0x01,                   // bDescriptorType
      0x0200,                 // bcdUSB
      0x00,                   // bDeviceClass
      0x00,                   // bDeviceSubClass
      0x00,                   // bDeviceProtocol
      8,                      // bMaxPacketSize0
      USB_VENDOR_ID,          // idVendor
      USB_PRODUCT_ID,         // idProduct
      0x0001,                 // bcdDevice
      0x01,                   // iManufacturer
      0x02,                   // iProduct
      0x00,                   // iSerialNumber
      0x01                    // bNumConfigurations
  };

/* Configuration 1 Descriptor */
const char configDescriptor1[]= {
    // Configuration Descriptor
    0x09,                   // bLength             - Descriptor size in bytes
    0x02,                   // bDescriptorType     - The constant CONFIGURATION (02h)
    0x29,0x00,              // wTotalLength        - The number of bytes in the configuration descriptor and all of its subordinate descriptors
    1,                      // bNumInterfaces      - Number of interfaces in the configuration
    1,                      // bConfigurationValue - Identifier for Set Configuration and Get Configuration requests
    0,                      // iConfiguration      - Index of string descriptor for the configuration
    USB_SELF_POWER,         // bmAttributes        - Self/bus power and remote wakeup settings
    USB_MAX_POWER,          // bMaxPower           - Bus power required in units of 2 mA

    // Interface Descriptor
    0x09,                   // bLength - Descriptor size in bytes (09h)
    0x04,                   // bDescriptorType - The constant Interface (04h)
    0,                      // bInterfaceNumber - Number identifying this interface
    0,                      // bAlternateSetting - A number that identifies a descriptor with alternate settings for this bInterfaceNumber.
    2,                      // bNumEndpoint - Number of endpoints supported not counting endpoint zero
    0x03,                   // bInterfaceClass - Class code
    0,                      // bInterfaceSubclass - Subclass code
    0,                      // bInterfaceProtocol - Protocol code
    0,                      // iInterface - Interface string index

    // HID Class-Specific Descriptor
    0x09,                   // bLength - Descriptor size in bytes.
    0x21,                   // bDescriptorType - This descriptor's type: 21h to indicate the HID class.
    0x01,0x01,              // bcdHID - HID specification release number (BCD).
    0x00,                   // bCountryCode - Numeric expression identifying the country for localized hardware (BCD) or 00h.
    1,                      // bNumDescriptors - Number of subordinate report and physical descriptors.
    0x22,                   // bDescriptorType - The type of a class-specific descriptor that follows
    USB_HID_RPT_SIZE,0x00,  // wDescriptorLength - Total length of the descriptor identified above.

    // Endpoint Descriptor
    0x07,                   // bLength - Descriptor size in bytes (07h)
    0x05,                   // bDescriptorType - The constant Endpoint (05h)
    USB_HID_EP | 0x80,      // bEndpointAddress - Endpoint number and direction
    USB_TRANSFER_TYPE,      // bmAttributes - Transfer type and supplementary information    
    0x40,0x00,              // wMaxPacketSize - Maximum packet size supported
    EP_IN_INTERVAL,         // bInterval - Service interval or NAK rate

    // Endpoint Descriptor
    0x07,                   // bLength - Descriptor size in bytes (07h)
    0x05,                   // bDescriptorType - The constant Endpoint (05h)
    USB_HID_EP,             // bEndpointAddress - Endpoint number and direction
    USB_TRANSFER_TYPE,      // bmAttributes - Transfer type and supplementary information
    0x40,0x00,              // wMaxPacketSize - Maximum packet size supported    
    EP_OUT_INTERVAL         // bInterval - Service interval or NAK rate
};

const struct {
  char report[USB_HID_RPT_SIZE];
}hid_rpt_desc =
  {
     {0x06, 0x00, 0xFF,       // Usage Page = 0xFF00 (Vendor Defined Page 1)
      0x09, 0x01,             // Usage (Vendor Usage 1)
      0xA1, 0x01,             // Collection (Application)
  // Input report
      0x19, 0x01,             // Usage Minimum
      0x29, 0x40,             // Usage Maximum
      0x15, 0x00,             // Logical Minimum (data bytes in the report may have minimum value = 0x00)
      0x26, 0xFF, 0x00,       // Logical Maximum (data bytes in the report may have maximum value = 0x00FF = unsigned 255)
      0x75, 0x08,             // Report Size: 8-bit field size
      0x95, HID_INPUT_REPORT_BYTES,// Report Count
      0x81, 0x02,             // Input (Data, Array, Abs)
  // Output report
      0x19, 0x01,             // Usage Minimum
      0x29, 0x40,             // Usage Maximum
      0x75, 0x08,             // Report Size: 8-bit field size
      0x95, HID_OUTPUT_REPORT_BYTES,// Report Count
      0x91, 0x02,             // Output (Data, Array, Abs)
      0xC0}                   // End Collection
  };

//Language code string descriptor
const struct {
  char bLength;
  char bDscType;
  unsigned int string[1];
  } strd1 = {
      4,
      0x03,
      {0x0409}
    };


//Manufacturer string descriptor
const struct{
  char bLength;
  char bDscType;
  unsigned int string[4];
  }strd2={
    10,           //sizeof this descriptor string
    0x03,
    {'t','e','s','t'}
  };

//Product string descriptor
const struct{
  char bLength;
  char bDscType;
  unsigned int string[4];
}strd3={
    10,          //sizeof this descriptor string
    0x03,
    {'t','e','s','t'}
 };

//Array of configuration descriptors
const char* USB_config_dsc_ptr[1];

//Array of string descriptors
const char* USB_string_dsc_ptr[3];

void USB_Init_Desc(){
  USB_config_dsc_ptr[0] = &configDescriptor1;
  USB_string_dsc_ptr[0] = (const char*)&strd1;
  USB_string_dsc_ptr[1] = (const char*)&strd2;
  USB_string_dsc_ptr[2] = (const char*)&strd3;
}
Here's the code of the modified SPI CAN example, it is a work in progress, unsure if it will function at the moment but this is just learning to use CAN.

Code: Select all

// snipped from Can_Spi_2st (CAN Network demonstration with mikroE's CAN SPI Click 3,3V)

#include <stdint.h>
#include "resources.h"

/**************************************************************************************************
* Global variables
**************************************************************************************************/
uint8_t cnt;
uint8_t kk;
uint8_t readbuff[64];
uint8_t writebuff[64];

unsigned char Can_Init_Flags, Can_Send_Flags, Can_Rcv_Flags; // can flags
unsigned char Rx_Data_Len;                                   // received data length in bytes
char RxTx_Data[8];                                           // can rx/tx data buffer
char Msg_Rcvd;                                               // reception flag
const long ID_1st = 12111, ID_2nd = 3;                       // node IDs
long Rx_ID;

/**************************************************************************************************
* Port read variables
**************************************************************************************************/
char port_rd;
char port_rd_temp;
char i;
char old_message = 0xFF;
sbit LEDA              at LATA6_bit;
sbit LEDA_Dir          at TRISA6_bit;

void main() {
     
    Unlock_IOLOCK();
    PPS_Mapping_NoLock( _RPD3, _OUTPUT, _SDO1 );
    PPS_Mapping_NoLock( _RPD2, _INPUT, _SDI1 );
    Lock_IOLOCK();
     
    HID_Enable(readbuff, writebuff);
	
	//AD1PCFG = 0xFFFF;            // Configure AN pins as digital I/O
	ANSELA = 1;
	ANSELE = 1;
	ANSELD = 1;
	JTAGEN_bit = 0;              // Disable JTAG
	CanSpi_CS_Direction = 0;
	CanSpi_CS           = 1;
	Can_Init_Flags = 0;                                         //
	Can_Send_Flags = 0;                                         // clear flags
	Can_Rcv_Flags  = 0;                                         //

	Can_Send_Flags = _CANSPI_TX_PRIORITY_0 &                    // form value to be used
                   _CANSPI_TX_XTD_FRAME &                     // with CANSPIWrite
                   _CANSPI_TX_NO_RTR_FRAME;

	Can_Init_Flags = _CANSPI_CONFIG_SAMPLE_THRICE &             // form value to be used
                   _CANSPI_CONFIG_PHSEG2_PRG_ON &             // with CANSPIInit
                   _CANSPI_CONFIG_XTD_MSG &
                   _CANSPI_CONFIG_DBL_BUFFER_ON &
                   _CANSPI_CONFIG_VALID_XTD_MSG &
                   _CANSPI_CONFIG_LINE_FILTER_OFF;

	// Initialize SPI1 module
	SPI1_Init_Advanced(_SPI_MASTER, _SPI_8_BIT, 80, _SPI_SS_DISABLE, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_HIGH, _SPI_ACTIVE_2_IDLE);

	// Focs = 10MHz, SJW = 1, PHSEG1 = 3, PHSEG2 = 3, PROPSEG = 1, -> N = 1+3+3+1, N = 8
	// Desired Baud rate Fbaud = 125kb/s
	// BRP = Fosc/(2*N*Fbaud) = 5
	CANSPIInitialize(1,5,3,3,1,Can_Init_Flags);                           // initialize external CANSPI module
	CANSPISetOperationMode(_CANSPI_MODE_CONFIG,0xFF);                     // set CONFIGURATION mode
	CANSPISetMask(_CANSPI_MASK_B1,-1,_CANSPI_CONFIG_XTD_MSG);             // set all mask1 bits to ones
	CANSPISetMask(_CANSPI_MASK_B2,-1,_CANSPI_CONFIG_XTD_MSG);             // set all mask2 bits to ones
	CANSPISetFilter(_CANSPI_FILTER_B2_F3,ID_1st,_CANSPI_CONFIG_XTD_MSG);  // set id of filter B2_F3 to 1st node ID

	CANSPISetOperationMode(_CANSPI_MODE_NORMAL,0xFF);                           // set NORMAL mode

	while(1)  // endless loop
	{
		//LATA6_bit =~ PORTAbits.RA6;
		//Delay_ms(100);
		////////////////////////////////////////////////////
		USB_Polling_Proc();               // Call this routine periodically
		kk = HID_Read(); // not really used for this test
		Msg_Rcvd = CANSPIRead(&Rx_ID , RxTx_Data , &Rx_Data_Len, &Can_Rcv_Flags); // receive message

		if ((Rx_ID == ID_1st) && Msg_Rcvd) {                                      // if message received check id
			if (RxTx_Data[0] != old_message){                                       // id correct, output data at PORTD
				old_message = RxTx_Data[0];
				HID_Write("a", 64); // HID_Write(7, 64); //send a character to HID as confirmation
				//LATA6_bit =~ PORTAbits.RA6; // toggle LEDA
			}
		}
	}
}
Windows 7 & 10 64 bit
PIC Clicker, PIC32MX Clicker
EasyPIC Pro v7 with PIC18F87J60, PIC18F87K22
EasyPIC Fusion v7 with PIC32MZ2048EFH144, PIC32MX795F512L, P33FJ256GP710A
Flip & Click with P32MZ2048EFH100
Easy TFT, GLCD, 7" TFT
MikroC

User avatar
petar.suknjaja
mikroElektronika team
Posts: 683
Joined: 05 Mar 2018 09:44
Location: Belgrade

Re: USB issue with Flip&Click with 3.3V CANSPI Click

#2 Post by petar.suknjaja » 15 Mar 2019 10:03

Hi,
Post the whole project so we could reproduce the issue.
I'll try to reproduce the same setup and try to find the solution,
but it will take some time.
Kind regards,
Petar

ColinI
Posts: 42
Joined: 29 Mar 2017 21:19

Re: USB issue with Flip&Click with 3.3V CANSPI Click

#3 Post by ColinI » 17 Mar 2019 08:45

Hi Petar,
Thanks for looking into this.
Just did a quick test and the main issue can be reproduced by simply creating a new usb descriptor file in Tools>HID Terminal>Descriptor in v4 Mikroc for PIC32. Using the unchanged Flip and Click USB example, leaving the settings in the HID Terminal alone and saving them to a new descriptor then trying a build or rebuild produces the errors listed in the first post.
The entire project can be posted but pretty much everything is there in the first post. The can bus issues can't be tested until the compiler works with a new descriptor file. Maybe an updated version of the USB library is needed, though I had a look on libstock.
Thanks again.
Windows 7 & 10 64 bit
PIC Clicker, PIC32MX Clicker
EasyPIC Pro v7 with PIC18F87J60, PIC18F87K22
EasyPIC Fusion v7 with PIC32MZ2048EFH144, PIC32MX795F512L, P33FJ256GP710A
Flip & Click with P32MZ2048EFH100
Easy TFT, GLCD, 7" TFT
MikroC

User avatar
petar.suknjaja
mikroElektronika team
Posts: 683
Joined: 05 Mar 2018 09:44
Location: Belgrade

Re: USB issue with Flip&Click with 3.3V CANSPI Click

#4 Post by petar.suknjaja » 18 Mar 2019 14:27

Hi Colin,
Will do that,
Kind regards,
Petar

ColinI
Posts: 42
Joined: 29 Mar 2017 21:19

Re: USB issue with Flip&Click with 3.3V CANSPI Click

#5 Post by ColinI » 30 Apr 2019 21:12

I was able to get some time to revisit the issues listed above.
After attempting many times to create a usb descriptor file with the terminal program it still would not compile. With the unchanged usbdsc.c example file it would compile but setting up the SPI on the f&c stopped the board being recognized as a usb device by the computer. This could be due to the SPI not being configured correctly as the MZ series use PPS.
Giving up on getting the usb working I moved on to simply lighting LEDC on the flip&click board if there is anything detected on the can circuit.
Currently I'm having difficulty getting the f&c to respond to the can signal sent from the fusion board. The fusion does appear to transmit the signal as it can be seen on a scope. The fusion CAN 1st example is unchanged and is only being used to send a signal.
I'm sure I have something simple mis-configured.
The CANSPI click board is in mikrobus D, LEDB is set to blink on a timer. LEDC is supposed to simply turn on if there's can activity.
Any help is appreciated, thanks in advance.
This is the modified canspi example:

Code: Select all

/* modified
 * Project name:
     Can_Spi_2st (CAN Network demonstration with mikroE's CAN SPI Click 3,3V)
 * Copyright:
     (c) Mikroelektronika, 2014.
 * Revision History:
     20111224:
       - initial release;
     20140719:
       - Adapted to EasyPIC v7 Fusion (TP)
 * Description:
     This is code that shows simple connection of two CAN SPI Click 3,3V boards. This is for 2st node.
     Press buttons on PortB/L to send message and receive message on TFT.
 * Test configuration:
     MCU:             PIC32MX795F512L modified for P32MZ2048EFH100
                      http://ww1.microchip.com/downloads/en/DeviceDoc/61156H.pdf
     Dev.Board:       EasyPIC v7 Fusion modified for flip and click pic32
                      http://www.mikroe.com/easypic-fusion/
     Oscillator:      HSE-PLL, 80MHz modified to 200
     ext. modules:    CAN SPI Click 3,3V
                      http://www.mikroe.com/click/can-spi-3.3v/
                      with  SN65HVD230 on board:
                      http://www.ti.com/product/sn65hvd230
     SW:              mikroC PRO for PIC32
                      http://www.mikroe.com/mikroc/pic32/
 * NOTES:
     - Consult the CAN standard about CAN bus termination resistance.
     - Turn ON TFT backlight switch SW11.1.
     - PULL Down all PORTB/L switches (portB three state switch.
     - Set Button Press Switch for PortB/L in upper position.
     - On CAN SPI Click 3,3V board set J2 Term jumper.
*/
#include <stdint.h>
#include "resources.h"

/**************************************************************************************************
* Global variables
**************************************************************************************************/
int count;
uint8_t cnt;
uint8_t kk;
uint8_t readbuff[64];
uint8_t writebuff[64];

unsigned char Can_Init_Flags, Can_Send_Flags, Can_Rcv_Flags; // can flags
unsigned char Rx_Data_Len;                                   // received data length in bytes
char RxTx_Data[8];                                           // can rx/tx data buffer
char Msg_Rcvd;                                               // reception flag
const long ID_1st = 12111, ID_2nd = 3;                       // node IDs
long Rx_ID;

/**************************************************************************************************
* CAN SPI connections
**************************************************************************************************/
sbit CanSpi_CS            at  LATD13_bit;
sbit CanSpi_CS_Direction  at  TRISD13_bit;
sbit CanSpi_Rst           at  LATG12_bit;
sbit CanSpi_Rst_Direction at  TRISG12_bit;

const unsigned int SJW = 1;
const unsigned int BRP = 16;
const unsigned int PHSEG1 = 8;
const unsigned int PHSEG2 = 3;
const unsigned int PROPSEG = 8;

char i;
char old_message = 0xFF;

// LED pins definitions
sbit LEDB              at LATA7_bit;
sbit LEDC              at LATE0_bit;
// End of LEDs connections

BlinkLed(){
 LATA7_bit =~ PORTAbits.RA7; //LEDB
	}
OffLed(){
 LATA7_bit = 0; //LEDB
	}

//Timer2/3
//Prescaler 1:1; PR3 Preload = 762; PR2 Preload = 61568; Actual Interrupt Time = 500 ms
void Init_Timer2_3() {
  T2CON                   = 0x8008;
  T3CON                   = 0x0;
  TMR2                    = 0;
  TMR3                    = 0;
  T3IP0_bit               = 1;
  T3IP1_bit               = 1;
  T3IP2_bit               = 1;
  T3IF_bit                = 0;
  T3IE_bit                = 1;
  PR2                     = 61568;
  PR3                     = 762;
	}

void Timer_interrupt() iv IVT_TIMER_3 ilevel 7 ics ICS_SRS {
  count++;
  // clear Timer Interrupt flag
  T3IF_bit = 0;
  switch (count) {
    case 2 :
         BlinkLed();
         count = 0;
    break;
	}
}
/**************************************************************************************************
* Main Function
**************************************************************************************************/
void main() {
     
    Unlock_IOLOCK();
    PPS_Mapping_NoLock( _RPD2, _OUTPUT, _SDO1 );
    PPS_Mapping_NoLock( _RPD3, _INPUT, _SDI1 );
    Lock_IOLOCK();


  ANSELA = 0;                  // set all ports to DIGITAL
  ANSELB = 0;
  ANSELC = 0;
  ANSELD = 0;
  ANSELE = 0;
  ANSELF = 0;
  ANSELG = 0;

  TRISA = 0;
  TRISB = 0;
  TRISC = 0;
  TRISD &= 0x0000C000;
  TRISE = 0;
  TRISF = 0;
  TRISG = 0;

  // LEDs direction
  LEDB_Dir = 0;
  LEDC_Dir = 0;
  
  Init_Timer2_3();             // Initialize Timer2/3
  EnableInterrupts();          // Enable all interrupts
  OffLed();

  CanSpi_CS_Direction = 0;
  CanSpi_CS           = 1;


  // Initialize SPI1 module
  SPI1_Init_Advanced(_SPI_MASTER, _SPI_8_BIT, 80, _SPI_SS_DISABLE, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_HIGH, _SPI_ACTIVE_2_IDLE);

  Can_Send_Flags = _CANSPI_TX_PRIORITY_0 &                    // form value to be used
                   _CANSPI_TX_XTD_FRAME &                     // with CANSPIWrite
                   _CANSPI_TX_NO_RTR_FRAME;

  Can_Init_Flags = _CANSPI_CONFIG_SAMPLE_THRICE &             // form value to be used
                   _CANSPI_CONFIG_PHSEG2_PRG_ON &             // with CANSPIInit
                   _CANSPI_CONFIG_XTD_MSG &
                   _CANSPI_CONFIG_DBL_BUFFER_ON &
                   _CANSPI_CONFIG_VALID_XTD_MSG &
                   _CANSPI_CONFIG_LINE_FILTER_OFF;
  
  // Focs = 10MHz, SJW = 1, PHSEG1 = 3, PHSEG2 = 3, PROPSEG = 1, -> N = 1+3+3+1, N = 8
  // Desired Baud rate Fbaud = 125kb/s
  // BRP = Fosc/(2*N*Fbaud) = 5
  //CANSPIInitialize(1,5,3,3,1,Can_Init_Flags);  // initialize external CANSPI module
  CANSPIInitialize(SJW, BRP, PHSEG1, PHSEG2, PROPSEG, Can_Init_Flags);
  CANSPISetOperationMode(_CANSPI_MODE_CONFIG,0xFF);                     // set CONFIGURATION mode
  CANSPISetMask(_CANSPI_MASK_B1,-1,_CANSPI_CONFIG_XTD_MSG);             // set all mask1 bits to ones
  CANSPISetMask(_CANSPI_MASK_B2,-1,_CANSPI_CONFIG_XTD_MSG);             // set all mask2 bits to ones
  CANSPISetFilter(_CANSPI_FILTER_B2_F3,ID_1st,_CANSPI_CONFIG_XTD_MSG);  // set id of filter B2_F3 to 1st node ID

  CANSPISetOperationMode(_CANSPI_MODE_NORMAL,0xFF);                          // set NORMAL mode
  
  while(1)  // endless loop
  {
    
    Msg_Rcvd = CANSPIRead(&Rx_ID , RxTx_Data , &Rx_Data_Len, &Can_Rcv_Flags); // receive message

    if ((Rx_ID == ID_1st) && Msg_Rcvd) {                                      // if message received check id
      if (RxTx_Data[0] != old_message){                                       // id correct, output data at PORTD
        old_message = RxTx_Data[0];
		LATE0_bit =0;
        LATE0_bit =1;
        Delay_ms(500);
	  }
    }
  }
}
Windows 7 & 10 64 bit
PIC Clicker, PIC32MX Clicker
EasyPIC Pro v7 with PIC18F87J60, PIC18F87K22
EasyPIC Fusion v7 with PIC32MZ2048EFH144, PIC32MX795F512L, P33FJ256GP710A
Flip & Click with P32MZ2048EFH100
Easy TFT, GLCD, 7" TFT
MikroC

Post Reply

Return to “PIC32 PRO Compilers”