pca9641 v0.2.1 PCA9641.Commands

Wrapper around the Registers module to handle sending commands to and from the device.

Link to this section Summary

Functions

Abandon access to the downstream bus.

BUS_CONNECT

BUS_HUNG

BUS_HUNG_MSK

BUS_INIT

BUS_LOST_MSK

Retrieve the device ID. For PCA9641 this should be 0x38.

INT_IN_MSK

Indicates the reasons for which an interrupt was generated (if any).

LOCK_GRANT

LOCK_GRANT_MSK

MBOX_EMPTY

MBOX_EMPTY_MSK

MBOX_FULL

MBOX_FULL_MSK

OTHER_LOCK

PRIORITY

Read shared mailbox.

Request access to downstream bus.

Request access to downstream bus.

Write shared mailbox.

Link to this section Types

Link to this type

interrupt_reason()

interrupt_reason() ::
  :bus_hung
  | :mbox_full
  | :mbox_empty
  | :test_int
  | :lock_grant
  | :bus_lost
  | :int_in

Link to this section Functions

Link to this function

abandon_downstream_bus(pid)

abandon_downstream_bus(pid()) :: :ok | {:error, term()}

Abandon access to the downstream bus.

Link to this function

bus_connect(pid, value)

bus_connect(pid(), boolean()) :: :ok | {:error, term()}

BUS_CONNECT

Connectivity between master and downstream bus; the internal switch connects I2C-bus from master to downstream bus only if LOCK_GRANT = 1.

  • false -> Do not connect I2C-bus from master to downstream bus.
  • true -> Connect downstream bus; the internal switch is closed only if LOCK_GRANT = 1.
Link to this function

bus_connect?(pid)

bus_connect?(pid()) :: boolean()

BUS_CONNECT

Connectivity between master and downstream bus; the internal switch connects I2C-bus from master to downstream bus only if LOCK_GRANT = 1.

  • false -> Do not connect I2C-bus from master to downstream bus.
  • true -> Connect downstream bus; the internal switch is closed only if LOCK_GRANT = 1.
Link to this function

bus_hung?(pid)

bus_hung?(pid()) :: boolean()

BUS_HUNG

This is a read-only status register bit. If this register bit is ‘0’, it indicates the bus is in normal condition. If this bit is ‘1’, it indicates the bus is hung. The hung bus means SDA signal is LOW and SCL signal does not toggle for more than 500 ms or SCL is LOW for 500 ms.

  • false -> Normal operation.
  • true -> Downstream bus hung; when SDA signal is LOW and SCL signal does not toggle for more than 500 ms or SCL is LOW for 500 ms.
Link to this function

bus_hung_interrupt(pid, value)

bus_hung_interrupt(pid(), boolean()) :: :ok | {:error, term()}

BUS_HUNG_INT

Indicates to both masters that SDA signal is LOW and SCL signal does not toggle for more than 500 ms or SCL is LOW for 500 ms.

  • false -> No interrupt generated; normal operation.
  • true -> Interrupt generated; downstream bus cannot recover; when SDA signal is LOW and SCL signal does not toggle for more than 500 ms or SCL is LOW for 500 ms,
Link to this function

bus_hung_interrupt?(pid)

bus_hung_interrupt?(pid()) :: boolean()

BUS_HUNG_INT

Indicates to both masters that SDA signal is LOW and SCL signal does not toggle for more than 500 ms or SCL is LOW for 500 ms.

  • false -> No interrupt generated; normal operation.
  • true -> Interrupt generated; downstream bus cannot recover; when SDA signal is LOW and SCL signal does not toggle for more than 500 ms or SCL is LOW for 500 ms,
Link to this function

bus_hung_mask?(pid)

bus_hung_mask?(pid()) :: boolean()

BUS_HUNG_MSK

  • false -> Enable output interrupt when BUS_HUNG function is set.
  • true -> Disable output interrupt when BUS_HUNG function is set.
Link to this function

bus_init(pid, value)

bus_init(pid(), boolean()) :: :ok | {:error, term()}

BUS_INIT

