Network & Communication

Embedded Communication
Embedded communication is the process of sending information between two MCUs or from one circuit to other. For a communication to happen there needs to be a transmitter and a receiver. Communication may be in one direction or in both directions, there are different classifications according to this, but the basic classification is Synchronous and Asynchronous communication.
Synchronous: means sender and receiver use the same clock signal. Asynchronous: means sender provides a synchronization signal to the receiver before starting the transfer of each message.

Synchronous & Asynchronous Dat



Communication protocol Communication protocols are formal descriptions of digital message formats and rules. They are required to exchange messages in or between computing systems and are required in telecommunications. Communications protocols cover authentication, error detection and correction, and signaling. They can also describe the syntax, semantics, and synchronization of analog and digital communications. Communications protocols are implemented in hardware and software. There are thousands of communications protocols that are used everywhere in analog and digital communications. Computer networks cannot exist without them.

There are two types of communication protocols which are classified below:
1. Inter System Protocol
2.Intra System Protocol
1.Inter System Protocol: The inter system protocol using to communicate the two different devices. Like communication between computer to microcontroller kit. The communication is done through a inter bus system.

UART Protocol

UART stands for universal asynchronous transmitter and receiver .UART Protocols is a serial communication with two wired protocol .The data cable signal lines are labeled as Rx and Tx. Serial communication is commonly used for transmitting and receiving the signal. It is transfer and receives the data serially bit by bit without class pulses. Ex: Emails, SMS, Walkie-talkie.

USART Protocol

USART stands for universal synchronous and asynchronous transmitter and receiver. It is a serial communication of two wire protocol. The data cable signal lines are labeled as Rx and TX. This protocol is used to transmitting and receiving the data byte by byte along with the clock pulses. It is a full-duplex protocol means transmitting and receiving data simultaneously to different board rates. Different devices communicate with microcontroller to this protocol. Ex:-Telecommunications.


USB Protocol

USB stands for universal serial bus. Again it is a serial communication of two wire protocol. The data cable signal lines are labeled D+ and D-.This protocol is used to communicate with the system peripherals.USB protocol is used to send and receive the data serially to the host and peripheral devices.USB communication requires a driver software which is based on the functionality of the system.USB device can transfer data on the bus without any request on the host computer. Ex: Mouse, Keyboard, Hubs, switches, pen drive.

2.Intra System Protocol: The Intra system protocol is used to communicate the two devices within the circuit board. While using this intra system protocols, with out going to intra system protocols we will expand the peripherals of the microcontroller. The circuit complexity and power consumption will be increases by using intra system protocol. Using intra system protocols circuit complexity and power consumption, cost is decrease and it is very secure to accessing the data.

Different categories of Inter system protocol

I2C Protocol

I2C stands for inter integrated circuit. I2C requires only two wires connecting all peripherals to microcontroller.I2C requires two wires SDA (serial data line) and SCL (serial clock line) to carry information between devices. It is a master to slave communication protocol. Each slave has a unique address. Master device sends the address of the target slave device and read/write flag. The address is match any slave device that device is ON, remaining slave devices are disable mode. Once the address is match communication proceed between master and that slave device and transmitting and receiving the data.

SPI Protocol

SPI stands for serial peripheral interface. It is one of the serial communication protocol developed by Motorola. Some times SPI protocol is also called a 4-wire protocol. It requires four wires MOSI, MISO, SS, and SCLK.SPI protocol used to communicate the master and slave devices. The master first configures the clock using a frequency. The master then selects the particular slave device for communication by pulling the chip select button. That particular device is selected and starts the communication between master and that particular slave. The master select only one slave at a time. It is full duplex communication protocol. Not limited to 8 bit words in the case of bit transferring.

CAN Protocol

CAN stands for controller area network .It is a serial communication protocol. It require two wires CAN High (H+) and CAN low (H-). It was developed by the Robert bosh company in 1985 for in vehicle networks. It is based on a message oriented transmission protocol.

Source- https://www.elprocus.com/communication-protocols/
Source- http://maxembedded.com/2013/09/serial-communication-introduction/#asyncMode


To understand about I2C we need to go through the pin Diagram of the ATTINY 44 to identify SDA and SCL pins, These pins would be used for I2C Communication.

Image Source-Google

PA6 - SDA (Serial Data)
PA4 - SCL (Serial Clock)
Making the schematic and routing the board for master-

traces
Cutout

Slave
Making the schematic and routing the board for slave-

Traces
Cutout
Master
Slave


The conncetion is made in the following fashion-


The Code and issues

Initially I tried to burn this code for master-

                                    

