Description

begin() – registers the data pool with the CAN bus object so that the data pool will be kept up to date and handling its maintenance in the background.

Syntax

myPool.begin();
myPool.begin( u16_peer_range_low_CANID, u16_peer_range_high_CANID);

Parameters

optional:
uint16_t u16_peer_range_low_CANID : defines lowest CAN-ID of the range of devices sharing this data pool. (default: 0x765)
uint16_t u16_peer_range_high_CANID: defines highest CAN-ID of the range of devices sharing this data pool. (default: 0x76F)

Returns

uint8_t: 0: OK or
1: Error (range or order error of the CAN-ID arguments)
2: Error while memory allocations
3: Wrong amount of variables in the pool [1…128]
4: Invalid pointer to MCAN CAN bus
5: No free can-filter available for this receiver
6: Pool name is too short (min.8 ; max. 32 characters)


Example Codes:

The following code example defines a data pool including an callback function that is called whenever a variable is modified by another peer.

#include "Datapool.h"

#define NB_OF_VARIABLES 3
#define POOL_NAME "A_SimplePool_V1_0"
void myCallBack(uint8_t ou8_NbOfUpdatedVariable);
DATAPOOL myPool( &MCAN0, &BOOTLOADER_SETTING, POOL_NAME, NB_OF_VARIABLES, myCallBack );

void setup() {
  while(!Serial);
  myPool.begin();
  Serial.println("Enter new value of Var1");
}

int8_t s8_modVar = -1;
void loop() 
{
  if(Serial.peek() != -1)
  {
    int i_new = Serial.readStringUntil('\n').toInt();
    myPool.setValue( 1, (int32_t)i_new ); 
  }
  if(s8_modVar > -1)
  {
    Serial.println("Var"+String(s8_modVar)+": "+
         String( myPool.getValue_int32(s8_modVar) ));
    s8_modVar = -1;
  }
}
void myCallBack(uint8_t ou8_NbOfUpdatedVariable)
{
  s8_modVar = ou8_NbOfUpdatedVariable;
}

Notes and Warnings

Whenever possible use the default CAN-IDs -> begin(). It is possible to use dice devices with different IDs (outside the default range 0x766 .. 0770) but this would involve many tools and software.

Examples can be found in the Arduino IDE menu:
File -> Examples -> Datapool ->

See also

Device addressing