Bus initialization for PCA9641 sends one clock out and checks SDA signal. If SDA is HIGH, PCA9641 sends a ‘not acknowledge’ and a STOP condition. The BUS_INIT function is completed. If SDA is LOW, PCA9641 sends other clock out and checks SDA again. The PCA9641 will send out 9 clocks (maximum), and if SDA is still LOW, PCA9641 determines the bus initialization has failed.

  • false -> Normal operation.
  • true -> Start initialization on next bus connect function to downstream bus.
Link to this function

bus_init?(pid)

bus_init?(pid()) :: boolean()

BUS_INIT

Bus initialization for PCA9641 sends one clock out and checks SDA signal. If SDA is HIGH, PCA9641 sends a ‘not acknowledge’ and a STOP condition. The BUS_INIT function is completed. If SDA is LOW, PCA9641 sends other clock out and checks SDA again. The PCA9641 will send out 9 clocks (maximum), and if SDA is still LOW, PCA9641 determines the bus initialization has failed.

  • false -> Normal operation.
  • true -> Start initialization on next bus connect function to downstream bus.
Link to this function

bus_initialisation_failed?(pid)

bus_initialisation_failed?(pid()) :: boolean()

BUS_INIT_FAIL

This is a read-only status register bit. If this register bit is ‘0’, it indicates the bus initialization function has passed. The downstream bus is in idle mode (SCL and SDA are HIGH). If this register bit is ‘1’, it indicates the bus initialization function has failed. The SDA signal could be stuck LOW.

  • false -> Normal operation.
  • true -> Bus initialization has failed. SDA still LOW, the downstream bus cannot recover.
Link to this function

bus_lost_interrupt(pid, value)

bus_lost_interrupt(pid(), boolean()) :: :ok | {:error, term()}

BUS_LOST_INT

Indicates the master has involuntarily lost the ownership of the downstream bus.

  • false -> No interrupt generated; this master is controlling the downstream bus.
  • true -> Interrupt generated; this master has involuntarily lost the control of the downstream bus.
Link to this function

bus_lost_interrupt?(pid)

bus_lost_interrupt?(pid()) :: boolean()

BUS_LOST_INT

Indicates the master has involuntarily lost the ownership of the downstream bus.

  • false -> No interrupt generated; this master is controlling the downstream bus.
  • true -> Interrupt generated; this master has involuntarily lost the control of the downstream bus.
Link to this function

bus_lost_mask(pid, value)

bus_lost_mask(pid(), boolean()) :: :ok | {:error, term()}

BUS_LOST_MSK

  • false -> Enable output interrupt when BUS_LOST function is set.
  • true -> Disable output interrupt when BUS_LOST function is set.
Link to this function

bus_lost_mask?(pid)

bus_lost_mask?(pid()) :: boolean()

BUS_LOST_MSK

  • false -> Enable output interrupt when BUS_LOST function is set.
  • true -> Disable output interrupt when BUS_LOST function is set.
Link to this function

downstream_disconnect_on_timeout(pid, value)

downstream_disconnect_on_timeout(pid(), boolean()) :: :ok | {:error, term()}

SMBUS_DIS

When PCA9641 detects an SMBus time-out, if this bit is set, PCA9641 will disconnect I2C-bus from master to downstream bus.

  • false -> Normal operation.
  • true -> Connectivity between master and downstream bus will be disconnected upon detecting an SMBus time-out condition.
Link to this function

downstream_disconnect_on_timeout?(pid)

downstream_disconnect_on_timeout?(pid()) :: boolean()

SMBUS_DIS

When PCA9641 detects an SMBus time-out, if this bit is set, PCA9641 will disconnect I2C-bus from master to downstream bus.

  • false -> Normal operation.
  • true -> Connectivity between master and downstream bus will be disconnected upon detecting an SMBus time-out condition.
Link to this function

id(pid)

id(pid()) :: {:ok, non_neg_integer()} | {:error, term()}

Retrieve the device ID. For PCA9641 this should be 0x38.

Link to this function

idle_timer_disconnect(pid, value)

idle_timer_disconnect(pid(), boolean()) :: :ok | {:error, term()}

IDLE_TIMER_DIS

After RES_TIME is expired, I2C-bus idle for more than 100 ms, PCA9641 will disconnect master from downstream bus and takes away its grant if this register bit is enabled. This IDLE_TIMER_DIS function also applies when there is a grant of a request with zero value on RES_TIME.

  • false -> Normal operation.
  • true -> Enable 100 ms idle timer. After reserve timer expires or if reserve timer is disabled, if the downstream bus is idle for more than 100 ms, the connection between master and downstream bus will be disconnected.
