Cmps10 I2c Address Assignment

On By In 1

We often get inquiries from our customers about what slave address to use in order to communicate with their I2C slave device. Unfortunately a lot of this confusion stems from the fact that different vendors follow different slave address conventions.

The goal of this article is to clarify the slave address standard used by all Total Phase products and to help developers determine what slave address they should use.


The I2C specification from NXP (formerly Philips) actually specifies two different slave addressing schemes. Standard Mode I2C makes use of 7-bit addressing. 10-bit addressing was later added as an extension to standard mode I2C.

7-bit Addressing

In 7-bit addressing procedure, the slave address is transferred in the first byte after the Start condition. The first seven bits of the byte comprise the slave address. The eighth bit is the read/write flag where 0 indicates a write and 1 indicates a read.

Figure 1: 7-bit addressing. The I2C bus specification specifies that in standard-mode I2C, the slave address is 7-bits long followed by the read/write bit.

All I2C products from Total Phase, follow this standard convention. The slave address used should only be the top seven bits. In the case of the Aardvark I2C/SPI Host Adapter, the software will automatically append the correct read/write bit depending on the transaction to be performed. In the case of the Beagle I2C/SPI Protocol Analyzer, the slave address and the type of transaction are displayed in two different columns.

Reserved Addresses

The I2C specification has reserved two sets of eight addresses, 1111XXX and 0000XXX. These addresses are used for special purposes. The following table has been taken from the I2C Specifications (2000).

Slave AddressR/W BitDescription
General call address
START byte(1)
CBUS address(2)
Reserved for different bus format(3)
Reserved for future purposes
Hs-mode master code
10-bit slave addressing
Reserved for future purposes

(1) No device is allowed to acknowledge at the reception of the START byte.

(2) The CBUS address has been reserved to enable the inter-mixing of CBUS compatible and I2C-bus compatible devices in the same system. I2C-bus compatible devices are not allowed to respond on reception of this address.

(3) The address reserved for a different bus format is included to enable I2C and other protocols to be mixed. Only I2C-bus compatible devices that can work with such formats and protocols are allowed to respond to this address.

8-bit Addresses

Some vendors incorrectly provide 8-bit addresses which include the read/write bit. Often times, you can determine if this is the case because they will provide one address for writing to the slave device and another to reading from the slave. In this situations. please only use the top seven bits of the address.

Figure 2: 8-bit addresses. Some vendors incorrectly provide two 8-bit slave addresses for their device, one to write to the device and one to read from the device. This 8-bit number actually encodes the 7-bit slave address and the read/write bit. Since Total Phase's products use 7-bit addressing, it is important to only use the top 7 bits of the address as the slave address.

Another way to determine if a vendor is using 8-bit addresses instead of 7-bit addresses is to see if the slave address falls within the correct range. All 7-bit addresses should be greater than 0x07 and less than 0x78 (120). If your slave address is outside this range, chances are your vendor has specified an 8-bit address.

Figure 3: Valid 7-bit Slave Address Range. The range of valid 7-bit slave addresses are bound by two blocks of reserved addresses at either end of the range. Valid slave addresses are greater than 0x07 and less than 0x78.

10-bit Addressing

One of the reasons that Total Phase decided to use 7-bit addressing for all of its products was to ensure that 10-bit addressing could be properly handled.

10-bit addressing was designed to be compatible with 7-bit addressing, allowing developers to mix two types of devices on a single bus. When communicating with a 10-bit addressed device, the special reserved address is used to indicate that 10-bit addressing is being used.

Figure 4: 10-bit addressing. In 10-bit addressing, the slave address is sent in the first two bytes. The first byte begins with the special reserved address of 1111 0XX which indicates that 10-bit addressing is being used. The 10 bits of the address is encoded in the last 2 bits of the first byte and the entire 8 bits of the second byte. The 8th bit of the first byte remains the read/write flag.

If a 10-bit address is specified when using the Aardvark I2C/SPI Host Adapter, its software will take care of sending the correct bits. The developer does not need to perform any special steps to send the correct address data. The Beagle I2C/SPI Protocol Analyzer will also automatically detect 10-bit slave addresses in the captured data and display the information correctly.


