Author Topic: CMPS03  (Read 2716 times)

0 Members and 1 Guest are viewing this topic.

Offline BacoTopic starter

  • Beginner
  • *
  • Posts: 3
  • Helpful? 0
CMPS03
« on: March 26, 2010, 11:23:01 AM »
hello,
do somebody know how to connect (calibrate and reading) the compass CMPS03 with the I2C pins on the axon microcontroller?

thank you very much!!
:)

Offline teoxan

  • Full Member
  • ***
  • Posts: 49
  • Helpful? 2
Re: CMPS03
« Reply #1 on: March 26, 2010, 03:23:52 PM »


There are three pins on the Axon I2C bus, Ground, Clock, Data.Connect the CMPS03 pins there, respectively.
The 5V you connect it to a regulated 5V pin on the Axon ( a 5V on the analog pins).

You must use certain I2C commands to calibrate it.
See the data sheet on the Devantech's site.

http://www.robot-electronics.co.uk/htm/cmps3tech.htm

Theo

Offline BacoTopic starter

  • Beginner
  • *
  • Posts: 3
  • Helpful? 0
Re: CMPS03
« Reply #2 on: March 30, 2010, 05:22:36 AM »
We've already visited this site, but our problem is the code.. In fact we wrote a program to calibrate CMPS03, but it doesn't run.

The program was:

//Includes di Society of robots
#include "SoR_Utils.h" //includes all the technical stuff
#include "hardware.c" //declare hardware variables and ports
//#include "sensors.c" //sensor libraries for sonar, sharp IR, etc.
//#include "misc.c" //ha al suo interno le due funzioni per far funzionare i due azionamenti
#include "a2d.h" //per sensori
//#include "uart4.h" //per protocollo di comunicazione
#include <stdio.h>
#include "i2c.c"
#include "rprintf.h"   // include printf function library

char n;
int i = 0;

int main(void)
{
   rprintf("WAIT...\n");
   i2cInit();
               
   i2cSetBitrate(2);   //set I2C transaction bit rate in kHz
   rprintf("WAIT...\n");

   //i2cSetLocalDeviceAddr(LOCAL_ADDR, TRUE);   //set local device address and allow response to general call
/*
   //set the Slave Receive Handler function
   // this function will run whenever a
   // master somewhere else on the bus
   // writes data to us as a slave
   i2cSetSlaveReceiveHandler(i2cSlaveReceiveService);
   
   //set the Slave Transmit Handler function
   // this function will run whenever a master
   // somewhere else on the bus
   // attempts to read data from us as a slave)
   i2cSetSlaveTransmitHandler(i2cSlaveTransmitService);
*/

   //Send I2C start condition in Master mode
   i2cSendStart();   
/*
   //Send I2C stop condition in Master mode
   i2cSendStop();
      
   //Wait for current I2C operation to complete
   i2cWaitForComplete();
   
   //Send (address|R/W) combination or a data byte over I2C
   i2cSendByte(data);
*/
   while(1)
   {
      
      rprintf("waiting..\n");
      
      n = uart1GetByte();
      
      if(n == 'f')
      {   
         //Send (address|R/W) combination or a data byte over I2C
         i2cSendByte(0xff);

         rprintf("sent!!\n");
         
         i++;
         
         if(i == 4) break;
      }   
   }      
   i2cSendStop();      //Send I2C stop condition in Master mode   
}      


   
(the part of the code used to manage the i2c is taken by the site of axon)

With this program we want to calibrate each of the four cardinal pIonts sending  'f' by the terminal of ubuntu. But, like I said, this doesn't work

SOMEONE HAS AN IDEA?????
      
   

Offline chelmi

  • Supreme Robot
  • *****
  • Posts: 496
  • Helpful? 15
    • Current projects
Re: CMPS03
« Reply #3 on: March 30, 2010, 08:51:51 AM »
Please, when you post code:
 - use the code tag
 - remove the code you commented out

It will be a lot easier for us to understand.

Anyway, the datasheet of your module says that to
calibrate the module you need to write 0xff to register 15.
It isn't very clear about how to write to a register though. Try the following:

- send start
- send address with R/W bit set to 0 (write): 0xC0
- wait for complete
- send the address of the register: 15
- wait for complete
- send the data: 0xff
- send stop

repeat this sequence 4 times for each cardinal point.

 

SMF spam blocked by CleanTalk