Featured post

Arduino FreeRTOS Mutex Examples

In this section, we will explain using an example to demonstrate mutexes in Arduino using freeRTOSThere are two freeRTOS Mutex examples in this tutorial, the first example demands some hardware (LCD) While the second does not need any hardware, you can try out both if you have the resources.

In the last tutorial, we considered in detail: semaphores and mutexes and we also established the difference between binary semaphores and mutexes.
Just for a review:Recall that a mutex is a locking mechanism that implements the take and gives functionality in itself, unlike a binary semaphore. See this tutorial if you have not before continuing.
Example 1: Protecting the LCD Resource Using Mutex in freeRTOS
Program Description

In this program, we Demonstrated the use a 16x2 LCD display to implement a mutex.

The LiquidCrystal library works with all LCD displays that are compatible with the Hitachi HD44780 driver. you can usually tell them by their 16-pin interface.

THE CIRCUIT

* LCD RS pin to digital…

Understanding the operation of I2C Bus

I2C pronounced as "I squared C" OR "I two C" is an acronym for Inter-Integrated Circuit Bus. It is a serial synchronous bus which we will be considering in this post. It is a very unique bus with a two-wire interface and can connect to about 127 slaves for a 7-bit address system, it can use 7-bit or 10-bit for slave addressing.

I2C Bus


I2C  is a serial and synchronous two-wire interface used to interface low-speed devices and peripherals like the EEPROMs, A/D and D/A converters, sensor networks, other I/O  to microcontrollers in embedded systems. It was invented by Philips and popular amongst all major IC manufacturers.  The two wires in I2C bus are:

  1. SCLK: For the serial clock signal

  2. SDA: Serial Data line for transfer of bits (data and address and control information)

I2C Features

  • Two-wire interface

  • Synchronous: All parties involved in the communication are tied to the same clock

  • Uses 7 bit or 10-bit slave address

  • Can address up to 256 peripherals in a 7-bit address mode

  • Uses open drain for CMOS and Open collector for TTL logic technologies

  • Half duplex communication

I2C Bus Modes

At any instant, the I2C buses can be in one of the three states:

  • Master Receive; Slave Transmit

  • Master Transmit; Slave Receive

  • Idle or Quiescent. In the idle or quiescent state, its buses are pulled high using pull-up resistors. This is important to understand the start condition.

I2C Terminology



  1. Transmitter: This is the device that transmits data to the bus

  2. Receiver: This is the device that receives data from the bus

  3. Master: This is the device that generates the clock signal, starts and stops communication.

  4. Slave: This is the device that listens to the bus and is addressed by the master can perform as a transmitter or receiver

  5. Multi-master: Having more than one master

I2C Bus Protocol


A protocol defines an agreement between two parties about the rules governing the exchange of data. In this section, we will be considering the protocol alongside the working/operation of the I2C interface.

Idle Condition: This is the default state, at this condition, the two buses are pulled high using pull-up resistors, the clock line is pulled line and the data line is pulled high too. There is no clocking.

Start Condition: The start condition is defined when the master pulls the Data line low while the clock line is still high. It should be noted here that in the I2C protocol, the contents in the data line only changes when the clock line goes low. Thus if the SDA line goes low while the clock is still high, then the start condition is met. As this happens, the clocking begins at the frequency of the clock. Note the clocking frequency controls the data rate.

Data Transfer: Data transfer is initiated once the start condition is met and clocking begins. Data transfer is in bytes. In the data format, as can be seen below, the first byte (8 bits) contains the 7-bit slave address, the R/WR signal which indicates whether the master wants to perform a read or write operation.

For Read Operation R/WR => 1 While for Write, R/ WR => 0 (Active Low)

The next byte may contain the data to be written or read from the slave depending on the designer. Note after each transfer of a successful byte (8 bits), an acknowledge signal is sent by the receiving party to confirm the successful reception of data.

Acknowledge Condition: The acknowledge (ACK) provides an avenue for error detection, the receiver (Master or slave) performs an action to indicate that it has successfully received the byte transferred. Just like the start condition, the acknowledge condition occurs after a byte is transferred, the transmitter (Master or Slave) leaves the data line high, if the receiver pulls the data line low in the next clock cycle then it is acknowledged but if the receiver could not pull the data line low, then it is a negative acknowledgment, byte was not received successfully.

Stop Condition: The stop condition just like the start condition occurs when there is a transition in state of the data line while the clock is still high, recall I said earlier that the data line is only permitted to change when the clock goes low, if the data line goes high while the clock is still high, then this condition defines a stop condition.

I2C Bus Arbitrations


Bus Arbitration is defined by a condition where multiple masters are trying to use the data bus at the same time, I2C has a way to determine who amongst the masters gets to use the data line as we will see shortly.

How is Bus Arbitration implemented in I2C without corrupting the data on the data line?

When multiple masters are trying to use the data bus at the same time, the bus arbitration is implemented bit by bit until a master fails to assert his data on the data bus, once this is done that master is out of the competition.

When a master fails to pull the data line low or take it high, that master is out of the competition, so it is possible from this explanation for 3 masters to send their data simultaneously on the data bus if and only if they are sending the same data, which is very rare, thus arbitration continues until one master is left.

I2C Applications


I2C interface can be found in so many devices using embedded systems. They are used in:

  • Communicating with EEPROM

  • Displays (LCDs)

  • Communicating with Sensors and Actuators etc

Comments

Popular posts from this blog

Arduino FreeRTOS Tutorial 05: Binary Semaphores and Mutexes

Arduino FreeRTOS Beginner Tutorial: Task Creation, Scheduling, Deleting

Digital Systems and Stability Analysis using Jury's Stability Test