Mikroelektronika MIKROE-442 Datenbogen
![Mikroelektronika](https://files.manualsbrain.com/attachments/e0529b3b58069a916ad7bb89f7e9f5f0eda73421/common/fit/150/50/1b07b99aa3112e022a916b06db07f1f4f211e91d41878452d87c7638b1bf/brand_logo.gif)
254
mikoBasic PRO for dsPIC30/33 and PIC24
MikroElektronika
CANxRead
Prototype
sub function CANxRead(dim byref id as longint, dim byref data as byte[1],
dim dataLen, CAN_RX_MSG_FLAGS as word) as word
Description If at least one full Receive Buffer is found, it will be processed in the following way:
- Message ID is retrieved and stored to location pointed by
id
pointer
- Message data is retrieved and stored to array pointed by
data
pointer
- Message length is retrieved and stored to location pointed by
dataLen
pointer
- Message flags are retrieved and stored to location pointed by
CAN_RX_MSG_FLAGS
pointer
Parameters -
id
: message identifier address
-
data
: an array of bytes up to 8 bytes in length
-
dataLen
: data length address
-
CAN_RX_MSG_FLAGS
: message flags address. For message receive flags format refer to
CAN_RX_
MSG_FLAGS
constants. See CAN_RX_MSG_FLAGS constants.
Returns
-
0
if nothing is received
-
0xFFFF
if one of the Receive Buffers is full (message received)
Requires
MCU with the CAN module.
MCU must be connected to the CAN transceiver (MCP2551 or similar) which is connected to the CAN
bus.
CAN must be in Config mode, otherwise the function will be ignored. See CANxSetOperationMode.
Example
‘ check the CAN1 module for received messages. If any was received do
something.
dim msg_rcvd, rx_flags, data_len as word
data as byte[8]
msg_id as longint
...
CAN1SetOperationMode(_CAN_MODE_NORMAL,0xFF) ‘ set NORMAL mode (CAN1 module
must be in mode in which receive is possible)
...
rx_flags = 0 ‘ clear message flags
if (msg_rcvd = CAN1Read(msg_id, data, data_len, rx_flags)<>0) then
...
end if
Notes
- CAN library routine require you to specify the module you want to use. To use the desired CAN
module, simply change the letter
x in the routine prototype for a number from 1 to 2.
- Number of CAN modules per MCU differs from chip to chip. Please, read the appropriate datasheet
before utilizing this library.