AnsweredAssumed Answered

i2c slave interrupt mode

Question asked by joe krell on May 2, 2012
Latest reply on Nov 8, 2012 by Monica Arvizu

Hi all,

Lots of great info here on the furums so thank you to begin.

I have a problem where slave i2c (i2c1 on K60 tower) task hangs application and also does not recieve any data from external master.


I was able to verify connections and also able to be a MASTER (tower K60  as master ) on the very same i2c (I2c1)  and send valid messages to an external i2c slave (which worked very well).


So, getting back to this case, I am trying to get i2c working as a slave interrupt mode and have the K60 respond as slave to external master.The only output is from the iitialization ("Leaving initialize_i2c1_slave()") and I never get to print any recieved i2c data from external master and further, the rest of the application is hung (there is also the "shell" running on serial port d but is becomes unresponsive/hung)/


Any ideas very appreciated!




This is what I have so far.....


#define I2C_RUC_ADDRESS 0x10
#define I2C1_DATA_SIZE 5

void InitializeI2C_1();
void initialize_i2c1_slave(void);

/* Global Variables */

FILE_PTR fd_i2c_slave;
uchar recv_buffer1[I2C1_DATA_SIZE];

 * Task for Test_i2c1
void Test_i2c1_Task()
     uint_32 result;
    pointer fh_ptr;
    fh_ptr = (pointer)fopen("ttyd:", BSP_DEFAULT_IO_OPEN_MODE);
    _io_set_handle(IO_STDOUT, fh_ptr);
    _io_set_handle(IO_STDIN, fh_ptr);
  printf("Starting Test_i2c1 Task FOR SLAVE INTERRUPT interface on PORTC i2c#1 JMK\n");

  initialize_i2c1_slave(); //From forum code
  //while (TRUE)
      // read
      result = 0;
         result += fread (&recv_buffer1, 1, 1, fd_i2c_slave);
      } while (result < 1);

      printf ("....ArdVark test: Slave I2C port C 1 Interrupt read data recv_buffer1[0-4]: %x, %x, %x, %x, %x ....\n",

 // }

void initialize_i2c1_slave(void)
    uint_32 param1;
   fd_i2c_slave = fopen ("ii2c1:", NULL); // interrupt i2c1  version
   if (fd_i2c_slave == NULL)
      printf ("Failed to open the I2C1 interrupt slave driver!\n");
      _time_delay (200L);
      _mqx_exit (1L);
   //Configure i2c1 as alt2 pins of portC  -> copy from previous master Demo  i2c1
   SIM_SCGC4 |= 0x80;
   SIM_SCGC5 |= 0x800;
   printf ("For the i2c1 task we use K60 Tower and the alt2 portC functions to locate the i2c1 \n");
   printf ("For the i2c1 task we intend to connect an external i2c tool (ardvark) to  \n");
   printf ("the tower's elevator  expansion ports. Lack of connection can hang demo at present  \n");
   PORTC_PCR10 = 0x223;
   PORTC_PCR11 = 0x223;
   printf (" PORTC_PCR10 = 0x%02lX, PORTC_PCR11 = 0x%02lX  \n",PORTC_PCR10,PORTC_PCR11);
   // Done configuring port pins on port2

       // Set I2C into slave mode & set the slave address
   if( I2C_OK == ioctl (fd_i2c_slave, IO_IOCTL_I2C_SET_SLAVE_MODE, NULL) )
   { printf("I2C1 int. slave mode GOOD\n"); }
   { printf("I2C1 int. slave mode ERROR\n"); }
   param1 = I2C_RUC_ADDRESS;
   if( I2C_OK == ioctl(fd_i2c_slave, IO_IOCTL_I2C_SET_STATION_ADDRESS, &param1) )
   { printf("I2C1 int. slave mode SET STATION ADDRESS= %x   is GOOD\n",I2C_RUC_ADDRESS); }
   { printf("I2C1 int. slave mode SET STATION ADDRESS ERROR\n"); }
   if( I2C_OK == ioctl (fd_i2c_slave,IO_IOCTL_I2C_ENABLE_DEVICE , NULL) )
   { printf("I2C1 int. slave mode ENABLE DEVICE is GOOD\n"); }
   { printf("I2C1 int. slave mode ENABLE DEVICE ERROR\n"); }
   printf ( "Leaving initialize_i2c1_slave().....\n");