Monday, September 12, 2011

Integration of BOSCH BMP085 using JENNIC 2-wire serial interface (I2Ccompatible) on JN-5148

The article describes use of Jennic hardware API library (AppHardwareApi_JN514x.h) for reading and writing data from the BOSCH BMP085 temperature and pressure sensor.

Hardware Description:
- The Jennic JN-5148 provides 2-wire synchronous serial interface, following I2C protocol, containing two lines of SCL (Serial Clock Line) connected to DIO14 and bi-directional SDA (Serial Data Line) connected to DIO15. The detailed description of Jennic Serial Interface and associated functions can be found at http://www.jennic.com/files/support_files/JN-UG-3066-Integrated-Peripherals-API.pdf.

- The BOSCH BMP085 consists of SCL (Serial Clock Line) connected to pin 6 and bi-directional SDA (Serial Data Line) connected to pin 7. The comprehensive description of BMP085 can be found at http://www.bosch-sensortec.com/content/language1/downloads/BST-BMP085-DS000-05.pdf.

Protocol Implementation Algorithm:
Major focus of this article is on how to communicate with BMP085 in order to read/write operations, and mathematical calculations for temperature and pressure can be found in the datasheet of BMP085.
Implementation is based on configuring Jennic as Master without interrupts enable and BMP085 as Slave device. The operational frequency 100 kHz is derived from Jennic system clock of 16 MHz by using pre-defined formula,

Operational Frequency = 16/[(Prescaler + 1) * 5]

Steps:
  • Jennic as Master Device and BMP085 as Slave Device configuration
  • Read calibration data from E2PROM of BMP085 for temperature and pressure
  • Reading and calculation of temperature
  • Reading and calculation of pressure
  • Resolution of output data is; Pressure – 0.01 hPa, and Temperature – 0.1 ˚C
Associated Jennic Functions:
  • void vAHI_SiMasterConfigure (bool_t bPulseSuppressionEnable, bool_t bInterruptEnable, uint8 u8PreScaler);
  • void vAHI_SiMasterWriteSlaveAddr (uint8 u8SlaveAddress, bool_t bReadStatus);
  • bool_t bAHI_SiMasterSetCmdReg (bool_t bSetSTA, bool_t bSetSTO, bool_t bSetRD, bool_t bSetWR, bool_t bSetAckCtrl, bool_t bSetIACK);
  • bool_t bAHI_SiMasterPollTransferInProgress (void);
  • void vAHI_SiMasterWriteData8 (uint8 u8Out);
  • uint8 u8AHI_SiMasterReadData8 (void);
Reading/Writing data from BMP085:
From the datasheet the BMP module address LSB distinguishes between read (1) and write (0) operations, corresponding to address 0xEF (read) and 0xEE (write). Where 0x77 is the BMP085 device address which will be Slave address.

// Sensor Address - Write Operation
uint8 BMP085_W = 0xEE;
// Sensor Address - Read Operation
uint8 BMP085_R  = 0xEF;

