ClusterM / clunet

CLUNET library - simple single-wire peer-to-peer network driver for AVR microcontrollers, perfect way to interconnect microcontrollers in your house
The Unlicense
112 stars 21 forks source link

CLUNET

The CLUNET library - is a simple single-wire peer-to-peer network driver for AVR microcontrollers, perfect way to interconnect microcontrollers in your house.

Features:

How to use

Hardware part

Sample schematic

You need a pin with an external interrupt to read data and any other pin to send data. Transistor method is recommended.

Software part

You will need one free 8-bit timer with output compare match interrupt.

Configuration

Edit clunet_config.h and change some values:

Default configuration file is optimised for ATMEGA8 / 8MHz.

Code

Include "clunet.h" and create callback function to receive data:

#include "clunet.h"

void data_received(unsigned char src_address, unsigned char dst_address, unsigned char command, char* data, unsigned char size)
{
    /* your code here */
}

Add initialization code and enable interrupts:

int main (void)
{
    clunet_init();
    clunet_set_on_data_received(data_received); 
    sei();

Also you can use clunet_set_on_data_received_sniff() to set callback function which will receive all packets, not only for this device.

Function to send data:

void clunet_send(unsigned char address, unsigned char prio, unsigned char command, char* data, unsigned char size);

Sample code:

char buffer[1];
buffer[0] = 1;
clunet_send(CLUNET_BROADCAST_ADDRESS, CLUNET_PRIORITY_MESSAGE, CLUNET_COMMAND_DEVICE_POWER_INFO, buffer, sizeof(buffer));

while (clunet_ready_to_send()); // wait while sending, otherwise next call will replace output buffer
                                // clunet_ready_to_send() returns current task priority
                                // or 0 if output buffer is not busy

char *hello = "Hello world!";
clunet_send(1, CLUNET_PRIORITY_INFO, 100, hello, strlen(hello));

Reserved commands

There are some reserved commands:

Tested on

Known bugs/problems

Author/contacts

Alexey 'Cluster' Avdyukhin

clusterrr@clusterrr.com

https://github.com/ClusterM

http://clusterrr.com