Skip to content

Commit

Permalink
Raise exception on _start on already active peripheral
Browse files Browse the repository at this point in the history
  • Loading branch information
bessman committed Jan 5, 2025
1 parent 05c135d commit d86fbfa
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions pslab/bus/i2c.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,12 @@ def _start(self, address: int, mode: int) -> int:
ackstat : int
ACK (0) or NACK (1) from addressed peripheral.
"""
if self._mode == mode:
return self._ACK
if self._mode is not None:
msg = (
f"An I2C transaction is already active on peripheral 0x{address:X}. "
"Use _restart instead."
)
raise RuntimeError(msg)

self._device.send_byte(CP.I2C_HEADER)
secondary = CP.I2C_START if not self._running else CP.I2C_RESTART
Expand Down

0 comments on commit d86fbfa

Please sign in to comment.