Link to this function

idle_timer_disconnect?(pid)

idle_timer_disconnect?(pid()) :: boolean()

IDLE_TIMER_DIS

After RES_TIME is expired, I2C-bus idle for more than 100 ms, PCA9641 will disconnect master from downstream bus and takes away its grant if this register bit is enabled. This IDLE_TIMER_DIS function also applies when there is a grant of a request with zero value on RES_TIME.

  • false -> Normal operation.
  • true -> Enable 100 ms idle timer. After reserve timer expires or if reserve timer is disabled, if the downstream bus is idle for more than 100 ms, the connection between master and downstream bus will be disconnected.
Link to this function

int_in_mask(pid, value)

int_in_mask(pid(), boolean()) :: :ok | {:error, term()}

INT_IN_MSK

  • false -> Enable output interrupt when INT_IN function is set.
  • true -> Disable output interrupt when INT_IN function is set.
Link to this function

int_in_mask?(pid)

int_in_mask?(pid()) :: boolean()

INT_IN_MSK

  • false -> Enable output interrupt when INT_IN function is set.
  • true -> Disable output interrupt when INT_IN function is set.
Link to this function

interrupt_reason(pid)

interrupt_reason(pid()) :: [interrupt_reason()]

Indicates the reasons for which an interrupt was generated (if any).

Link to this function

interupt_in_interrupt(pid, value)

interupt_in_interrupt(pid(), boolean()) :: :ok | {:error, term()}

INT_IN_INT

Indicates that there is an interrupt from the downstream bus to both the granted and non-granted masters.

  • false -> No interrupt on interrupt input pin INT_IN.
  • true -> Interrupt on interrupt input pin INT_IN.
Link to this function

interupt_in_interrupt?(pid)

interupt_in_interrupt?(pid()) :: boolean()

INT_IN_INT

Indicates that there is an interrupt from the downstream bus to both the granted and non-granted masters.

  • false -> No interrupt on interrupt input pin INT_IN.
  • true -> Interrupt on interrupt input pin INT_IN.
Link to this function

lock_grant?(pid)

lock_grant?(pid()) :: boolean()

LOCK_GRANT

This is a status read only register bit. Lock grant status register bit indicates the ownership between reading master and the downstream bus. If this register bit is 1, the reading master has owned the downstream bus. If this register bit is zero, the reading master has not owned the downstream bus.

  • false -> This master does not have a lock on the downstream bus.
  • true -> This master has a lock on the downstream bus.
Link to this function

lock_grant_interrupt(pid, value)

lock_grant_interrupt(pid(), boolean()) :: :ok | {:error, term()}

LOCK_GRANT_INT

Indicates the master has a lock (ownership) on the downstream bus.

  • false -> No interrupt generated; this master does not have a lock on the downstream bus.
  • true -> Interrupt generated; this master has a lock on the downstream bus.
Link to this function

lock_grant_interrupt?(pid)

lock_grant_interrupt?(pid()) :: boolean()

LOCK_GRANT_INT

Indicates the master has a lock (ownership) on the downstream bus.

  • false -> No interrupt generated; this master does not have a lock on the downstream bus.
  • true -> Interrupt generated; this master has a lock on the downstream bus.
Link to this function

lock_grant_mask(pid, value)

lock_grant_mask(pid(), boolean()) :: :ok | {:error, term()}

LOCK_GRANT_MSK

  • false -> Enable output interrupt when LOCK_GRANT function is set.
  • true -> Disable output interrupt when LOCK_GRANT function is set.
Link to this function

lock_grant_mask?(pid)

lock_grant_mask?(pid()) :: boolean()

LOCK_GRANT_MSK

  • false -> Enable output interrupt when LOCK_GRANT function is set.
  • true -> Disable output interrupt when LOCK_GRANT function is set.
Link to this function

lock_request(pid, value)

lock_request(pid(), boolean()) :: :ok | {:error, term()}

LOCK_REQ