#include "Wire.h" // This is I2C library #include "SoftwareSerial.h" // This is used for making rx tx pins using software #define Rx 0 #define Tx 1 SoftwareSerial myserial(Rx, Tx); // declared Rx and Tx Pins void setup() { Wire.begin(); // I2C communication Started myserial.begin(9600); // Serial communiation Started myserial.println("Communication Started"); } void loop() { char d; // Character type declaration to store a character. if (myserial.available() > 0) { d = myserial.read(); // Read serial and store its value in variable d. if (d == '1') { // Now transmit data over the I2C lines according to the cases. Wire.beginTransmission(1); // Communication started with first node Wire.write(1); // Value sent over the channel Wire.endTransmission(); // Communication Ended myserial.println("send :- "); myserial.print(d); // Print on Serial Monitor } if (d == '2') { // Same of others. Wire.beginTransmission(1); Wire.write(2); Wire.endTransmission(); myserial.println("send :- "); myserial.print(d); } if (d == '3') { Wire.beginTransmission(2); Wire.write(3); Wire.endTransmission(); myserial.println("send :- "); myserial.print(d); } if (d == '4') { Wire.beginTransmission(2); Wire.write(4); Wire.endTransmission(); myserial.println("send :- "); myserial.print(d); } } delay(10); // Delay to make sure whole CPU is not consumed. } Note: To understand the code read comments Slave Code 1 #include "Wire.h" // This is I2C library int led1 = A0; int led2 = A1; void setup() { Wire.begin(1); // I2C Communication Started Wire.onReceive(receiveEvent); // Event triggering i.e this event will be called only when some data is recieved pinMode(led1,OUTPUT); // Declared the nature of the pin OUTPUT LED 1 Connected pinMode(led2,OUTPUT); // Decalerd the nature of the pin OUTPUT LED 2 Connected } void loop() { delay(100); } void receiveEvent(int howMany) { int x = Wire.read(); // Read Data over the channel if (x == 1) { digitalWrite(led1,HIGH); // if 1 is recieved Make LED1 pin HIGH digitalWrite(led2,LOW); // if 1 is recieved Make LED2 pin LOW } if(x ==2) { digitalWrite(led1,LOW); // if 2 is recieved Make LED1 pin Low digitalWrite(led2,HIGH); // if 2 is recieved Make LED 2 pin HIGH } }


But it showed errorr while compiling for At Tiny 44.
And a long string of error was displayed to me.


Arduino: 1.8.5 (Windows Store 1.8.10.0) (Windows 10), Board: "ATtiny24/44/84, ATtiny44, External 20 MHz"

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c: 
In function 'twi_init':

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:76:16: error: 'SDA' undeclared (first use in this function)

digitalWrite(SDA, 1);

^

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:76:16: note: each undeclared identifier is reported only once for each function it appears in

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:77:16: error: 'SCL' undeclared (first use in this function)

digitalWrite(SCL, 1);

^

In file included from c:\users\dell\documents\arduinodata\packages\arduino\tools\avr-gcc\4.9.2-atmel3.5.4-arduino2\avr\include\avr\io.h:99:0,

from C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:25:

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:80:7: error: 'TWSR' undeclared (first use in this function)

cbi(TWSR, TWPS0);

^

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:80:3: note: in expansion of macro 'cbi'

cbi(TWSR, TWPS0);

^

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:80:13: error: 'TWPS0' undeclared (first use in this function)

cbi(TWSR, TWPS0);

^

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:80:3: note: in expansion of macro 'cbi'

cbi(TWSR, TWPS0);

^

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:81:13: error: 'TWPS1' undeclared (first use in this function)

cbi(TWSR, TWPS1);

^

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:81:3: note: in expansion of macro 'cbi'

cbi(TWSR, TWPS1);

^

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:82:3: error: 'TWBR' undeclared (first use in this function)

TWBR = ((F_CPU / TWI_FREQ) - 16) / 2;

^

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:90:3: error: 'TWCR' undeclared (first use in this function)

TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWEA);

^

In file included from c:\users\dell\documents\arduinodata\packages\arduino\tools\avr-gcc\4.9.2-atmel3.5.4-arduino2\avr\include\avr\io.h:99:0,

from C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:25:

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:90:14: error: 'TWEN' undeclared (first use in this function)

TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWEA);

^

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:90:26: error: 'TWIE' undeclared (first use in this function)

TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWEA);

^

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:90:38: error: 'TWEA' undeclared (first use in this function)

TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWEA);

^

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c: In function 'twi_disable':

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:102:3: error: 'TWCR' undeclared (first use in this function)

TWCR &= ~(_BV(TWEN) | _BV(TWIE) | _BV(TWEA));