PRIVATE void vI2CRead (uint8 u8ReadAddress, uint8* u8DataOut, uint8 u8Length)
{
          uint8 i = 0;
          uint8 u8ReadLength;
          bool_t bFlag = FALSE;
          u8ReadLength = u8Length;
          vAHI_SiMasterWriteSlaveAddr (BMP085_W>>1, FALSE); // FALSE - Write Operation
          bFlag = bAHI_SiMasterSetCmdReg (E_AHI_SI_START_BIT,
                                                                      E_AHI_SI_NO_STOP_BIT,
                                                                      E_AHI_SI_NO_SLAVE_READ,
                                                                      E_AHI_SI_SLAVE_WRITE,
                                                                      E_AHI_SI_SEND_ACK,
                                                                      E_AHI_SI_NO_IRQ_ACK);
          while(bAHI_SiMasterPollTransferInProgress());    // Wait While Busy
          vAHI_SiMasterWriteData8(u8ReadAddress);          // Address to Start Read From
          bFlag = bAHI_SiMasterSetCmdReg(E_AHI_SI_NO_START_BIT,
                                                                      E_AHI_SI_NO_STOP_BIT,
                                                                      E_AHI_SI_NO_SLAVE_READ,
                                                                      E_AHI_SI_SLAVE_WRITE,
                                                                      E_AHI_SI_SEND_ACK,
                                                                      E_AHI_SI_NO_IRQ_ACK);
          while(bAHI_SiMasterPollTransferInProgress());    // Wait While Busy
          vAHI_SiMasterWriteSlaveAddr(BMP085_R>>1,TRUE); // TRUE - Read Operation
          vAHI_SiMasterSetCmdReg(E_AHI_SI_START_BIT,
                                                  E_AHI_SI_NO_STOP_BIT,
                                                  E_AHI_SI_NO_SLAVE_READ,
                                                  E_AHI_SI_SLAVE_WRITE,
                                                  E_AHI_SI_SEND_ACK,
                                                  E_AHI_SI_NO_IRQ_ACK);
          while(bAHI_SiMasterPollTransferInProgress()); // wait while busy
          // now we can start reading data back from the eeprom
          while(u8ReadLength > 0)
          {
                    if(u8ReadLength < 2)    // is it the last byte
                    {
                              vAHI_SiMasterSetCmdReg(E_AHI_SI_NO_START_BIT,
                                                                      E_AHI_SI_STOP_BIT,
                                                                      E_AHI_SI_SLAVE_READ,
                                                                      E_AHI_SI_NO_SLAVE_WRITE,
                                                                      E_AHI_SI_SEND_NACK,
                                                                      E_AHI_SI_NO_IRQ_ACK);
                    }
                    else
                    {
                              vAHI_SiMasterSetCmdReg(E_AHI_SI_NO_START_BIT,
                                                                      E_AHI_SI_NO_STOP_BIT,
                                                                      E_AHI_SI_SLAVE_READ,
                                                                      E_AHI_SI_NO_SLAVE_WRITE,
                                                                      E_AHI_SI_SEND_ACK,
                                                                      E_AHI_SI_NO_IRQ_ACK);
                    }
                    while(bAHI_SiMasterPollTransferInProgress()); // wait while busy
                    u8DataOut[i] = u8AHI_SiMasterReadData8();
                    i=i+1;
                    u8ReadLength--;
          }
}

PRIVATE void vI2CWrite (uint8* u8DataIn, uint8 u8Length)
{
          uint8 i = 0;
          uint8 u8WriteLength;
          u8WriteLength = u8Length;
          // set slave address
          vAHI_SiMasterWriteSlaveAddr(BMP085_W >> 1,FALSE);
          bAHI_SiMasterSetCmdReg(E_AHI_SI_START_BIT,
                                                  E_AHI_SI_NO_STOP_BIT,
                                                  E_AHI_SI_NO_SLAVE_READ,
                                                  E_AHI_SI_SLAVE_WRITE,
                                                  E_AHI_SI_SEND_ACK,
                                                  E_AHI_SI_NO_IRQ_ACK);
          while(bAHI_SiMasterPollTransferInProgress()); // wait while busy
          // now we can start writing data to the device
          while(u8WriteLength > 0)
          {
                    // data to write
                    vAHI_SiMasterWriteData8(u8DataIn[i++]);
                    if(u8WriteLength < 2)    // is it the last byte
                    {
                              bAHI_SiMasterSetCmdReg(E_AHI_SI_NO_START_BIT,
                                                                      E_AHI_SI_STOP_BIT,
                                                                      E_AHI_SI_NO_SLAVE_READ,
                                                                      E_AHI_SI_SLAVE_WRITE,
                                                                      E_AHI_SI_SEND_NACK,
                                                                      E_AHI_SI_NO_IRQ_ACK);
                    }
                    else
                    {
                              bAHI_SiMasterSetCmdReg(E_AHI_SI_NO_START_BIT,
                                                                      E_AHI_SI_NO_STOP_BIT,
                                                                      E_AHI_SI_NO_SLAVE_READ,
                                                                      E_AHI_SI_SLAVE_WRITE,
                                                                      E_AHI_SI_SEND_ACK,
                                                                      E_AHI_SI_NO_IRQ_ACK);
                    }
                    u8WriteLength--;
                    while(bAHI_SiMasterPollTransferInProgress()); // wait while busy
          }
}

I spent few days in understanding I2C protocol in general to start integration of pressure sensor with Jennic board, so I thought it would be beneficial to write in blog for others who found difficulty as well.