Lock request register bit is for a master requesting the downstream bus when it does not have a lock on downstream bus. When a master has a lock on downstream bus, it can give up the ownership by writing zero to LOCK_REQ register bit. When LOCK_REQ becomes zero, LOCK_GRANT bit becomes zero and the internal switch will be open.

  • false -> Master is not requesting a lock on the downstream bus or giving up the lock if master had a lock on the downstream bus.
  • true -> Master is requesting a lock on the downstream bus.
Link to this function

lock_request?(pid)

lock_request?(pid()) :: boolean()

LOCK_REQ

Lock request register bit is for a master requesting the downstream bus when it does not have a lock on downstream bus. When a master has a lock on downstream bus, it can give up the ownership by writing zero to LOCK_REQ register bit. When LOCK_REQ becomes zero, LOCK_GRANT bit becomes zero and the internal switch will be open.

  • false -> Master is not requesting a lock on the downstream bus or giving up the lock if master had a lock on the downstream bus.
  • true -> Master is requesting a lock on the downstream bus.
Link to this function

mailbox_empty?(pid)

mailbox_empty?(pid()) :: boolean()

MBOX_EMPTY

This is a read-only status register bit. If this bit is ‘0’, it indicates other master mailbox is full, and this master cannot send more data to other master mailbox. If it is ‘1’, it indicates other master is empty and this master can send data to other master mailbox.

  • false -> Other master mailbox is full; wait until other master reads data.
  • true -> Other master mailbox is empty. Other master has read previous data and it is permitted to write new data.
Link to this function

mailbox_empty_interrupt(pid, value)

mailbox_empty_interrupt(pid(), boolean()) :: :ok | {:error, term()}

MBOX_EMPTY_INT

Indicates the sent mail is empty, other master has read the mail.

  • false -> No interrupt generated; sent mail is not empty.
  • true -> Interrupt generated; mailbox is empty.
Link to this function

mailbox_empty_interrupt?(pid)

mailbox_empty_interrupt?(pid()) :: boolean()

MBOX_EMPTY_INT

Indicates the sent mail is empty, other master has read the mail.

  • false -> No interrupt generated; sent mail is not empty.
  • true -> Interrupt generated; mailbox is empty.
Link to this function

mailbox_empty_mask(pid, value)

mailbox_empty_mask(pid(), boolean()) :: :ok | {:error, term()}

MBOX_EMPTY_MSK

  • false -> Enable output interrupt when MBOX_EMPTY function is set.
  • true -> Disable output interrupt when MBOX_EMPTY function is set.
Link to this function

mailbox_empty_mask?(pid)

mailbox_empty_mask?(pid()) :: boolean()

MBOX_EMPTY_MSK

  • false -> Enable output interrupt when MBOX_EMPTY function is set.
  • true -> Disable output interrupt when MBOX_EMPTY function is set.
Link to this function

mailbox_full?(pid)

mailbox_full?(pid()) :: boolean()

MBOX_FULL

This is a read-only status register bit. If this bit is ‘0’, it indicates no data is available in the mail box. If it is ‘1’, it indicates new data is available in the mail box.

  • false -> No data is available for this master.
  • true -> Mailbox contains data for this master from the other master.
Link to this function

mailbox_full_interrupt(pid, value)

mailbox_full_interrupt(pid(), boolean()) :: :ok | {:error, term()}

MBOX_FULL_INT

Indicates the mailbox has new mail.

  • false -> No interrupt generated; mailbox is not full.
  • true -> Interrupt generated; mailbox full.
Link to this function

mailbox_full_interrupt?(pid)

mailbox_full_interrupt?(pid()) :: boolean()

MBOX_FULL_INT

Indicates the mailbox has new mail.

  • false -> No interrupt generated; mailbox is not full.
  • true -> Interrupt generated; mailbox full.
Link to this function

mailbox_full_mask(pid, value)

mailbox_full_mask(pid(), boolean()) :: :ok | {:error, term()}

MBOX_FULL_MSK

  • false -> Enable output interrupt when MBOX_FULL function is set.
  • true -> Disable output interrupt when MBOX_FULL function is set.
Link to this function

mailbox_full_mask?(pid)

mailbox_full_mask?(pid()) :: boolean()

MBOX_FULL_MSK

  • false -> Enable output interrupt when MBOX_FULL function is set.
  • true -> Disable output interrupt when MBOX_FULL function is set.