^

In file included from c:\users\dell\documents\arduinodata\packages\arduino\tools\avr-gcc\4.9.2-atmel3.5.4-arduino2\avr\include\avr\io.h:99:0,

from C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:25:

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:102:17: error: 'TWEN' undeclared (first use in this function)

TWCR &= ~(_BV(TWEN) | _BV(TWIE) | _BV(TWEA));

^

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:102:29: error: 'TWIE' undeclared (first use in this function)

TWCR &= ~(_BV(TWEN) | _BV(TWIE) | _BV(TWEA));

^

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:102:41: error: 'TWEA' undeclared (first use in this function)

TWCR &= ~(_BV(TWEN) | _BV(TWIE) | _BV(TWEA));

^

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:105:16: error: 'SDA' undeclared (first use in this function)

digitalWrite(SDA, 0);

^

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:106:16: error: 'SCL' undeclared (first use in this function)

digitalWrite(SCL, 0);

^

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c: In function 'twi_setAddress':

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:118:3: error: 'TWAR' undeclared (first use in this function)

TWAR = address << 1;

^

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c: In function 'twi_setFrequency':

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:129:3: error: 'TWBR' undeclared (first use in this function)

TWBR = ((F_CPU / frequency) - 16) / 2;

^

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c: In function 'twi_readFrom':

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:187:7: error: 'TWDR' undeclared (first use in this function)

TWDR = twi_slarw;

^

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:188:13: error: 'TWCR' undeclared (first use in this function)

} while(TWCR & _BV(TWWC));

^

In file included from c:\users\dell\documents\arduinodata\packages\arduino\tools\avr-gcc\4.9.2-atmel3.5.4-arduino2\avr\include\avr\io.h:99:0,

from C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:25:

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:188:24: error: 'TWWC' undeclared (first use in this function)

} while(TWCR & _BV(TWWC));

^

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:189:16: error: 'TWINT' undeclared (first use in this function)

TWCR = _BV(TWINT) | _BV(TWEA) | _BV(TWEN) | _BV(TWIE); // enable INTs, but not START

^

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:189:29: error: 'TWEA' undeclared (first use in this function)

TWCR = _BV(TWINT) | _BV(TWEA) | _BV(TWEN) | _BV(TWIE); // enable INTs, but not START

^

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:189:41: error: 'TWEN' undeclared (first use in this function)

TWCR = _BV(TWINT) | _BV(TWEA) | _BV(TWEN) | _BV(TWIE); // enable INTs, but not START

^

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:189:53: error: 'TWIE' undeclared (first use in this function)

TWCR = _BV(TWINT) | _BV(TWEA) | _BV(TWEN) | _BV(TWIE); // enable INTs, but not START

     ^

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:193:65: error: 'TWSTA' undeclared (first use in this function)

TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWEA) | _BV(TWINT) | _BV(TWSTA);

                 ^

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c: In function 'twi_writeTo':

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:269:7: error: 'TWDR' undeclared (first use in this function)

TWDR = twi_slarw;    

^

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:270:13: error: 'TWCR' undeclared (first use in this function)

} while(TWCR & _BV(TWWC));

^

In file included from c:\users\dell\documents\arduinodata\packages\arduino\tools\avr-gcc\4.9.2-atmel3.5.4-arduino2\avr\include\avr\io.h:99:0,

from C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:25:

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:270:24: error: 'TWWC' undeclared (first use in this function)

} while(TWCR & _BV(TWWC));

^

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:271:16: error: 'TWINT' undeclared (first use in this function)

TWCR = _BV(TWINT) | _BV(TWEA) | _BV(TWEN) | _BV(TWIE); // enable INTs, but not START

^

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:271:29: error: 'TWEA' undeclared (first use in this function)

TWCR = _BV(TWINT) | _BV(TWEA) | _BV(TWEN) | _BV(TWIE); // enable INTs, but not START

^

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:271:41: error: 'TWEN' undeclared (first use in this function)

TWCR = _BV(TWINT) | _BV(TWEA) | _BV(TWEN) | _BV(TWIE); // enable INTs, but not START

^

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:271:53: error: 'TWIE' undeclared (first use in this function)

TWCR = _BV(TWINT) | _BV(TWEA) | _BV(TWEN) | _BV(TWIE); // enable INTs, but not START

     ^

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:275:65: error: 'TWSTA' undeclared (first use in this function)

TWCR = _BV(TWINT) | _BV(TWEA) | _BV(TWEN) | _BV(TWIE) | _BV(TWSTA); // enable INTs

                 ^

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c: In function 'twi_reply':

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:357:5: error: 'TWCR' undeclared (first use in this function)

TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWINT) | _BV(TWEA);

^

In file included from c:\users\dell\documents\arduinodata\packages\arduino\tools\avr-gcc\4.9.2-atmel3.5.4-arduino2\avr\include\avr\io.h:99:0,

from C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:25:

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:357:16: error: 'TWEN' undeclared (first use in this function)

TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWINT) | _BV(TWEA);

^

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:357:28: error: 'TWIE' undeclared (first use in this function)

TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWINT) | _BV(TWEA);

^

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:357:40: error: 'TWINT' undeclared (first use in this function)

TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWINT) | _BV(TWEA);

^

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:357:53: error: 'TWEA' undeclared (first use in this function)

TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWINT) | _BV(TWEA);

     ^

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c: In function 'twi_stop':

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:372:3: error: 'TWCR' undeclared (first use in this function)

TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWEA) | _BV(TWINT) | _BV(TWSTO);

^

In file included from c:\users\dell\documents\arduinodata\packages\arduino\tools\avr-gcc\4.9.2-atmel3.5.4-arduino2\avr\include\avr\io.h:99:0,

from C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:25:

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:372:14: error: 'TWEN' undeclared (first use in this function)

TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWEA) | _BV(TWINT) | _BV(TWSTO);

^

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:372:26: error: 'TWIE' undeclared (first use in this function)

TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWEA) | _BV(TWINT) | _BV(TWSTO);

^

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:372:38: error: 'TWEA' undeclared (first use in this function)

TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWEA) | _BV(TWINT) | _BV(TWSTO);

^

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:372:50: error: 'TWINT' undeclared (first use in this function)

TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWEA) | _BV(TWINT) | _BV(TWSTO);

  ^

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:372:63: error: 'TWSTO' undeclared (first use in this function)

TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWEA) | _BV(TWINT) | _BV(TWSTO);

               ^

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c: In function 'twi_releaseBus':

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:393:3: error: 'TWCR' undeclared (first use in this function)

TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWEA) | _BV(TWINT);

^

In file included from c:\users\dell\documents\arduinodata\packages\arduino\tools\avr-gcc\4.9.2-atmel3.5.4-arduino2\avr\include\avr\io.h:99:0,

from C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:25:

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:393:14: error: 'TWEN' undeclared (first use in this function)

TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWEA) | _BV(TWINT);

^

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:393:26: error: 'TWIE' undeclared (first use in this function)

TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWEA) | _BV(TWINT);

^

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:393:38: error: 'TWEA' undeclared (first use in this function)

TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWEA) | _BV(TWINT);

^

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:393:50: error: 'TWINT' undeclared (first use in this function)

TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWEA) | _BV(TWINT);

  ^

In file included from c:\users\dell\documents\arduinodata\packages\arduino\tools\avr-gcc\4.9.2-atmel3.5.4-arduino2\avr\include\compat\twi.h:36:0,

from C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:27:

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c: In function 'TWI_vect':

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:401:10: error: 'TWSR' undeclared (first use in this function)