If anyone still interested in complete code, you can ask. I can send it you :)

Wednesday, June 29, 2011

Extracting specific data block, from text file, associated withcorresponding label and store data in structure variables of respectivedata type by using C/C++ environment

Requirements:
Text file, having structure similar to like this.
Label-1
$A,1234,B56F,5.678;:
Label-2
$B,7890,C00E,5.678;:
........
Analysis:
The case under consideration is as:
Label-1
$A,1234,B56F,5.678;:
'Label-1' relates to data block "$A,1234,B56F,5.678;" (separated by ','). In my case data block format consist of three parameters is pre-decided:
$A -> Header1234 -> Integer Value
B56F -> Hex Value
5.678 -> Float Value
; -> Footer
: -> represents the termination of data block
Upon retrieval of data block, the task is to extract and assign values to data structure parameters as per requirements.

Design & Development:
'tsDataBlock' is structure with four parameters as observed in analysis phase:

typedef struct stDataBlock
{
          int iParam1;
          int iParam2;
          float fParam3;
};
int _tmain(int argc, _TCHAR* argv[])
{
          stDataBlock sDataBlock;
          ifstream inFile;
          inFile.open("configFile.txt"); // Text File containing data
          char cLabel[10] = "Label-1"; // Label to search
          bool bFlag = false;
          char cDataBuffer[50];
          char cParam1[10];
          char cParam2[10];
          char cParam3[10];
          char *pch[5];
          int i = 0;
          inFile.getline(&cDataBuffer[0], 10); // Get line containing Label
          // Get corresponding data block
         {
                  // Check if Parameter 1 is integer as data type in data structure
                  // Finally print all values
                  printf("\nParam 1 %d", sDataBlock.iParam1);          
                  printf("\nParam 2 %x", sDataBlock.iParam2);
                  printf("\nParam 3 %f", sDataBlock.fParam3);
                  cin.ignore();
                  return 0;
         }
         
         while (!bFlag && (inFile.eof() != 1))
         {
                    if (strcmp(cDataBuffer, cLabel) == 0)
                    {
                              inFile.getline(&cDataBuffer[0], 50, ':');
                              cout<<"Corresponding Data Block: ";
                              // String tokenizer, excepts header, separator, and footer character
                              pch[0] = strtok(cDataBuffer, "$A,;");
                              while (pch[i] != NULL)
                              {
                                        i++;
                                        pch[i] = strtok(NULL, "$,;");
                              }
                              strcpy(cParam1, pch[0]); // Parameter 1
                              strcpy(cParam2, pch[1]); // Parameter 2
                              strcpy(cParam3, pch[2]); // Parameter 3
                              printf("Param 1: %s, Param 2: %s, Param 3: %s",
                                        cParam1, cParam2, cParam3);

                              if (i == 3)          
                              {
                                        // Check if Parameter 1 as integer data type
                                        if(!sscanf(cParam1,"%d", &sDataBlock.iParam1))
                                        bFlag = false;          
                                        // Check if Parameter 2 as hexadecimal data type
                                        if(!sscanf(cParam2,"%x", &sDataBlock.iParam2))
                                        bFlag = false;
                                        // Check if Parameter 3 is float as data type
                                        if(!sscanf(cParam3,"%f", &sDataBlock.fParam3))
                                        bFlag = false;
                              }
                              // Finally print all values
                              printf("\nParam 1 %d", sDataBlock.iParam1);
                              printf("\nParam 2 %x", sDataBlock.iParam2);
                              printf("\nParam 3 %f", sDataBlock.fParam3);
                    }
}
          cin.ignore();
          return 0;
}

Saturday, December 11, 2010

Failed to download repository information

GPG error 'NO PUBLIC KEY FOUND':

Still, I am not sure that how public keys were deleted, but these keys can be recovered by running the following command in terminal.

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys AF5ED91C56978EF9

Replace hexadecimal numbers with the number written in the error while updating ubuntu. If there are more than one error then run the above command by changing the hexadecimal numbers associated with each error. At the end run the following command,
sudo apt-get update

I hope it will work :)

Saturday, December 4, 2010

Base64 – Encode and Decode JAVA Functions

