Hi,
I am using PIC Clicker 2 (PIC18F67K40) and CanSpi 5V Click board for testing. It is not working.
When I am doing degugging, it seems that the program stops at CANSPIInitialize() function.
I used similar code for EasyPICV7 board with CanSpi 5V Clcik, it is working fine. My objective is to test Clicker 2 and EasyPICV7 board communication through two CanSpi 5V clicks boards.
Appreciate if you could help. I have attached project file as well.
Best Regards,
Saw
* Global variables
**************************************************************************************************/
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 LATD0_bit;
sbit CanSpi_CS_Direction at TRISD0_bit;
sbit CanSpi_Rst at LATG3_bit;
sbit CanSpi_Rst_Direction at TRISG3_bit;
/**************************************************************************************************
* Define TX LED indicator
**************************************************************************************************/
sbit TX_LED_dir at TRISD7_bit;
sbit TX_LED at LATD7_bit;
/**************************************************************************************************
* Port read variables
**************************************************************************************************/
char port_rb;
char port_rb_temp;
/**************************************************************************************************
* MAIN PROGRAM
**************************************************************************************************/
void main() { // Main Program
ANSELA = 0; // Configure PORTA pins as digital
ANSELB = 0; // Configure PORTB pins as digital
//ANSELC = 0; // Configure PORTC pins as digital
ANSELD = 0; // Configure PORTD pins as digital
ANSELE = 0; // Configure PORTE pins as digital
ANSELF = 0; // Configure PORTF pins as digital
ANSELG =0;
TRISF2_BIT=1; // AS INPUT
TRISF3_BIT=1; // AS INPUT
TRISD7_BIT=0;// AS OUTPUT
TRISH3_BIT=0;// AS OUTPUT
//SLRCON = 0; // Configure all PORTS at the standard Slew
PORTD = 0; // clear PORTD
TRISD = 0; // set PORTD as output
CanSpi_CS_Direction = 0;
CanSpi_Rst_Direction = 0;
TX_LED_dir = 0;
port_rb = 0;
port_rb_temp = 0xff;
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_OSC_DIV4, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH); // initialize SPI1 module
// 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
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
LATD = RxTx_Data[0]; // id correct, output data at PORTB
Delay_ms(10);
}
if (RF2_BIT==1) // Check for change on PORTB
{
LATH3_BIT = 1;
delay_ms(500);
LATH3_BIT=0;
delay_ms(500); // Turn ON TX LED indicator
port_rb= 0x0F;
CANSPIWrite(ID_2nd, &port_rb, 1, Can_Send_Flags); // send incremented data back
LATH3_BIT = 1;
delay_ms(500);
LATH3_BIT=0;
delay_ms(500); // Turn OFF TX LED indicator
}
}
}
/**************************************************************************************************
* End of File
**************************************************************************************************/
PIC Clicker 2 (18FK) & CanSpi 5V Click Board not working
-
- Posts: 14
- Joined: 06 Feb 2016 16:52
PIC Clicker 2 (18FK) & CanSpi 5V Click Board not working
- Attachments
-
- 2nd_NODE - Clicker 2.rar
- (117.79 KiB) Downloaded 61 times
Re: PIC Clicker 2 (18FK) & CanSpi 5V Click Board not working
Hi,
Have you been able to sort out this issue ?
Regards,
Filip.
Have you been able to sort out this issue ?
Regards,
Filip.
-
- Posts: 14
- Joined: 06 Feb 2016 16:52
Re: PIC Clicker 2 (18FK) & CanSpi 5V Click Board not working
Hi Flip,
Yes, I have solved this problem through your support.
Thank you very much.
Best Regards,
Saw
Yes, I have solved this problem through your support.
Thank you very much.
Best Regards,
Saw
-
- Posts: 14
- Joined: 06 Feb 2016 16:52
Re: PIC Clicker 2 (18FK) & CanSpi 5V Click Board not working
Hi,
I was having problems with my project to use I2C Library and RS485 Library together. Even if I go back to simple RS485 sample program, after I select I2C library to use, it showed below two errors. I don't quite understand that I haven't even write a single line of code related to I2C.
Is it not possible to use mikroC Pro for receiving data from I2C and sending out via RS485 or vise visa? How to overcome this issue?
38 365 Reentrancy is not allowed: function 'I2C1_Start' called from two threads __Lib_I2C_c34.c
58 365 Reentrancy is not allowed: function 'UART1_Write' called from two threads __Lib_UART_c67.c
Best Regards,
Saw
I was having problems with my project to use I2C Library and RS485 Library together. Even if I go back to simple RS485 sample program, after I select I2C library to use, it showed below two errors. I don't quite understand that I haven't even write a single line of code related to I2C.
Is it not possible to use mikroC Pro for receiving data from I2C and sending out via RS485 or vise visa? How to overcome this issue?
38 365 Reentrancy is not allowed: function 'I2C1_Start' called from two threads __Lib_I2C_c34.c
58 365 Reentrancy is not allowed: function 'UART1_Write' called from two threads __Lib_UART_c67.c
Best Regards,
Saw
Re: PIC Clicker 2 (18FK) & CanSpi 5V Click Board not working
Hi,
Can you please attach minimal project that demonstrates this issue ?
Regards,
Filip.
Can you please attach minimal project that demonstrates this issue ?
Regards,
Filip.