Anti-Crash Car


This project involves a GPS-controlled car that drives to a user determined destination. To prevent self-damage, when an obstacle is in its path, the car will move around the obstacle and determine a new path towards the destination. In addition, any time the car cannot move around the obstacle (all sides are blocked), the car will stop.

Objectives & Introduction

The objectives of the project was to use concepts learned in class to put together a car that would avoid crashing into objects.The car is driven by the motors and steered by a single servo. It is guided by a compass which points to the direction of the destination set by the user. The compass determines this direction through calculations, comparing its current location (coordinates found by the GPS Receiver) with the destination's coordinates. To avoid collision with interfering obstacles, 3 sensors are used--one being sonar, two being infrared.

Team Members & Responsibilities

  • Geff Lozano
    • Infrared Sensor Module
    • GPS Module
      • Parser
      • Information Processing
    • System State Machine
  • Koko Maung
    • Car Kit Assembly
    • Servos/ Wheel Motor Module
    • Infrared Sensor Module
    • Sonar Sensor Module
    • Compass Module
    • System State Machine
  • Matthew Pham
    • GPS Module
      • UART Interface
      • Parser
      • Information Processing
    • System State Machine


Week# Date Task Description
1 3/23 Planning Top-Level System Drafting
2 3/30 Top-Level System Design Went through many drafts
3 4/6 Order Parts Ordered GPS/compass unit, sonar sensor, IR sensor, and necessary accessories.
4 4/13 Assign peripheral responsibilities Divided the work.
5/6 4/20 Peripheral Interfacing GPS, Infrared, Sonar; No communication with GPS; Burned GPS;
7 4/27 System State Machine Implementation Redrafted Original State Machine
8 5/4 Implementing Started implementing State Machine with Peripheral devices together. Figured out that we purchased incorrect GPS / compass device.
8 5/11 Implementing State machine and peripheral devices are working the we we predicted. Except compass. Order new compass
8 5/18 Implementing / Testing Implementing State machine with compass. Did field testing.
8 5/22 Demo

Parts List & Cost

Design & Implementation

Hardware Design

Main Components:

  • SJ-one Board
  • Rock Crawler
  • IR sensor
  • Sonar sensor
  • GPS module
  • Compass module

Hardware Interface

Software Design

The system runs off of multiple FreeRTOS tasks running together.

Sonar Task

The task for sonar is responsible for detecting objects from a user specified distance and updating a global "sonar" variable used by the other tasks. Detections closer to the sonar return greater values while detections farther away return lesser values.

Left and Right IR Tasks

The left and right infrared sensor tasks act the same way as the sonar's task. These tasks are also used for object detection. It updates global "left IR" and "right IR" variables to be used by other tasks.

GPS Task

The GPS task updates a struct named "coordinates" with GPS coordinates. This struct contains two double types (one for longitude and one for latitude).

Compass Task

The compass task also updates a global variable which indicates the angle at which the compass is directed (e.g. 0°-359°).

State Machine Task

This task includes the system state machine as shown in the Design Flow Diagram

Design Flow


State machine

Our State machine is designed with

STOP : Forever stop loop START: Car turned on / reset button is pressed CURRENT: 1. current location is collected from GPS 2. set L,M,R = 0,0,0 3. ( destination == current) ? if true : stop ; else : compass COMPASS: 1. check head direction 2. check where the coordinate of destination 3. set L,M,R bits accordingly 4. move to decision DECISION: 1. depending on the L,M,R bit it will make decision on which sensor to check 2. ( Object )? if : next sensor; else move MOVE : 1. move accordingly 2. move back to current

Servo and Wheel motor Communication (PWM)

Servo and Wheel motor communication is done by using PWM communication. Interface for PWM is already given by Professor Preet.

1. We must set the pin that we want to use with the waveform period

2. set percentage of waveform to be stay at high.

eg.PWM pwm1(PWM::pwm1, 50); // pw1 = p0.0, period = 50 pwm1.set(10); // percent = 10 1/5 of the time signal gonna be high

Sonar and Compass Communication (I2C)