Link to this function

other_lock?(pid)

other_lock?(pid()) :: boolean()

OTHER_LOCK

This is a status read-only register bit. Other master lock status indicates the ownership between other master and the downstream bus. If this register bit is ‘1’, the other master has owned the downstream bus. If this register bit is ‘0’, the other master does not own the downstream bus.

  • false -> The other master does not have a lock on the downstream bus.
  • true -> The other master has a lock on the downstream bus.
Link to this function

priority(pid, value)

priority(pid(), boolean()) :: :ok | {:error, term()}

PRIORITY

Master can set this register bit for setting priority of the winner when two masters request the downstream bus at the same time.

Link to this function

priority?(pid)

priority?(pid()) :: boolean()

PRIORITY

Master can set this register bit for setting priority of the winner when two masters request the downstream bus at the same time.

Link to this function

read_mailbox(pid)

read_mailbox(pid()) :: {:ok, binary()} | {:error, term()}

Read shared mailbox.

Link to this function

request_downstream_bus(pid)

request_downstream_bus(pid()) :: :ok | {:error, term()}

Request access to downstream bus.

Requests access to the downstream bus and blocks until given access.

Link to this function

request_downstream_bus(pid, reserve_time)

request_downstream_bus(pid(), non_neg_integer()) :: :ok | {:error, term()}

Request access to downstream bus.

Requests access to the downstream bus and blocks until given access.

Link to this function

reserve_time(pid)

reserve_time(pid()) :: {:ok, non_neg_integer()} | {:error, term()}
reserve_time(pid()) :: {:ok, non_neg_integer()} | {:error, term()}

RES_TIME

Reserve timer. Changes during LOCK_GRANT = 1 will have no effect.

Returns {:ok, n} where n is the number if milliseconds remaining in the reservation.

Link to this function

reserve_time(pid, ms)

RES_TIME

Reserve timer. Changes during LOCK_GRANT = 1 will have no effect.

ms is the number of milliseconds remaining in the reservation.

Link to this function

scl_becomes_io(pid, value)

scl_becomes_io(pid(), boolean()) :: :ok | {:error, term()}

SCL_IO

SCL becomes I/O pin; master can read or write to this register bit. If master reads this bit, the value is the state of the downstream SCL pin. Zero value means SCL is LOW, and one means SCL pin is HIGH. When master writes ‘0’ to this register bit, the downstream SCL pin will assert LOW. If master writes‘1’ to this register bit, the downstream SCL pin will be pulled HIGH. Remark: SCL becomes I/O pin only when BUS_CONNECT = 0 and LOCK_GRANT = 1.

  • false -> When read, shows the SCL pin of the downstream bus is LOW. When written, PCA9641 drives SCL pin of downstream bus LOW.
  • true -> When read, shows the SCL pin of the downstream bus is HIGH. When written, PCA9641 drives SCL pin of the downstream bus HIGH.
Link to this function

scl_becomes_io?(pid)

scl_becomes_io?(pid()) :: boolean()

SCL_IO

SCL becomes I/O pin; master can read or write to this register bit. If master reads this bit, the value is the state of the downstream SCL pin. Zero value means SCL is LOW, and one means SCL pin is HIGH. When master writes ‘0’ to this register bit, the downstream SCL pin will assert LOW. If master writes‘1’ to this register bit, the downstream SCL pin will be pulled HIGH. Remark: SCL becomes I/O pin only when BUS_CONNECT = 0 and LOCK_GRANT = 1.

  • false -> When read, shows the SCL pin of the downstream bus is LOW. When written, PCA9641 drives SCL pin of downstream bus LOW.
  • true -> When read, shows the SCL pin of the downstream bus is HIGH. When written, PCA9641 drives SCL pin of the downstream bus HIGH.
Link to this function

sda_becomes_io(pid, value)

sda_becomes_io(pid(), boolean()) :: :ok | {:error, term()}

SDA_IO

