Init(CANX,...)
Description
Initializes CAN BUS pins.
Syntax
Init(CANX, MODE, SPEED);
In case user wants to use CAN Database and script at the same time:
Init(CANX, MODE, SPEED, CANX_READ);
Parameters
Variable | Input |
|---|---|
| This defines which can channel pins (CAN H and CAN L) is going to be used. Can be either CAN1 or CAN2 |
| NORMAL - In normal mode Can Bus provides ACK frame and is able to send messages. SILENT - Silent mode means the interface only listens to the CAN bus. This means the unit does not even provide an ACK frame when a message is placed on the CAN bus correctly. ONE_SHOT - One shot mode sends single frame to can bus without requesting ACK. This is a non-automatic retransmission mode. |
| Can bus baudrate which is measured in Kbit/s (for example 20 Kbit/s, 33.333 Kbit/s and so on). Speed is either 20000, 33333, 50000, 83333, 100000, 125000, 250000, 500000 or 1000000 |
| Initializes receive buffer for reading CAN messages. Can be either CAN1_READ or CAN2_READ |
Returns
Return value | Return explanation |
SCRIPT_OPERATION_SUCCESS | Success |
SCRIPT_OPERATION_FAILED | Failed |
SCRIPT_NO_ACCESS | Peripheral already initialized. |
SCRIPT_PARAM_INVALID | Passed invalid init parameters. |
Function call example (1)
CANX initialization example
main()
{
Init(CAN1, NORMAL, 250000);
while(1){
Delay(100);
}
}Function call example (2)
CANX read mode initialization example
...
#define CAN1_MODE_READ
#include <can>
...
public callback (event)
{
switch(event)
{
case CAN1:
{
...
}
}
return 0;
}
...
main()
{
Init(CAN1, NORMAL, 250000, CAN1_READ);
while(1)
{
Delay(100);
}
}