So I am trying to compile the example code for the MCP2517_click (Mikroe) example but its coming with error.
from what I could diagnose, it seem that I am missing some of the required libraries (even though I did download and install the package!)
If anyone would point me to or share the libraries required for this example code, if would be much appreciated!
Code: Select all
/*
Example for MCP2517FD Click
Date : Jun 2018.
Author : Nemanja Medakovic
Test configuration PIC :
MCU : P18F87K22
Dev. Board : EasyPIC PRO v7
PIC Compiler ver : v7.2.0.0
---
Description :
The application is composed of three sections :
- System Initialization - Initializes peripherals and pins.
- Application Initialization - Initializes SPI interface and performs the device configuration to work properly.
- Application Task - (code snippet) - Always checks is a new message in FIFO ready for receiving and when
is message ready, receives a message from the other device.
Also in this example we can send the desired message via CAN communication to the other device.
We can choose a message to be sent by sending the determined command to the UART.
In this example the command can be number from 1 to 5.
Additional Functions :
- char * _strcpy( char * _to, char * _from ) - String copy function.
*/
#include "Click_MCP2517FD_types.h"
#include "Click_MCP2517FD_config.h"
uint8_t checkFlag;
uint8_t rxDat;
T_MCP2517FD_config conObj;
char *chPtr;
char txtMessage1[6] = "HELLO";
char txtMessage2[8] = "MESSAGE";
char txtMessage3[3] = "IS";
char txtMessage4[9] = "RECEIVED";
char txtMessage5[4] = "END";
// Transmit objects
uint8_t txd[ 64 ];
// Receive objects
uint8_t rxd[ 64 ];
char * _strcpy( char * _to, char * _from )
{
char *cp;
cp = _to;
while (*_from != 0)
{
*cp = *_from;
cp = cp + 1;
_from = _from + 1;
}
return _to;
}
void systemInit()
{
mikrobus_gpioInit( _MIKROBUS3, _MIKROBUS_CS_PIN, _GPIO_OUTPUT );
mikrobus_spiInit( _MIKROBUS3, &_MCP2517FD_SPI_CFG[0] );
mikrobus_logInit( _MIKROBUS1, 115200 );
mikrobus_logWrite( "Initializing...", _LOG_LINE );
Delay_ms( 200 );
}
void applicationInit()
{
uint8_t oscByte;
mcp2517fd_spiDriverInit( (T_MCP2517FD_P)&_MIKROBUS3_GPIO, (T_MCP2517FD_P)&_MIKROBUS3_SPI );
Delay_ms( 500 );
conObj._IsoCrcEnable = ISO_CRC;
conObj._StoreInTEF = 0;
conObj._txFifoSize = 8;
conObj._txPayLoadSize = MCP2517FD_PLSIZE_8;
conObj._txPriority = 1;
conObj._rxFifoSize = 8;
conObj._rxPayLoadSize = MCP2517FD_PLSIZE_8;
conObj._StandardID = 0;
conObj._ExtendedID = 0;
conObj._FDFrame = 1;
conObj._SwitchBitRate = 1;
conObj._IDE = 0;
conObj._RemoteFrameReq = 0;
conObj._SEQ = 1;
MCP2517FD_clickInit( &conObj );
// Setup Transmit and Receive Interrupts
MCP2517FD_GpioModeConfigure( DRV_CANFDSPI_INDEX_0, MCP2517FD_PINMODE_INT, MCP2517FD_PINMODE_INT );
MCP2517FD_TransmitChannelEventEnable( DRV_CANFDSPI_INDEX_0, MCP2517FD_FIFO_CH2, MCP2517FD_TX_FIFO_NOT_FULL_EVENT );
MCP2517FD_ReceiveChannelEventEnable( DRV_CANFDSPI_INDEX_0, MCP2517FD_FIFO_CH1, MCP2517FD_RX_FIFO_NOT_EMPTY_EVENT );
MCP2517FD_ModuleEventEnable( DRV_CANFDSPI_INDEX_0, MCP2517FD_TX_EVENT | MCP2517FD_RX_EVENT );
MCP2517FD_ReadByte( DRV_CANFDSPI_INDEX_0, _MCP2517FD_REG_CiINT + 3, &oscByte );
oscByte |= MCP2517FD_WAKEUP_INTERR_EN;
MCP2517FD_WriteByte( DRV_CANFDSPI_INDEX_0, _MCP2517FD_REG_CiINT + 3, oscByte );
MCP2517FD_ReadByte( DRV_CANFDSPI_INDEX_0, _MCP2517FD_REG_OSC, &oscByte );
oscByte &= 0xF3;
MCP2517FD_WriteByte( DRV_CANFDSPI_INDEX_0, _MCP2517FD_REG_OSC, oscByte );
Delay_ms( 200 );
// Select Normal Mode
MCP2517FD_OperationModeSelect( DRV_CANFDSPI_INDEX_0, MCP2517FD_NORMAL_MODE );
Delay_ms( 1000 );
mikrobus_logWrite( "MCP2517FD is initialized for PIC", _LOG_LINE );
mikrobus_logWrite( "", _LOG_LINE );
}
void applicationTask()
{
if (UART_Rdy_Ptr())
{
rxDat = UART_Rd_Ptr();
chPtr = &txd[0];
switch (rxDat)
{
case '1' :
{
_strcpy( chPtr, &txtMessage1[0] );
MCP2517FD_transmitMessage( 5, &checkFlag, &txd[0] );
if (checkFlag == 1)
{
mikrobus_logWrite( "Message Sent", _LOG_LINE );
}
break;
}
case '2' :
{
_strcpy( chPtr, &txtMessage2[0] );
MCP2517FD_transmitMessage( 7, &checkFlag, &txd[0] );
if (checkFlag == 1)
{
mikrobus_logWrite( "Message Sent", _LOG_LINE );
}
break;
}
case '3' :
{
_strcpy( chPtr, &txtMessage3[0] );
MCP2517FD_transmitMessage( 2, &checkFlag, &txd[0] );
if (checkFlag == 1)
{
mikrobus_logWrite( "Message Sent", _LOG_LINE );
}
break;
}
case '4' :
{
_strcpy( chPtr, &txtMessage4[0] );
MCP2517FD_transmitMessage( 8, &checkFlag, &txd[0] );
if (checkFlag == 1)
{
mikrobus_logWrite( "Message Sent", _LOG_LINE );
}
break;
}
case '5' :
{
_strcpy( chPtr, &txtMessage5[0] );
MCP2517FD_transmitMessage( 3, &checkFlag, &txd[0] );
if (checkFlag == 1)
{
mikrobus_logWrite( "Message Sent", _LOG_LINE );
}
break;
}
default :
{
break;
}
}
}
MCP2517FD_receiveMessage( &checkFlag, &rxd[0] );
if (checkFlag == 1)
{
chPtr = &rxd[0];
mikrobus_logWrite( "Message Received : ", _LOG_TEXT );
mikrobus_logWrite( chPtr, _LOG_LINE );
}
}
void main()
{
systemInit();
applicationInit();
while (1)
{
applicationTask();
}
}