Simulator says my I2C slave is always driving the SCL pin

If you have a simple question and just want an answer.
IgorLopez
Member++
Posts: 25
Joined: Tue Mar 11, 2014 8:16 pm

Simulator says my I2C slave is always driving the SCL pin

Post by IgorLopez »

Hi,

I am trying to debug my very simple I2C Slave application using the simulator and a plugin acting as a Master.
The plugin is at each plugin_clock call checking the status of the SCL and SDA pins like this:

  status = xsi->is_pin_driving(package, scl, &scl_driving);

and that function call will always return that scl_driving > 0 which according to my understanding means that my xcore application is driving the pin.

Since my app is only doing an ACK for the slave callbacks requiring it I figure it must be the i2c_slave task that is driving the pin and I found three places in i2s_slave.xc (using library version 3.1.1) where the scl pin was being driven (clock stretching is my assumption). But even when I added an argument to i2c_slave where I turned off the clock stretching, is_pin_driving still reports that my slave application is driving SCL.

What am I missing here?

This is my xc app: (with the added argument to i2c_slave turning off clock stretching):

#include <i2c.h>
#include <xs1.h>
#include <platform.h>
#include <syscall.h>
 
 
port p_scl = XS1_PORT_1F; // X0D13
port p_sda = XS1_PORT_1H; // X0D23
 
//[[distributable]]
void i2c_slave_register_file(server i2c_slave_callback_if i2c)
{
  while (1) {
    select {
    case i2c.start_read_request(void):
      break;
    case i2c.ack_read_request(void) -> i2c_slave_ack_t response:
      response = I2C_SLAVE_ACK;
      break;
    case i2c.start_write_request(void):
      break;
    case i2c.ack_write_request(void) -> i2c_slave_ack_t response:
      response = I2C_SLAVE_ACK;
      break;
    case i2c.start_master_write(void):
      break;
    case i2c.master_sent_data(uint8_t data) -> i2c_slave_ack_t response:
      response = I2C_SLAVE_ACK;
      break;
    case i2c.start_master_read(void):
      break;
    case i2c.master_requires_data() -> uint8_t data:
      data = 1;
      break;
    case i2c.stop_bit():
      break;
    }
  }
}
 
int main() {
  i2c_slave_callback_if i_i2c;
  par {
    i2c_slave_register_file(i_i2c);
    i2c_slave(i_i2c, p_scl, p_sda, 0x21, 0);
  }
  return 0;
}
 
/Igor