Sample program for interfacing with PNI's RM3100 Breakout Board

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers mbed_objects.cpp Source File

mbed_objects.cpp

00001 // The purpose of this file and associated header file is to 
00002 // enable globalization of mbed platform specific objects
00003 // for all source files to utilize
00004 
00005 #include "mbed_objects.h"
00006 
00007 //******************************
00008 // MBED Library instatiations 
00009 //******************************
00010 
00011 I2C i2c(I2C_SDA, I2C_SCL);
00012 Serial pc(USBTX, USBRX);
00013 
00014 DigitalIn DRDY_PIN(D8);
00015 
00016 // MBED native READ/ WRITE functions
00017 unsigned int rm3100_i2c_write(char registerAddress, char* buffer, short int length)
00018 {
00019     char writeBuffer[MAX_I2C_WRITE + 1];
00020     writeBuffer[0] = registerAddress;
00021     memcpy(&writeBuffer[1], buffer, length);
00022     //i2c.write(RM3100_I2C_ADDRESS_8bit, const char *data, int length, 1);
00023     // returns 0 on success (ack), non-0 on failure (nack)
00024     int status = i2c.write(RM3100_I2C_ADDRESS_8bit, writeBuffer, length+1, 0);
00025     return !status; // return True if successfull. mbed:0=Success
00026 }
00027 
00028 unsigned int rm3100_i2c_read(char registerAddress, char* buffer, short int length)
00029 {
00030     char writeBuffer[1] = {registerAddress};
00031     i2c.write(RM3100_I2C_ADDRESS_8bit, writeBuffer, 1, 1);
00032     int status = i2c.read(RM3100_I2C_ADDRESS_8bit, buffer, length, 0);
00033     if (!status) //mbed:0=Success
00034         return length;
00035     else
00036         return 0;
00037 }