Legacy Forum: Preserving Nearly 20 Years of Community History - A Time Capsule of Discussions, Memories, and Shared Experiences.

i2c programming on Linux

Based on DMP's Vortex processor / SoC this board is a full computer capable of running a standard Windows and Linux installation on the backpack of your robot.
3 postsPage 1 of 1
3 postsPage 1 of 1

i2c programming on Linux

Post by maestro » Thu Aug 06, 2009 4:49 pm

Post by maestro
Thu Aug 06, 2009 4:49 pm

Hi,

I try to program a Robard (Vortex86DX) operating with Linux.

Alll I want to to is to send a the data 0x1 to a PCF8574. Pleas have look on my sourceCode:

Code: Select all
#include "i2clib/i2c.h"

#include <cstdio>
#include <unistd>

int main() {

   char lightshow = 0x01; //0x80

   int retval = 0;

   printf("Starting I2C test \n\n ");

   if (!i2c_Initialize(I2CIRQ_DISABLE)) {
      perror("Can't open I2c");
      return -5;
   }
   if( i2c0_SetSpeed(I2CMODE_STANDARD, 100000L) !=0 ){
      perror("Couln't set i2c speed\n");
   }
    do {
      printf("Blink \n\n ");
      
      //START with address 0x40 to write 1 byte
      i2cmaster_StartN(0,0x40, I2C_WRITE, 1);

      i2c0master_WriteLast(lightshow); //set SRF command register

      usleep(6000); //wait 3000ms

      lightshow <<= lightshow;

   } while (true); //press ctr+c to quit

   i2c_Close();
   return retval;
}


The PCF8574 charged with some LED doesn't move. On the oscilloscope I can't recognize any proper SCL signal neither a good shaped SDA signal.

What I'm doing wrong?

Thanks for any suggestions.

[/code]
Hi,

I try to program a Robard (Vortex86DX) operating with Linux.

Alll I want to to is to send a the data 0x1 to a PCF8574. Pleas have look on my sourceCode:

Code: Select all
#include "i2clib/i2c.h"

#include <cstdio>
#include <unistd>

int main() {

   char lightshow = 0x01; //0x80

   int retval = 0;

   printf("Starting I2C test \n\n ");

   if (!i2c_Initialize(I2CIRQ_DISABLE)) {
      perror("Can't open I2c");
      return -5;
   }
   if( i2c0_SetSpeed(I2CMODE_STANDARD, 100000L) !=0 ){
      perror("Couln't set i2c speed\n");
   }
    do {
      printf("Blink \n\n ");
      
      //START with address 0x40 to write 1 byte
      i2cmaster_StartN(0,0x40, I2C_WRITE, 1);

      i2c0master_WriteLast(lightshow); //set SRF command register

      usleep(6000); //wait 3000ms

      lightshow <<= lightshow;

   } while (true); //press ctr+c to quit

   i2c_Close();
   return retval;
}


The PCF8574 charged with some LED doesn't move. On the oscilloscope I can't recognize any proper SCL signal neither a good shaped SDA signal.

What I'm doing wrong?

Thanks for any suggestions.

[/code]
maestro
Newbie
Newbie
Posts: 3
Joined: Thu Aug 06, 2009 4:10 pm

Re: i2c programming on Linux

Post by roboard » Sat Aug 08, 2009 9:03 am

Post by roboard
Sat Aug 08, 2009 9:03 am

maestro wrote:
Code: Select all
......

      i2cmaster_StartN(0,0x40, I2C_WRITE, 1);
      i2c0master_WriteLast(lightshow);
......



Hi, please ensure that you don't modify the source of RoBoIO library and include "ROBOARD.H"; then change the two lines above as follows and try again:

Code: Select all
......
if (!i2c0master_StartN(0x40, I2C_WRITE, 1))
{
    printf("START fail (%s)...try again\n", roboio_GetErrMsg());
    if (!i2c0master_StartN(0x40, I2C_WRITE, 1))
    {
        printf("START fail again (%s)\n", roboio_GetErrMsg());
        i2c_Close();
        return 0;
    }
}

if (!i2c0master_WriteN(lightshow))
{
    printf("WRITE fail (%s)\n", roboio_GetErrMsg());
    i2c_Close();
    return 0;
}
......
maestro wrote:
Code: Select all
......

      i2cmaster_StartN(0,0x40, I2C_WRITE, 1);
      i2c0master_WriteLast(lightshow);
......



Hi, please ensure that you don't modify the source of RoBoIO library and include "ROBOARD.H"; then change the two lines above as follows and try again:

Code: Select all
......
if (!i2c0master_StartN(0x40, I2C_WRITE, 1))
{
    printf("START fail (%s)...try again\n", roboio_GetErrMsg());
    if (!i2c0master_StartN(0x40, I2C_WRITE, 1))
    {
        printf("START fail again (%s)\n", roboio_GetErrMsg());
        i2c_Close();
        return 0;
    }
}

if (!i2c0master_WriteN(lightshow))
{
    printf("WRITE fail (%s)\n", roboio_GetErrMsg());
    i2c_Close();
    return 0;
}
......
roboard
Savvy Roboteer
Savvy Roboteer
Posts: 302
Joined: Fri Jul 03, 2009 4:44 am

Post by maestro » Sat Aug 08, 2009 3:50 pm

Post by maestro
Sat Aug 08, 2009 3:50 pm

Hi roboard

Thanks for your answer. It works perfect.

If I start i2c communication with i2cmaster_StartN(0,0x40, I2C_WRITE, 1) I have to continue with i2cmaster_WriteN().

thanks again.
Hi roboard

Thanks for your answer. It works perfect.

If I start i2c communication with i2cmaster_StartN(0,0x40, I2C_WRITE, 1) I have to continue with i2cmaster_WriteN().

thanks again.
maestro
Newbie
Newbie
Posts: 3
Joined: Thu Aug 06, 2009 4:10 pm


3 postsPage 1 of 1
3 postsPage 1 of 1