Sonar and Compass communication is done by using I2C communication. Interface for I2C is already given by Professor Preet. Since I2C module already take care of turning the LSB to high and low accordingly, we don't have to worry about it.

1. Get device address from datasheet.

2. If device requires commands to perform operation, write command to appropriate register.

3. Read information from appropriate register.

notice : If you try to read value before its ready, you will get zero.

eg. i2c.writeReg(0xE0,0x00,0x50); //writing: device address = 0xE0, register address = 0x00, writing value = 0x50; char high_byte = i2c.readReg(0xE0, 0x02); // reading: device address = 0xE0, register address = 0x02 char low_byte = i2c.readReg(0xE0, 0x03); // register address = 0x02

Infrared Communication (ADC)

Infrared communication is done by using ADC communication. Interface for ADC is already given by Professor Preet.

1. set a pin for ADC

2. select mode

3. initialize the pin

4. read value at appropriate time.

// initialization eg. LPC_PINCON -> PINSEL1 |= ( 1 << 20 ); // P0.30 LPC_PINCON -> PINMODE1 |= ( 2 << 20 ); // output mode adc0_init(); // initilize // reading IR_Left_distance = adc0_get_reading(4);

GPS Communication (UART)

The GPS Receiver communicates with the SJ One board through UART via NMEA sentences.


  • The user can configure the update (baud) rate of the GPS module with the following example commands:
    • 38400bps - $PMTK251,38400*27<CR><LF>
    • 57600bps - $PMTK251,57600*2C<CR><LF>
  • The user can filter out unwanted NMEA sentences with the following example commands:
    • Only RMC at 1Hz - $PMTK314,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*29<CR><LF>
    • Only GGA at 1Hz - $PMTK314,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*29<CR><LF>
Pin Configuration

Pin Name Description
1 VCC Power input
2 RX Data input (TTL level)
3 TX Data output (TTL level)
4 GND Ground
5 GND Ground

Testing & Technical Challenges


Test Stage 1: Individual Peripherals

In the first stage of testing, each individual peripheral was tested separately.

GPS Module
  • Checked for UART communication
    • The console for the SJ One board should at least read characters (unreadable or unrecognized characters are a result of mismatched (GPS Receiver)<->(SJ One) baud rates)
  • Checked for data consistency and reliability
    • The GPS Receiver must first be able to detect any nearby satellites
    • No LED blinking or inconsistent blinking rates are a result of satellites not being detected.
    • GPS Receiver was tested in open outdoors (The GPS Receiver was moved around EAST, WEST, NORTH, and SOUTH to check for change of data.)
Infrared and Sonar Sensors
  • Checked for correct functionality
    • Checked whether sensor detected objects in front by analyzing converted values
    • Checked whether values sent to board are consistent with proximity of objects in front of sensors
  • The compass should return a value between 0 and 359 degrees to the SJ One Board
    • NORTH: 0°
    • WEST: 90°
    • SOUTH: 180°
    • EAST: 270°

Test Stage 2: System State Cases with Peripherals

  • Individual State Testing
    • Interact with sensors to control state machine paths
    • Analyze variables to verify correct conditions to state entry
    • Print out current state upon entering state

Test Stage 3: Field Testing

After each individual peripheral has been thoroughly tested, the car was brought out for field testing (literally!). To test the car, the destination of the car was set to be equal to the car's current location plus a certain amount of coordinates away. The car was then dropped off and set to drive. The following criteria were to be met:

  • The car should drive in the direction pointed to its destination
  • The car should stop when it has reached its destination
  • The car should move around obstacles present in its path




  • Due to the SJ One Board's PWM API, PWMs connected to the SJ One Board must run at 50Hz. Although the servos and motors are capable of handling faster frequencies, they cannot handshake without matching.


  • We end up using 50Hz and we had to operate motor at slower speed.

Software Related Crashing


  • Combinations of function calls and interrupts would sometimes crash the system.


  • Convert functions for GPS, motor, state machine, sensors, etc., to tasks
    • As tasks, the functions were able to run in the background