Find information on Wikipedia about Base64
privatestatic String toBase64Encode(Serializable o)
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos;
try
{
oos = new ObjectOutputStream( baos );
oos.writeObject( o );
oos.close();
}
catch (IOException e)
e.printStackTrace();

returnnew String(Base64.encodeBytes(baos.toByteArray()));
}

privatestatic Object toBase64Decode(String s)
{
byte [] data = Base64.decode(s);
ObjectInputStream ois;
try
{
ois = new ObjectInputStream(new ByteArrayInputStream(data));
Object o = ois.readObject();
ois.close();
return o;
}
catch (IOException e)
e.printStackTrace();
catch (ClassNotFoundException e)
e.printStackTrace();

returnnull;
}

Thursday, November 18, 2010

Distributed Locking Manager (DLM)

Abstract

The race of high-speed communications and high quality service provisioning is compelling the market to move towards less expensive and far reaching ways to provide services to the stakeholders. Evolution of distributed computing in consistency with extremely large networks abstracting the underlying equipments and protocols, leads the way into the world of concurrent access of available resources, at frequencies far higher than ever. Concurrency control, at present day, is being molded into a solution module called “Distributed Locking Manager” or commonly “DLM”, which is aimed to manage the concurrent access of resources while preventing network chaos. This paper is aimed to provide the reader a thorough insight into the functionality and evolution of the Distributed Locking Manager, from educational and development point of views. We present the reader with a generalized overview about the operation of DLM module. Apart from the fact that at present, different solutions for implementation of DLM are available in the market, the insight presented applies to all, in general. The vendor specific solutions differ in terms of attribute provisioning, levels of granularity or establishing communication for resource access, however, the main principles and core logics are intact in each of them. We describe the evolution of DLM from past to the present and reach some conclusions at the end of this paper which are quite essential for the integration of DLMs into distributed networks allowing for heterogeneous hardware functionalities and convergence of technology into large footprints.

Saturday, June 19, 2010

Intelligently Present Info Screen (IPIS) [Human Computer Interaction]

Abstract

The IPIS (Intelligently Present Info Screen) application will guide a user to find important places, important persons, ongoing cultural events, moral stories and histories of a place and talent hunt events. Application will show user current location automatically in a map. It will indicate important places, persons, cultural activities and moral stories & histories in a map which are closest to user current position. Suppose users are in Duomo, Milan, Italy, application will suggest users “Roman Catholic” as a historical place showing in map to visit that place. Also in application user can tag places, important persons, cultural events and moral stories. General user or foreigner who want to search for a particular place or want to join in local cultural activities, application will help them. Application will show available transportation, shortest path and brief history of that place if available. Moral histories, user experience and comment will preserved by this application. This will be a digital preserve system where user can share each other experiences. User can broadcast their talent in a second. Application will help users to participate in a talent hunt event remotely .Suppose user current position is Milan and talent hunt event is ongoing in USA, Hollywood then user will perform in front of i-phone and that will be shown in a TV screen in talent hunt event in front of judge for judgment. Now if user want to move Milan to Rome and want to visit some tourist places on the way, application will guide them and draw road map according to tourist places. This application will be integrated with i-phone’s existing application.

Friday, June 18, 2010

Customized Function Module Integration in PerLa for WSNs

Abstract

PerLa or Pervasive System language is a declarative language for application in pervasive computing. This concept behind PerLa is to provide the user with the opportunity to manage heterogeneous pervasive devices while avoiding the complexity of underlying hardware. At present, PerLa provides the users with a declarative approach towards the network to be managed. However, a limitation which arose with increase of applicability of the language was the absence of any mechanism to induct customized user functions to perform need-based operations on the data e. g. filtering operations, performing statistical functions on the data and special-case procedural code inductions. In this report, we propose a way to introduce the possibility of integrating procedural functions in the existing declarative approach offered by PerLa. In order to allow for this approach, it is necessary to embed the custom-code in the system such that the existing architecture is disturbed at a minimum and maximum functionality is achieved. We present the solution in which the system capabilities can be extended with the design point of view. The implementation of these functionalities is separated from the design phase, covered in this report.

Integration of SQLite3 and Netbeans C/C++ IDE

Few days back, I wanted to use SQLite database for one of my project. I spend couple of hours to find a way to integrate with Netbeans. Mayb...