K60 I2C alternate function in board TWR-K60N512

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

K60 I2C alternate function in board TWR-K60N512

1,143件の閲覧回数
Suvarna
Contributor I

Hi All,

 

I am working freescale board TWR-K60N512. I am trying to write I2 driver for kinetics.

 

Below is the piece of code for I2C alternate function in board TWR-K60N512

 

//Clock gate
  SIM_SCGC4 |= SIM_SCGC4_I2C0_MASK;
  SIM_SCGC5 |= SIM_SCGC5_PORTD_MASK;

 
  PORTD_PCR8 &= ~PORT_PCR_MUX_MASK;
  PORTD_PCR8 |= PORT_PCR_MUX(2); //I2C0SCL
  PORTD_PCR9 &= ~PORT_PCR_MUX_MASK;
  PORTD_PCR9 |= PORT_PCR_MUX(2); //I2C0SDA
 
  _ki2c_int_install("ii2c0:", &_bsp_i2c0_init).

 

Is this mapping is right?

 

Regards,'

Hareesha

0 件の賞賛
4 返答(返信)

547件の閲覧回数
mjbcswitzerland
Specialist V

Hi Hareesha

 

The mapping looks good - the pins should however also be configured as open-drain with (optional) pull-up resistor.

 

Regards

 

Mark

 

0 件の賞賛

547件の閲覧回数
Suvarna
Contributor I

Hi Mark,

 

Thank you for the response. I am still facing some problem with I2C write . Below is the piece of code.

 

setup_I2C();
 
   _time_delay (1L);
   
   /* Open the I2C driver, and assign a I2C device handler */
  fd = fopen ("ii2c0:", NULL);
  if (fd == NULL)
  {
    printf ("Failed to open the I2C driver!\n");
    _time_delay (200L);
    _mqx_exit (1L);
  }

  /* Set I2C into Master mode */
  ioctl (fd, IO_IOCTL_I2C_SET_MASTER_MODE, NULL);
  /* Set the destination address */
  ioctl (fd, IO_IOCTL_I2C_SET_DESTINATION_ADDRESS, &ltc_i2c_slave_adr);
 
 _time_delay (1L);
  /* Write 2 bytes of data: the desired register and then the data */
 
 
  result = fwrite (&val, 1, 2, fd);  //data to write, size of unit, # of bytes to write, I2C device handler
  _time_delay (1L);
  fflush (fd);
  _time_delay (1L);
  if (result == 0)
  {
      printf ("Write FAILED! with %d\n", result);
  }
  else
  {
      printf ("OK - Sent: %d bytes of 0x%08x\n", result, param);
  }
 
  //ioctl (fd, IO_IOCTL_FLUSH_OUTPUT, NULL);

 // _time_delay (1L);
  /* Send out stop */
  ioctl (fd, IO_IOCTL_I2C_STOP, NULL);
  fclose(fd);

 

 

I am able to send the start and slave address using i2c bus which i can see in logic analyzer  , but i2c data write fails. I2C write API fwrite fails which returns 0. Is anything wrong in the code I used. Attached is the waveform snapshot

 

Regards,

Haresha

0 件の賞賛

547件の閲覧回数
mjbcswitzerland
Specialist V

Hi

 

I don't know the code that you use - if it is iunterrupt driven I suspect that the interrupts are not enabled since there is no data after the I2C address is sent (which is also acknowledged).

 

The I2C interface that I use is here: http://www.utasker.com/docs/uTasker/uTaskerIIC.PDF

 

Regards

 

Mark

 

0 件の賞賛

547件の閲覧回数
Suvarna
Contributor I

Hi,

 

Thanks for the response. I am able to send the data in polled mode. But actual data is not sent, event address sent is wrong. Instead of 0x20 something else is sent. Data sending stopped after sending 1 byte , it supposed to send 3 byte

Am I using correct write API. Below is the piece of code

 

 

 

setup_I2C();
 
   _time_delay (1L);
   
   /* Open the I2C driver, and assign a I2C device handler */
  fd = fopen ("i2c0:", NULL);
  if (fd == NULL)
  {
    printf ("Failed to open the I2C driver!\n");
    _time_delay (200L);
    _mqx_exit (1L);
  }

  /* Set I2C into Master mode */
  ioctl (fd, IO_IOCTL_I2C_SET_MASTER_MODE, NULL);
  /* Set the destination address */
  ioctl (fd, IO_IOCTL_I2C_SET_DESTINATION_ADDRESS, &ltc_i2c_slave_adr);
 
 _time_delay (1L);
  /* Write 2 bytes of data: the desired register and then the data */
 
  result = fwrite (&param, 1, 3, fd);  //data to write, size of unit, # of bytes to write, I2C device handler
 // result = write(fd,&val, 2);
  fflush (fd);
  _time_delay (3L);
  if (result == 0)
  {
      printf ("Write FAILED! with %d\n", result);
  }
  else
  {
      printf ("OK - Sent: %d bytes of 0x%08x\n", result, param);
  }
 
  //ioctl (fd, IO_IOCTL_FLUSH_OUTPUT, NULL);

  //_time_delay (1L);
  /* Send out stop */
  ioctl (fd, IO_IOCTL_I2C_STOP, NULL);
  fclose(fd);

Attached is the snapshot

 

 

 

 

0 件の賞賛