Datasheet

const
CANSPI_FILTER_B1_F1 as byte = 0
CANSPI_FILTER_B1_F2 as byte = 1
CANSPI_FILTER_B2_F1 as byte = 2
CANSPI_FILTER_B2_F2 as byte = 3
CANSPI_FILTER_B2_F3 as byte = 4
CANSPI_FILTER_B2_F4 as byte = 5
Library Example
This is a simple demonstration of CANSPI Library routines usage. First node initi-
ates the communication with the second node by sending some data to its address.
The second node responds by sending back the data incremented by 1. First node
then does the same and sends incremented data back to second node, etc.
Code for the first CANSPI node:
program Can_Spi_1st
dim Can_Init_Flags, Can_Send_Flags, Can_Rcv_Flags as byte ' can flags
Rx_Data_Len as byte ' received data length in bytes
RxTx_Data as byte[8] ' can rx/tx data buffer
Msg_Rcvd as byte ' reception flag
Tx_ID, Rx_ID as longint ' can rx and tx ID
' CANSPI module connections
dim CanSpi_CS as sbit at PORTB.B0
CanSpi_CS_Direction as sbit at DDRB.B0
CanSpi_Rst as sbit at PORTB.B2
CanSpi_Rst_Direction as sbit at DDRB.B2
' End CANSPI module connections
main:
ADCSRA.7 = 0 ' Set AN pins to Digital I/O
PORTC = 0
DDRC = 255
Can_Init_Flags = 0 '
Can_Send_Flags = 0 ' clear flags
Can_Rcv_Flags = 0 '
Can_Send_Flags = _CANSPI_TX_PRIORITY_0 and ' form value to be used
_CANSPI_TX_XTD_FRAME and ' with CANSPIWrite
_CANSPI_TX_NO_RTR_FRAME
Can_Init_Flags = _CANSPI_CONFIG_SAMPLE_THRICE and ' form value to be
used
_CANSPI_CONFIG_PHSEG2_PRG_ON and ' with CANSPIInit
_CANSPI_CONFIG_XTD_MSG and
_CANSPI_CONFIG_DBL_BUFFER_ON and
_CANSPI_CONFIG_VALID_XTD_MSG
185
MIKROELEKTRONIKA - SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Libraries
mikroBasic PRO for AVR
CHAPTER 6