switch(TW_STATUS){

^

In file included from c:\users\dell\documents\arduinodata\packages\arduino\tools\avr-gcc\4.9.2-atmel3.5.4-arduino2\avr\include\avr\io.h:99:0,

from C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:25:

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:401:10: error: 'TWS7' undeclared (first use in this function)

switch(TW_STATUS){

^

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:401:10: error: 'TWS6' undeclared (first use in this function)

switch(TW_STATUS){

^

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:401:10: error: 'TWS5' undeclared (first use in this function)

switch(TW_STATUS){

^

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:401:10: error: 'TWS4' undeclared (first use in this function)

switch(TW_STATUS){

^

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:401:10: error: 'TWS3' undeclared (first use in this function)

switch(TW_STATUS){

^

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:406:7: error: 'TWDR' undeclared (first use in this function)

TWDR = twi_slarw;

^

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:426:4: error: 'TWCR' undeclared (first use in this function)

TWCR = _BV(TWINT) | _BV(TWSTA)| _BV(TWEN) ;

^

In file included from c:\users\dell\documents\arduinodata\packages\arduino\tools\avr-gcc\4.9.2-atmel3.5.4-arduino2\avr\include\avr\io.h:99:0,

from C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:25:

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:426:15: error: 'TWINT' undeclared (first use in this function)

TWCR = _BV(TWINT) | _BV(TWSTA)| _BV(TWEN) ;

^

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:426:28: error: 'TWSTA' undeclared (first use in this function)

TWCR = _BV(TWINT) | _BV(TWSTA)| _BV(TWEN) ;

^

C:\Users\Dell\Documents\ArduinoData\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c:426:40: error: 'TWEN' undeclared (first use in this function)

TWCR = _BV(TWINT) | _BV(TWSTA)| _BV(TWEN) ;

^

exit status 1
Error compiling for board ATtiny24/44/84.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
                                                                                

                              
I got so scared to see this at first, after hours of searching there was no help, I asked my friend to help me out who was very good in arduino and stuff he gave me the solution from the net which I wasn't able to figure out-

Resolving Of the Issues

There is a github repo i which we have to add a board Attiny core to use the Wire Library.
The repo Link

In the board preference add this-
http://drazzy.com/package_drazzy.com_index.json
Then add the AtTiny Core board.
After including optiboot library you can select optiboot atTiny board whichever 44 or 45 but you get a lot of option in the tool section to play with and the code compiles and burns easily, I selected AtTiny44 board not the optiboot one.
I selected the following settings for the code to compile and burn successfully-
-Board ATTiny24/44/84
-Chip -atTiny44
-Clock External 20 mhz
-BOD level- Disabled(Default)
-EEPROM Retained(Default)
-Pin Mapping Clockwise like damellis core) (Default)
-L.T.O Disabled(Default)

The Final Code that worked after This

For Master

                                         
            #include "Wire.h" 
            #include "SoftwareSerial.h"
            #define Rx 0
            #define Tx 1
            SoftwareSerial myserial(Rx, Tx);

            void setup() {
              Wire.begin(); 
              myserial.begin(9600); 
            }

            void loop() {
              char f;
              if (myserial.available() > 0)
              {
                f = myserial.read(); 
                if (d == '1') 
                {   
                  Wire.beginTransmission(1); 
                  Wire.write(1);
                  Wire.endTransmission();
                  Wire.beginTransmission(2);
                  Wire.write(1);
                  Wire.endTransmission();
                  myserial.println("Data Sent - 1");
                }
                if (d == '2') 
                {             
                  Wire.beginTransmission(1); 
                  Wire.write(2);
                  Wire.endTransmission();
                  Wire.beginTransmission(2);
                  Wire.write(2);
                  Wire.endTransmission();
                  myserial.println("Data Sent - 2");
                }
              delay(5); 
            }

                                    

For Slave 1




                        #include "Wire.h" 
                        int led1 = A0;
                        int led2 = A1;
                        void setup() 
                        {
                          Wire.begin(1); 
                          Wire.onReceive(receiveEvent); 

                          pinMode(led1,OUTPUT); 
                          pinMode(led2,OUTPUT); 
                          digitalWrite(led1,HIGH);
                          digitalWrite(led2,LOW);
                        }

                        void loop()
                        {
                          delay(5);
                        }


                        void receiveEvent()
                        {
                          char x = Wire.read();
                          if (x == '1')
                          {
                            digitalWrite(led1,LOW); 
                            digitalWrite(led2,HIGH); 
                          }
                          if(x == '2')
                          {
                            digitalWrite(led1,HIGH); 
                            digitalWrite(led2,LOW);
                          }

                        }
                                        

For Slave 2

                                                




                            #include "Wire.h" 
                            int led1 = A0;
                            int led2 = A1;
                            void setup() 
                            {
                              Wire.begin(2); 
                              Wire.onReceive(receiveEvent); 

                              pinMode(led1,OUTPUT); 
                              pinMode(led2,OUTPUT); 
                              digitalWrite(led1,HIGH);
                              digitalWrite(led2,LOW);
                            }

                            void loop()
                            {
                              delay(5);
                            }


                            void receiveEvent()
                            {
                              char x = Wire.read();
                              if (x == '1')
                              {
                                digitalWrite(led1,HIGH); 
                                digitalWrite(led2,LOW); 
                              }
                              if(x == '2')
                              {
                                digitalWrite(led1,LOW); 
                                digitalWrite(led2,HIGH);
                              }

                            }




                                        

The working



Group Assignment

For the group assignment visit our Group Page
My board and Narendra and Rajat's Board were used to communicate with each other with the same code that were used as the master and slave.
I took Narendra Bhaiya's Master board and my slave board to setup i2c communication.
The connection was done in the similar manner connectting the vcc ground pin of the master and the slave then connecting sck and sda pins of the board.


The working



Learning

This week I mostly learned about the tiny 44 and wire library about the various communication protocols.
The error made me scratched my head but finally It was resolve I felt much more documentation should have been sone or any tutorial should have been given because the tiny44 has very less video tutorials and reading the datasheet might not always be a quick choice.
Any how even I ran into errors I learned something out of it.
I'll deep dive more in this once I get a good hold of working with codes and reading datsheets.


Top