SDA becomes I/O pin; master can read or write to this register bit. If master reads this bit, the value is the state of the downstream SDA pin. Zero value means SDA is LOW, and one means SDA pin is HIGH. When master writes ‘0’ to this register bit, the downstream SDA pin will assert LOW. If master writes‘1’ to this register bit, the downstream SDA pin will be pulled HIGH. Remark: SDA becomes I/O pin only when BUS_CONNECT = 0 and LOCK_GRANT = 1.

  • false -> When read, indicates the SDA pin of the downstream bus is LOW. When written, PCA9641 drives SDA pin of downstream bus LOW.
  • true -> When read, indicates the SDA pin of the downstream bus is HIGH. When written, PCA9641 drives SDA pin of the downstream bus HIGH.
Link to this function

sda_becomes_io?(pid)

sda_becomes_io?(pid()) :: boolean()

SDA_IO

SDA becomes I/O pin; master can read or write to this register bit. If master reads this bit, the value is the state of the downstream SDA pin. Zero value means SDA is LOW, and one means SDA pin is HIGH. When master writes ‘0’ to this register bit, the downstream SDA pin will assert LOW. If master writes‘1’ to this register bit, the downstream SDA pin will be pulled HIGH. Remark: SDA becomes I/O pin only when BUS_CONNECT = 0 and LOCK_GRANT = 1.

  • false -> When read, indicates the SDA pin of the downstream bus is LOW. When written, PCA9641 drives SDA pin of downstream bus LOW.
  • true -> When read, indicates the SDA pin of the downstream bus is HIGH. When written, PCA9641 drives SDA pin of the downstream bus HIGH.
Link to this function

smbus_software_reset(pid, value)

smbus_software_reset(pid(), boolean()) :: :ok | {:error, term()}

SMBUS_SWRST

Non-granted or granted master sends a soft reset, if this bit is set, PCA9641 sets clock LOW for 35 ms following reset of all register values to defaults.

  • false -> Normal operation.
  • true -> Enable sending SMBus time-out to downstream bus, after receiving a general call soft reset from master.
Link to this function

smbus_software_reset?(pid)

smbus_software_reset?(pid()) :: boolean()

SMBUS_SWRST

Non-granted or granted master sends a soft reset, if this bit is set, PCA9641 sets clock LOW for 35 ms following reset of all register values to defaults.

  • false -> Normal operation.
  • true -> Enable sending SMBus time-out to downstream bus, after receiving a general call soft reset from master.
Link to this function

test_interrupt_mask?(pid)

test_interrupt_mask?(pid()) :: boolean()

TEST_INT_MSK

  • false -> Enable output interrupt when TEST_INT function is set.
  • true -> Disable output interrupt when TEST_INT function is set.
Link to this function

test_interrupt_mask?(pid, value)

test_interrupt_mask?(pid(), boolean()) :: :ok | {:error, term()}

TEST_INT_MSK

  • false -> Enable output interrupt when TEST_INT function is set.
  • true -> Disable output interrupt when TEST_INT function is set.
Link to this function

test_interrupt_pin(pid, value)

test_interrupt_pin(pid(), boolean()) :: :ok | {:error, term()}

TEST_INT

Test interrupt output pin; a master can send an interrupt to itself by writing ‘1’ to this register bit. Writing ‘0’ to this register bit has no effect. To clear this interrupt, master must write ‘1’ to TEST_INT_INT in Interrupt Status register.

  • false -> Normal operation.
  • true -> Causes PCA9641 INT pin to go LOW if not masked by TEST_INT_INT in Interrupt Mask register. Allows this master to invoke its Interrupt Service Routine to handle housekeeping tasks.
Link to this function

test_interrupt_pin_interrupt(pid, value)

test_interrupt_pin_interrupt(pid(), true) :: :ok | {:error, term()}

TEST_INT_INT

Indicates this master has sent an interrupt to itself.

  • false -> No interrupt generated; master has not set the TEST_INT bit in STATUS register.
  • true -> Interrupt generated; master activates its interrupt pin via the TEST_INT bit in STATUS register.
Link to this function

test_interrupt_pin_interrupt?(pid)

test_interrupt_pin_interrupt?(pid()) :: boolean()

TEST_INT_INT

Indicates this master has sent an interrupt to itself.

  • false -> No interrupt generated; master has not set the TEST_INT bit in STATUS register.
  • true -> Interrupt generated; master activates its interrupt pin via the TEST_INT bit in STATUS register.
Link to this function

write_mailbox(pid, message)

write_mailbox(pid(), binary()) :: :ok | {:error, term()}

Write shared mailbox.