Compass Issues


  • The first compass (UBLOXLEA-6) ordered was not compatible with the SJ One Board
    • It was designed for Plug-n-Play with specific Android related devices.
    • There was no specifications document for individual pins of the device.
  • The second compass (HMC58830) ordered had incomplete datasheets.
    • A search online was made for further specifications, but no documentation was found.


  • A third compass (CMPS10) was bought. However, it had trouble returning values pointing in the NORTH-EAST direction (270° to 359°).
    • All expected values located in that range returned inconsistently incorrect values instead.
    • During Field Testing, it was found that the compass DOES guide the car to its destination. It was trying to adjust the car left and right. However, since the compass value is inconsistent, that car was not able to reach destination.
  • Due to having to reorder three different compasses, time had taken its toll. The compass still not able to output correct result.
  • According to Professor Preet, the inconsistency might have to do with our hardware design. Our compass is too close to motor which is producing magnetic field. We will update the result once we found the solution and the cause.

Time management issue


  • We were spending most of the time implementing and testing it in control environment that we only have one day left to field test it.
    • In our software design, when compass decide to turn left, right or mid, only one sensor is driving and making decision for the car. Therefore, when turning left, if there is an object at either front or right side, it will crash into it.


  • Since we field tested one day before the demo, we didn't have enough time to come up with new algorithm. However, by adding case statements, to check other sensors, after compass decision can solve above issue.

GPS Issues


  • The ordered GPS Receiver (LS20031) was not the one received (LS23060).
  • There were no specific datasheets for the acquired model (LS23060).
    • The datasheet for LS20031 was used instead. NOTE: Use LS20031 specifications with caution.
  • The baud rate specified in the datasheet (57600bps) did not match the baud rate of the acquired GPS Receiver (38400bps).
    • Communication between the GPS Receiver and the SJSU development board was not possible due to mismatched baud rates. The GPS Receiver baud rate cannot even be set to a desired baud rate through PTMK commands without being in sync with the command sender in the first place.


The solution was to use an FDTI cable (UART to USB) with Realterminal ( for synchronization.

  • Using Realterminal, users can determine the baud rate of the GPS Receiver through trial and error--changing the port baud rate until NMEA sentences are displayed.
    • e.g. $--GGA,,llll.ll,a,yyyyy.yy,a,x,xx,x.x,x.x,M,x.x,M,x.x,xxxx.
    • See GPS - NMEA sentence information for more examples.
  • Only until the Port is initially synced with the GPS Receiver, users cannot set the GPS Receiver to a desired baud rate. When the port is in sync, the following actions can be taken:
    • With Realterminal open, click the Send Tab and check "+CR" and "+LF" flags.
    • Send the string "$PMTK314,-1*04" as ASCII to reset the GPS to its default configuration. The baud rate will then be reset to 38400bps.
    • Now the SJSU development board can communicate through PTMK commands at UART - 38400bps.


Much of the car's functionalities were implemented correctly. From the project, the team gained firsthand experience after utilizing concepts and protocols such as state machines, ADC, UART, and I2C. Also, the team learned how to test individual modules and the system itself. Sensors were tested manually to make sure that they functional and were outputting correct values. System states had to be tested with great attention to detail to make sure the system transitioned to the correct state. The team learned the benefits of implementing functions as tasks to allow the system to execute multiple tasks concurrently. Also, the team learned how to work together and work efficiently by dividing up tasks and working side by side to design, implement, and test the project. As a result, we were able to deliver the anti-crash car that is nearly complete.

Project Video

Upload a video of your project and post the link here.

Project Source Code



We would like to thanks Dr. Ozemek for giving us detailed knowledge of how circuits and components works.

We would like to thanks Preetpal Kang for teaching us how to use microcontrollers and FreeRTOS.

We would like to thanks James Loo for guiding me [Koko] throughout this whole project, making sure our project was being put together correctly.

References Used

Sonar Sensor -

IR Sensors -

Compass -

GPS Receiver -

NMEA Commands -*O-mvQMNhGW6Mmt-2RUB2Jb1odwCMia*dzrbnJWicJlJ4D9KxRkh6huPt4fDP14imYTC2D1ozEw-k6Jq-/MTKNMEAPROPRIETARYCOMMAND.pdf

Checksum Calculator -


You can list the references you used.


Leave a Reply

Your email address will not be published. Required fields are marked *